fallback to webrtc if enabled before jsmpeg

This commit is contained in:
Josh Hawkins 2024-08-15 05:41:16 -05:00
parent af4bc9b466
commit 8f44cc3725
3 changed files with 33 additions and 10 deletions

View File

@ -139,6 +139,13 @@ function MSEPlayer({
} }
}, [bufferTimeout]); }, [bufferTimeout]);
const handlePause = useCallback(() => {
// don't let the user pause the live stream
if (isPlaying && playbackEnabled) {
videoRef.current?.play();
}
}, [isPlaying, playbackEnabled]);
const onOpen = () => { const onOpen = () => {
setWsState(WebSocket.OPEN); setWsState(WebSocket.OPEN);
@ -402,7 +409,7 @@ function MSEPlayer({
lastJumpTimeRef.current = Date.now(); lastJumpTimeRef.current = Date.now();
}} }}
muted={!audioEnabled} muted={!audioEnabled}
onPause={() => videoRef.current?.play()} onPause={handlePause}
onProgress={() => { onProgress={() => {
const bufferTime = getBufferedTime(videoRef.current); const bufferTime = getBufferedTime(videoRef.current);

View File

@ -298,7 +298,12 @@ export interface FrigateConfig {
retry_interval: number; retry_interval: number;
}; };
go2rtc: Record<string, unknown>; go2rtc: {
streams: string[];
webrtc: {
candidates: string[];
};
};
camera_groups: { [groupName: string]: CameraGroupConfig }; camera_groups: { [groupName: string]: CameraGroupConfig };

View File

@ -286,14 +286,25 @@ export default function LiveCameraView({
} }
}, [fullscreen, isPortrait, cameraAspectRatio, containerAspectRatio]); }, [fullscreen, isPortrait, cameraAspectRatio, containerAspectRatio]);
const handleError = useCallback((e: LivePlayerError) => { const handleError = useCallback(
if (e == "mse-decode") { (e: LivePlayerError) => {
setWebRTC(true); if (e) {
} else { if (
setWebRTC(false); !webRTC &&
setLowBandwidth(true); config &&
} config.go2rtc?.webrtc?.candidates?.length > 0
}, []); ) {
// console.log(camera.name, "switching to webrtc");
setWebRTC(true);
} else {
// console.log(camera.name, "switching to jsmpeg");
setWebRTC(false);
setLowBandwidth(true);
}
}
},
[config, webRTC],
);
return ( return (
<TransformWrapper minScale={1.0} wheel={{ smoothStep: 0.005 }}> <TransformWrapper minScale={1.0} wheel={{ smoothStep: 0.005 }}>