Live view improvements (#20177)

This commit is contained in:
Josh Hawkins
2025-09-22 21:21:51 -05:00
committed by GitHub
parent bdb7a18602
commit 7f7eefef7f
4 changed files with 242 additions and 201 deletions
+15 -3
View File
@@ -37,6 +37,18 @@ export default function WebRtcPlayer({
return `${baseUrl.replace(/^http/, "ws")}live/webrtc/api/ws?src=${camera}`;
}, [camera]);
// error handler
const handleError = useCallback(
(error: LivePlayerError, description: string = "Unknown error") => {
// eslint-disable-next-line no-console
console.error(
`${camera} - WebRTC error '${error}': ${description} See the documentation: https://docs.frigate.video/configuration/live`,
);
onError?.(error);
},
[camera, onError],
);
// camera states
const pcRef = useRef<RTCPeerConnection | undefined>();
@@ -212,7 +224,7 @@ export default function WebRtcPlayer({
useEffect(() => {
videoLoadTimeoutRef.current = setTimeout(() => {
onError?.("stalled");
handleError("stalled", "WebRTC connection timed out.");
}, 5000);
return () => {
@@ -327,7 +339,7 @@ export default function WebRtcPlayer({
document.visibilityState === "visible" &&
pcRef.current != undefined
) {
onError("stalled");
handleError("stalled", "WebRTC connection stalled.");
}
}, 3000),
);
@@ -344,7 +356,7 @@ export default function WebRtcPlayer({
// @ts-expect-error code does exist
e.target.error.code == MediaError.MEDIA_ERR_NETWORK
) {
onError?.("startup");
handleError("startup", "Browser reported a network error.");
}
}}
/>