Use refs for proper js closures in the liveReady timeout (#12464)

This commit is contained in:
Josh Hawkins 2024-07-16 06:50:58 -05:00 committed by GitHub
parent 5c90f7dce7
commit 58dbbd5d29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -73,6 +73,15 @@ export default function LivePlayer({
const liveMode = useCameraLiveMode(cameraConfig, preferredLiveMode);
const [liveReady, setLiveReady] = useState(false);
const liveReadyRef = useRef(liveReady);
const cameraActiveRef = useRef(cameraActive);
useEffect(() => {
liveReadyRef.current = liveReady;
cameraActiveRef.current = cameraActive;
}, [liveReady, cameraActive]);
useEffect(() => {
if (!autoLive || !liveReady) {
return;
@ -80,7 +89,7 @@ export default function LivePlayer({
if (!cameraActive) {
const timer = setTimeout(() => {
if (!cameraActive) {
if (liveReadyRef.current && !cameraActiveRef.current) {
setLiveReady(false);
}
}, 500);

View File

@ -79,7 +79,7 @@ export default function LiveDashboardView({
return cameras
.map((cam) => cam.name)
.filter((cam) => config.camera_groups[cameraGroup].cameras.includes(cam))
.filter((cam) => config.camera_groups[cameraGroup]?.cameras.includes(cam))
.join(",");
}, [cameras, cameraGroup, config, includeBirdseye]);