revert to inline funcs

This commit is contained in:
Josh Hawkins 2024-07-04 17:38:57 -05:00
parent bdad02bff9
commit c79c631712

View File

@ -372,65 +372,54 @@ function MSEPlayer({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [playbackEnabled]); }, [playbackEnabled]);
const handleLoadedData = useCallback(() => {
handleLoadedMetadata?.();
if (playTimeoutRef.current) {
clearTimeout(playTimeoutRef.current);
playTimeoutRef.current = null;
}
onPlaying?.();
setIsPlaying(true);
}, [handleLoadedMetadata, onPlaying]);
const handleProgress = useCallback(() => {
if (!isPlaying && !playTimeoutRef.current && playbackEnabled) {
playTimeoutRef.current = setTimeout(() => {
handleLoadedData();
}, 5000);
}
if (onError != undefined) {
if (videoRef.current?.paused) {
return;
}
if (bufferTimeout) {
clearTimeout(bufferTimeout);
setBufferTimeout(undefined);
}
setBufferTimeout(
setTimeout(() => {
if (
document.visibilityState === "visible" &&
wsRef.current != null &&
videoRef.current
) {
onDisconnect();
onError("stalled");
}
}, 3000),
);
}
}, [
isPlaying,
onError,
videoRef,
bufferTimeout,
onDisconnect,
handleLoadedData,
playbackEnabled,
]);
return ( return (
<video <video
ref={videoRef} ref={videoRef}
className={className} className={className}
playsInline playsInline
preload="auto" preload="auto"
onLoadedData={handleLoadedData} onLoadedData={() => {
handleLoadedMetadata?.();
if (playTimeoutRef.current) {
clearTimeout(playTimeoutRef.current);
playTimeoutRef.current = null;
}
onPlaying?.();
setIsPlaying(true);
}}
muted={!audioEnabled} muted={!audioEnabled}
onPause={() => videoRef.current?.play()} onPause={() => videoRef.current?.play()}
onProgress={handleProgress} onProgress={() => {
if (!isPlaying && !playTimeoutRef.current && playbackEnabled) {
playTimeoutRef.current = setTimeout(() => {
setIsPlaying(true);
onPlaying?.();
}, 5000);
}
if (onError != undefined) {
if (videoRef.current?.paused) {
return;
}
if (bufferTimeout) {
clearTimeout(bufferTimeout);
setBufferTimeout(undefined);
}
setBufferTimeout(
setTimeout(() => {
if (
document.visibilityState === "visible" &&
wsRef.current != null &&
videoRef.current
) {
onDisconnect();
onError("stalled");
}
}, 3000),
);
}
}}
onError={(e) => { onError={(e) => {
if ( if (
// @ts-expect-error code does exist // @ts-expect-error code does exist