Fix webUI generating HTTP500s when camera disabled (#17305)

* Check camera enabled state before querying go2rtc

* lint

* Add change to CameraStreamingDialog
This commit is contained in:
leccelecce 2025-03-22 19:13:41 +00:00 committed by GitHub
parent 17e14cefd9
commit 644faaf65b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import { useState, useCallback, useEffect, useMemo } from "react";
import { useEnabledState } from "@/api/ws";
import { IoIosWarning } from "react-icons/io";
import { Button } from "@/components/ui/button";
import {
@ -63,6 +64,10 @@ export function CameraStreamingDialog({
// metadata
// camera enabled state
const { payload: enabledState } = useEnabledState(camera);
const cameraEnabled = enabledState === "ON";
const isRestreamed = useMemo(
() =>
config &&
@ -71,7 +76,7 @@ export function CameraStreamingDialog({
);
const { data: cameraMetadata } = useSWR<LiveStreamMetadata>(
isRestreamed ? `go2rtc/streams/${streamName}` : null,
cameraEnabled && isRestreamed ? `go2rtc/streams/${streamName}` : null,
{
revalidateOnFocus: false,
},

View File

@ -142,8 +142,11 @@ export default function LiveCameraView({
const [{ width: windowWidth, height: windowHeight }] =
useResizeObserver(window);
// supported features
// camera enabled state
const { payload: enabledState } = useEnabledState(camera.name);
const cameraEnabled = enabledState === "ON";
// supported features
const [streamName, setStreamName] = usePersistence<string>(
`${camera.name}-stream`,
Object.values(camera.live.streams)[0],
@ -157,7 +160,7 @@ export default function LiveCameraView({
);
const { data: cameraMetadata } = useSWR<LiveStreamMetadata>(
isRestreamed ? `go2rtc/streams/${streamName}` : null,
cameraEnabled && isRestreamed ? `go2rtc/streams/${streamName}` : null,
{
revalidateOnFocus: false,
},
@ -192,10 +195,6 @@ export default function LiveCameraView({
);
}, [cameraMetadata]);
// camera enabled state
const { payload: enabledState } = useEnabledState(camera.name);
const cameraEnabled = enabledState === "ON";
// click overlay for ptzs
const [clickOverlay, setClickOverlay] = useState(false);