Only disconnect instead of full remove

This commit is contained in:
Nicolas Mowen 2024-02-12 14:30:19 -07:00
parent adc103ccc8
commit 8e9e03a936
3 changed files with 16 additions and 12 deletions

View File

@ -96,6 +96,7 @@ export default function LivePlayer({
<MSEPlayer <MSEPlayer
className={`rounded-2xl h-full ${liveReady ? "" : "hidden"}`} className={`rounded-2xl h-full ${liveReady ? "" : "hidden"}`}
camera={cameraConfig.name} camera={cameraConfig.name}
playbackEnabled={cameraActive}
onPlaying={() => setLiveReady(true)} onPlaying={() => setLiveReady(true)}
/> />
); );
@ -130,8 +131,7 @@ export default function LivePlayer({
> >
<div className="absolute top-0 left-0 right-0 rounded-2xl z-10 w-full h-[30%] bg-gradient-to-b from-black/20 to-transparent pointer-events-none"></div> <div className="absolute top-0 left-0 right-0 rounded-2xl z-10 w-full h-[30%] bg-gradient-to-b from-black/20 to-transparent pointer-events-none"></div>
<div className="absolute bottom-0 left-0 right-0 rounded-2xl z-10 w-full h-[10%] bg-gradient-to-t from-black/20 to-transparent pointer-events-none"></div> <div className="absolute bottom-0 left-0 right-0 rounded-2xl z-10 w-full h-[10%] bg-gradient-to-t from-black/20 to-transparent pointer-events-none"></div>
{player}
{(showStillWithoutActivity == false || cameraActive) && player}
<div <div
className={`absolute left-0 top-0 right-0 bottom-0 w-full ${ className={`absolute left-0 top-0 right-0 bottom-0 w-full ${

View File

@ -4,10 +4,16 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
type MSEPlayerProps = { type MSEPlayerProps = {
camera: string; camera: string;
className?: string; className?: string;
playbackEnabled?: boolean;
onPlaying?: () => void; onPlaying?: () => void;
}; };
function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) { function MSEPlayer({
camera,
className,
playbackEnabled = true,
onPlaying,
}: MSEPlayerProps) {
let connectTS: number = 0; let connectTS: number = 0;
const RECONNECT_TIMEOUT: number = 30000; const RECONNECT_TIMEOUT: number = 30000;
@ -203,6 +209,10 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
}; };
useEffect(() => { useEffect(() => {
if (!playbackEnabled) {
return;
}
// iOS 17.1+ uses ManagedMediaSource // iOS 17.1+ uses ManagedMediaSource
const MediaSourceConstructor = const MediaSourceConstructor =
"ManagedMediaSource" in window ? window.ManagedMediaSource : MediaSource; "ManagedMediaSource" in window ? window.ManagedMediaSource : MediaSource;
@ -236,18 +246,12 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
observer.observe(videoRef.current!); observer.observe(videoRef.current!);
} }
return () => {
onDisconnect();
};
}, [onDisconnect, onConnect]);
useEffect(() => {
onConnect(); onConnect();
return () => { return () => {
onDisconnect(); onDisconnect();
}; };
}, [wsURL]); }, [playbackEnabled, onDisconnect, onConnect]);
return ( return (
<video <video

View File

@ -64,7 +64,7 @@ function Live() {
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order); .sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
}, [config]); }, [config]);
const [windowVisible, setWindowVisible] = useState(false); const [windowVisible, setWindowVisible] = useState(true);
const visibilityListener = useCallback(() => { const visibilityListener = useCallback(() => {
setWindowVisible(document.visibilityState == "visible"); setWindowVisible(document.visibilityState == "visible");
}, []); }, []);