This commit is contained in:
janisslsm committed 2026-11-01 12:12:55 +02:00
1 parent 1781d25a15
commit 732c0ad767
33051 files changed
+2591613 -3019689

No files matched your search

@@ -0,0 +1,148 @@
// Metro module 14159 (f14160).
import { useCallback, useEffect, useRef, useState } from "react";
import { VideoPlayerState } from "../../_bundle/Module5988";
export default function useVideoSegmentAnalytics({ getCurrentVideoTime, onAnalytics, emitIntervalMs, minSegmentDurationMs }) {
let callback2, callback3, ref4;
callback2 = void 0;
callback3 = void 0;
ref4 = void 0;
const [state, setState] = useState(null);
const [state2, setState2] = useState(false);
const [state3, setState3] = useState(false);
const [state4, setState4] = useState(false);
const ref = useRef(null);
const ref2 = useRef(Date.now());
const ref3 = useRef(false);
const callback = useCallback((a0) => {
if (!(a0.segmentEndSec < a0.segmentStartSec)) {
onAnalytics({
start_time: a0.startTimeMs,
end_time: a0.endTimeMs,
duration: a0.endTimeMs - a0.startTimeMs,
segment_start_sec: a0.segmentStartSec,
segment_end_sec: a0.segmentEndSec,
segment_duration_sec: a0.segmentEndSec - a0.segmentStartSec
});
}
}, [onAnalytics]);
callback2 = useCallback(() => {
const currentVideoTime = getCurrentVideoTime();
if (currentVideoTime != null && state3 && state4) {
const startTimeMs = Date.now();
setState({
startTimeMs,
endTimeMs: startTimeMs,
segmentStartSec: currentVideoTime,
segmentEndSec: currentVideoTime
});
ref3.current = true;
}
}, [getCurrentVideoTime, state3, state4]);
callback3 = useCallback(() => {
const currentVideoTime = getCurrentVideoTime();
if (currentVideoTime != null && state != null) {
const endTimeMs = Date.now();
if (!(endTimeMs - ref2.current < emitIntervalMs || currentVideoTime - state.segmentStartSec < minSegmentDurationMs / 1000)) {
callback({
...state,
endTimeMs,
segmentEndSec: currentVideoTime
});
setState({
startTimeMs: endTimeMs,
endTimeMs,
segmentStartSec: currentVideoTime,
segmentEndSec: currentVideoTime
});
ref2.current = endTimeMs;
}
}
}, [state, callback, emitIntervalMs, minSegmentDurationMs, getCurrentVideoTime]);
useEffect(() => {
let r3 = state3;
if (state3) {
r3 = state4;
}
if (!r3) {
setState(null);
ref3.current = false;
}
}, [state3, state4]);
useEffect(() => {
if (state2 && (state3 && state4)) {
if (!ref3.current) {
callback2();
}
ref.current = window.setInterval(() => {
callback3();
}, 200);
} else {
const currentVideoTime = getCurrentVideoTime();
if (state != null && currentVideoTime != null) {
const endTimeMs = Date.now();
if (currentVideoTime - state.segmentStartSec > 0.2) {
callback({
...state,
endTimeMs,
segmentEndSec: currentVideoTime
});
}
}
setState(null);
ref3.current = false;
if (ref.current != null) {
clearInterval(ref.current);
ref.current = null;
}
}
return () => {
if (ref.current != null) {
clearInterval(ref.current);
ref.current = null;
}
};
}, [state2, state3, state4, state, callback3, callback, callback2, getCurrentVideoTime]);
const callback4 = useCallback(() => {
const currentVideoTime = getCurrentVideoTime();
if (state != null && currentVideoTime != null) {
const endTimeMs = Date.now();
if (currentVideoTime - state.segmentStartSec > 0.2) {
callback({
...state,
endTimeMs,
segmentEndSec: currentVideoTime
});
}
setState(null);
ref3.current = false;
}
}, [state, callback, getCurrentVideoTime]);
ref4 = useRef(callback4);
ref4.current = callback4;
return {
handlePlayerStateChange: useCallback((a0) => {
L5: {
if (VideoPlayerState.PLAYING === a0) {
setState2(true);
} else {
if (VideoPlayerState.PAUSED !== a0 && VideoPlayerState.ENDED !== a0) {
break L5;
}
ref4.current();
setState2(false);
}
}
}, []),
handleLoadEnd: useCallback(() => {
setState3(true);
}, []),
handleFirstFrame: useCallback(() => {
setState4(true);
}, []),
handleSeek: useCallback(() => {
ref4.current();
}, [])
};
};
export const SEGMENT_ANALYTICS_EMIT_INTERVAL_MS = 4000;
export const SEGMENT_ANALYTICS_MIN_DURATION_MS = 2000;