diff --git a/web/src/views/live/LiveCameraView.tsx b/web/src/views/live/LiveCameraView.tsx index a9c62f623..5de52d243 100644 --- a/web/src/views/live/LiveCameraView.tsx +++ b/web/src/views/live/LiveCameraView.tsx @@ -147,10 +147,11 @@ export default function LiveCameraView({ // supported features - const [streamName, setStreamName] = useUserPersistence( - `${camera.name}-stream`, - Object.values(camera.live.streams)[0], - ); + const [streamName, setStreamName, streamNameLoaded] = + useUserPersistence( + `${camera.name}-stream`, + Object.values(camera.live.streams)[0], + ); const isRestreamed = useMemo( () => @@ -159,6 +160,19 @@ export default function LiveCameraView({ [config, streamName], ); + // validate stored stream name and reset if now invalid + + useEffect(() => { + if (!streamNameLoaded) return; + + const available = Object.values(camera.live.streams || {}); + if (available.length === 0) return; + + if (streamName != null && !available.includes(streamName)) { + setStreamName(available[0]); + } + }, [streamNameLoaded, camera.live.streams, streamName, setStreamName]); + const { data: cameraMetadata } = useSWR( isRestreamed ? `go2rtc/streams/${streamName}` : null, {