From 53b31224c18a7941878a47c11126cb1d060a4de7 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:56:36 -0500 Subject: [PATCH 01/11] Use full resolution aspect for main camera style in history view --- web/src/views/events/RecordingView.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/views/events/RecordingView.tsx b/web/src/views/events/RecordingView.tsx index f42e83a173..e0dcb65aa0 100644 --- a/web/src/views/events/RecordingView.tsx +++ b/web/src/views/events/RecordingView.tsx @@ -314,7 +314,10 @@ export function RecordingView({ return undefined; } - const aspect = camera.detect.width / camera.detect.height; + const aspect = + fullResolution.width && fullResolution.height + ? fullResolution.width / fullResolution.height + : camera.detect.width / camera.detect.height; if (!aspect) { return undefined; @@ -336,7 +339,14 @@ export function RecordingView({ return { width: `${Math.round(percent)}%`, }; - }, [config, mainCameraAspect, mainWidth, mainHeight, mainCamera]); + }, [ + config, + mainCameraAspect, + mainWidth, + mainHeight, + mainCamera, + fullResolution, + ]); const previewRowOverflows = useMemo(() => { if (!previewRowRef.current) { From b29757544c2b39b97ffbfb20356605981a4b173f Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:33:10 -0500 Subject: [PATCH 02/11] Only check for offline cameras after 60s of uptime --- web/src/hooks/use-camera-activity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/hooks/use-camera-activity.ts b/web/src/hooks/use-camera-activity.ts index 15b35de7ff..815bd12f35 100644 --- a/web/src/hooks/use-camera-activity.ts +++ b/web/src/hooks/use-camera-activity.ts @@ -133,7 +133,7 @@ export function useCameraActivity( return false; } - return cameras[camera.name].camera_fps == 0; + return cameras[camera.name].camera_fps == 0 && stats["service"].uptime > 60; }, [camera, stats]); return { From bdad02bff96e506dcdd899b438ab23b2209dbc01 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 4 Jul 2024 17:07:31 -0500 Subject: [PATCH 03/11] only call onPlaying when loadeddata is fired or after timeout --- web/src/components/player/MsePlayer.tsx | 87 +++++++++++++++---------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/web/src/components/player/MsePlayer.tsx b/web/src/components/player/MsePlayer.tsx index ad2c10e24b..bff6a59286 100644 --- a/web/src/components/player/MsePlayer.tsx +++ b/web/src/components/player/MsePlayer.tsx @@ -46,6 +46,7 @@ function MSEPlayer({ const visibilityCheck: boolean = !pip; const [isPlaying, setIsPlaying] = useState(false); + const playTimeoutRef = useRef(null); const [wsState, setWsState] = useState(WebSocket.CLOSED); const [connectTS, setConnectTS] = useState(0); @@ -371,49 +372,65 @@ function MSEPlayer({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [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 (