128 lines
4.6 KiB
TypeScript
128 lines
4.6 KiB
TypeScript
// Metro module 14055 (f14056).
|
|
import { useState, useRef, useCallback } from "react";
|
|
import { QuestsExperimentLocations } from "../../QuestConstants";
|
|
import { useBountiesExperience } from "../../experiments/useBountiesExperience";
|
|
let c9828_5 = {
|
|
END_CARD: "END_CARD",
|
|
END_CARD_WITH_CTA: "END_CARD_WITH_CTA",
|
|
LOOP: "LOOP"
|
|
};
|
|
export { c9828_5 as BountyVideoEndMode };
|
|
export function useBountiesModalTiming(a0) {
|
|
let setState2, setState3, setState4, setState5, ref, ref2, ref3, ref4, ref5;
|
|
const { endMode, rewardDurationMs } = a0;
|
|
let isCompleted = a0.isCompleted;
|
|
const { onRewardEarned, onVideoProgress, onVideoEnd, onVideoLooped, onVideoPaused, onVideoResumed, playerRef, initialProgressSec = 0 } = a0;
|
|
let c20874_9 = initialProgressSec;
|
|
let initialMaxVideoProgressSec = a0.initialMaxVideoProgressSec;
|
|
if (initialMaxVideoProgressSec === void 0) {
|
|
initialMaxVideoProgressSec = 0;
|
|
}
|
|
let initialVideoDurationSec = a0.initialVideoDurationSec;
|
|
if (initialVideoDurationSec === void 0) {
|
|
initialVideoDurationSec = null;
|
|
}
|
|
let c20874_10 = initialVideoDurationSec;
|
|
setState2 = void 0;
|
|
setState3 = void 0;
|
|
setState4 = void 0;
|
|
setState5 = void 0;
|
|
ref = void 0;
|
|
ref2 = void 0;
|
|
ref3 = void 0;
|
|
ref4 = void 0;
|
|
ref5 = void 0;
|
|
const [isEndCardVisible, setState] = useState(initialVideoDurationSec != null && initialProgressSec >= initialVideoDurationSec - 1 && endMode !== c9828_5.LOOP);
|
|
let state;
|
|
[state, setState2] = useState(() => c20874_10 != null ? c20874_9 / c20874_10 : 0);
|
|
let normalizedProgress;
|
|
[normalizedProgress, setState3] = useState(null);
|
|
let maxVideoProgressSeconds;
|
|
[maxVideoProgressSeconds, setState4] = useState(initialMaxVideoProgressSec);
|
|
let videoDuration;
|
|
[videoDuration, setState5] = useState(initialVideoDurationSec);
|
|
ref = useRef(isCompleted);
|
|
ref2 = useRef(initialMaxVideoProgressSec);
|
|
if (initialVideoDurationSec == null) {
|
|
initialVideoDurationSec = 0;
|
|
}
|
|
ref3 = useRef(initialVideoDurationSec);
|
|
ref4 = useRef(0);
|
|
ref5 = useRef(initialProgressSec);
|
|
const callback = useCallback(({ progress, currentTime, seekableDuration }) => {
|
|
setState3(null);
|
|
const current2 = Math.max(currentTime, ref2.current);
|
|
ref2.current = current2;
|
|
ref3.current = seekableDuration;
|
|
ref5.current = currentTime;
|
|
setState2(progress);
|
|
setState4(current2);
|
|
setState5(seekableDuration);
|
|
onVideoProgress(current2, seekableDuration, currentTime);
|
|
const current = ref.current;
|
|
if (current ? !current : 1000 * current2 >= rewardDurationMs) {
|
|
ref.current = true;
|
|
onRewardEarned();
|
|
}
|
|
}, [onVideoProgress, onRewardEarned, rewardDurationMs]);
|
|
const callback2 = useCallback(() => {
|
|
onVideoEnd(ref2.current, ref3.current, ref5.current);
|
|
if (endMode === c9828_5.LOOP) {
|
|
ref4.current = ref4.current + 1;
|
|
onVideoLooped(ref4.current);
|
|
ref5.current = 0;
|
|
} else {
|
|
setState(true);
|
|
}
|
|
if (!ref.current) {
|
|
ref.current = true;
|
|
onRewardEarned();
|
|
}
|
|
}, [endMode, onVideoEnd, onVideoLooped, onRewardEarned]);
|
|
const callback3 = useCallback(() => {
|
|
if (playerRef != null) {
|
|
const current = playerRef.current;
|
|
if (current != null) {
|
|
current.seekToStart();
|
|
}
|
|
}
|
|
setState3(0);
|
|
setState(false);
|
|
}, [playerRef]);
|
|
const callback4 = useCallback((a0) => {
|
|
onVideoPaused(ref5.current, a0);
|
|
}, [onVideoPaused]);
|
|
const callback5 = useCallback((a0) => {
|
|
onVideoResumed(ref5.current, a0);
|
|
}, [onVideoResumed]);
|
|
const r2 = 1000 * maxVideoProgressSeconds;
|
|
const rewardTotalSeconds = rewardDurationMs / 1000;
|
|
const r91 = Math.max(0, rewardTotalSeconds - maxVideoProgressSeconds);
|
|
const rewardRemainingSeconds = r2 >= rewardDurationMs ? 0 : isEndCardVisible ? 0 : isCompleted ? 0 : videoDuration != null ? videoDuration > 0 ? Math.max(0, Math.min(rewardTotalSeconds, videoDuration) - maxVideoProgressSeconds) : r91 : r91;
|
|
const ctaTimerMilliSeconds = useBountiesExperience(QuestsExperimentLocations.VIDEO_MODAL_MOBILE).ctaTimerMilliSeconds;
|
|
const r109 = isEndCardVisible && endMode !== c9828_5.END_CARD_WITH_CTA;
|
|
if (!isCompleted) {
|
|
isCompleted = r2 > ctaTimerMilliSeconds;
|
|
}
|
|
if (isCompleted) {
|
|
isCompleted = !r109;
|
|
}
|
|
if (normalizedProgress == null) {
|
|
normalizedProgress = state;
|
|
}
|
|
return {
|
|
isCtaVisible: isCompleted,
|
|
isEndCardVisible,
|
|
handleVideoEnd: callback2,
|
|
handleVideoProgress: callback,
|
|
handleVideoPaused: callback4,
|
|
handleVideoResumed: callback5,
|
|
handleReplay: callback3,
|
|
rewardRemainingSeconds,
|
|
rewardTotalSeconds,
|
|
normalizedProgress,
|
|
maxVideoProgressSeconds,
|
|
videoDuration
|
|
};
|
|
}
|