Change camera_activity effect to run only when config updates (#20468)

This commit is contained in:
Josh Hawkins 2025-10-13 17:24:35 -05:00 committed by GitHub
parent 6caa2050ff
commit 3c3e11ecaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,14 +33,9 @@ function useValue(): useValueReturn {
// main state // main state
const [hasCameraState, setHasCameraState] = useState(false);
const [wsState, setWsState] = useState<WsState>({}); const [wsState, setWsState] = useState<WsState>({});
useEffect(() => { useEffect(() => {
if (hasCameraState) {
return;
}
const activityValue: string = wsState["camera_activity"] as string; const activityValue: string = wsState["camera_activity"] as string;
if (!activityValue) { if (!activityValue) {
@ -105,12 +100,9 @@ function useValue(): useValueReturn {
...cameraStates, ...cameraStates,
})); }));
if (Object.keys(cameraStates).length > 0) {
setHasCameraState(true);
}
// we only want this to run initially when the config is loaded // we only want this to run initially when the config is loaded
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [wsState]); }, [wsState["camera_activity"]]);
// ws handler // ws handler
const { sendJsonMessage, readyState } = useWebSocket(wsUrl, { const { sendJsonMessage, readyState } = useWebSocket(wsUrl, {
@ -131,9 +123,7 @@ function useValue(): useValueReturn {
retain: false, retain: false,
}); });
}, },
onClose: () => { onClose: () => {},
setHasCameraState(false);
},
shouldReconnect: () => true, shouldReconnect: () => true,
retryOnError: true, retryOnError: true,
}); });