From 8e9e03a9362768c9df8a3f79951a686feaada6db Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 12 Feb 2024 14:30:19 -0700 Subject: [PATCH] Only disconnect instead of full remove --- web/src/components/player/LivePlayer.tsx | 6 +++--- web/src/components/player/MsePlayer.tsx | 20 ++++++++++++-------- web/src/pages/Live.tsx | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/web/src/components/player/LivePlayer.tsx b/web/src/components/player/LivePlayer.tsx index c190fe9d1..f6f9c535f 100644 --- a/web/src/components/player/LivePlayer.tsx +++ b/web/src/components/player/LivePlayer.tsx @@ -63,7 +63,7 @@ export default function LivePlayer({ const stillReloadInterval = useMemo(() => { if (!windowVisible) { - return -1; // no reason to update the image when the window is not visible + return -1; // no reason to update the image when the window is not visible } if (liveReady) { @@ -96,6 +96,7 @@ export default function LivePlayer({ setLiveReady(true)} /> ); @@ -130,8 +131,7 @@ export default function LivePlayer({ >
- - {(showStillWithoutActivity == false || cameraActive) && player} + {player}
void; }; -function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) { +function MSEPlayer({ + camera, + className, + playbackEnabled = true, + onPlaying, +}: MSEPlayerProps) { let connectTS: number = 0; const RECONNECT_TIMEOUT: number = 30000; @@ -203,6 +209,10 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) { }; useEffect(() => { + if (!playbackEnabled) { + return; + } + // iOS 17.1+ uses ManagedMediaSource const MediaSourceConstructor = "ManagedMediaSource" in window ? window.ManagedMediaSource : MediaSource; @@ -236,18 +246,12 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) { observer.observe(videoRef.current!); } - return () => { - onDisconnect(); - }; - }, [onDisconnect, onConnect]); - - useEffect(() => { onConnect(); return () => { onDisconnect(); }; - }, [wsURL]); + }, [playbackEnabled, onDisconnect, onConnect]); return (