From 29318022a7645c1f9a339e1084d24cd9b69515df Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Sun, 22 Nov 2026 23:11:37 -0500 Subject: [PATCH 1/3] Apply suggested fix to web/js/components/preact/HLSVideoCell.tsx from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- web/js/components/preact/HLSVideoCell.tsx | 30 ++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/web/js/components/preact/HLSVideoCell.tsx b/web/js/components/preact/HLSVideoCell.tsx index 03717166d..50986b3c0 100644 --- a/web/js/components/preact/HLSVideoCell.tsx +++ b/web/js/components/preact/HLSVideoCell.tsx @@ -459,6 +459,19 @@ export function HLSVideoCell({ hls.loadSource(hlsStreamUrl); hls.attachMedia(videoRef.current!); + let lastPlaybackTime = -1; + const handlePlaybackProgress = () => { + if (!isMounted || !videoRef.current) return; + const currentTime = videoRef.current.currentTime; + if (recoveringRef.current && currentTime > lastPlaybackTime && !videoRef.current.paused && !videoRef.current.ended) { + console.log(`[HLS ${stream.name}] Recovery successful - playback progressed`); + recoveringRef.current = false; + fatalErrorCountRef.current = 0; + } + lastPlaybackTime = currentTime; + }; + videoRef.current?.addEventListener('timeupdate', handlePlaybackProgress); + hls.on(Hls.Events.MANIFEST_PARSED, function() { if (!isMounted) return; if (!recoveringRef.current) { @@ -479,15 +492,7 @@ export function HLSVideoCell({ } }); - // Reset fatal error counter after successful fragment buffering (real recovery signal) - hls.on(Hls.Events.FRAG_BUFFERED, function() { - if (!isMounted) return; - if (recoveringRef.current) { - console.log(`[HLS ${stream.name}] Recovery successful - fragment buffered`); - recoveringRef.current = false; - fatalErrorCountRef.current = 0; - } - }); + // FRAG_BUFFERED only confirms append-to-buffer; recovery reset now happens on playback progress. hls.on(Hls.Events.ERROR, function(event, data) { if (!isMounted) return; @@ -586,6 +591,13 @@ export function HLSVideoCell({ } } }); + + // Cleanup playback progress listener + const originalCleanup = cleanup; + cleanup = () => { + videoRef.current?.removeEventListener('timeupdate', handlePlaybackProgress); + originalCleanup(); + }; } // Check if HLS is supported natively (Safari) else if (videoRef.current!.canPlayType('application/vnd.apple.mpegurl')) { From fd78c4ebf84064eabc3609e5726c6e683bbd1665 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Sun, 22 Nov 2026 23:11:38 -0500 Subject: [PATCH 2/3] Apply suggested fix to web/js/components/preact/HLSVideoCell.tsx from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- web/js/components/preact/HLSVideoCell.tsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/web/js/components/preact/HLSVideoCell.tsx b/web/js/components/preact/HLSVideoCell.tsx index 50986b3c0..e92edc765 100644 --- a/web/js/components/preact/HLSVideoCell.tsx +++ b/web/js/components/preact/HLSVideoCell.tsx @@ -92,16 +92,28 @@ export function HLSVideoCell({ const hadPrivacyFocusRef = useRef(false); const previousFocusedElementRef = useRef(null); const tileContainerRef = useRef(null); + const privacyFocusInitializedRef = useRef(false); + const previousPrivacyActiveRef = useRef(privacyActive); useEffect(() => { if (privacyActive) { const focused = document.activeElement; const container = tileContainerRef.current; const focusedInTile = focused instanceof Node && !!container?.contains(focused); + const becamePrivacyActive = !previousPrivacyActiveRef.current && privacyActive; - if (!focusedInTile && focused !== document.body) { + if (!privacyFocusInitializedRef.current) { + privacyFocusInitializedRef.current = true; hadPrivacyFocusRef.current = false; previousFocusedElementRef.current = null; + previousPrivacyActiveRef.current = privacyActive; + return; + } + + if (!becamePrivacyActive || !focusedInTile) { + hadPrivacyFocusRef.current = false; + previousFocusedElementRef.current = null; + previousPrivacyActiveRef.current = privacyActive; return; } @@ -111,14 +123,19 @@ export function HLSVideoCell({ } privacyResumeButtonRef.current?.focus(); hadPrivacyFocusRef.current = true; + previousPrivacyActiveRef.current = privacyActive; return; } - if (!hadPrivacyFocusRef.current) return; + if (!hadPrivacyFocusRef.current) { + previousPrivacyActiveRef.current = privacyActive; + return; + } if (document.activeElement !== privacyResumeButtonRef.current && document.activeElement !== document.body) { hadPrivacyFocusRef.current = false; previousFocusedElementRef.current = null; + previousPrivacyActiveRef.current = privacyActive; return; } @@ -130,6 +147,7 @@ export function HLSVideoCell({ tileContainerRef.current?.focus(); } previousFocusedElementRef.current = null; + previousPrivacyActiveRef.current = privacyActive; }, [privacyActive]); useEffect(() => { From 39bad324b702ea694b83910a4e7bc92fccddb843 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Mon, 23 Nov 2026 05:14:29 -0500 Subject: [PATCH 3/3] Preserve privacy focus and clean up playback listener --- web/js/components/preact/HLSVideoCell.tsx | 43 ++++++----------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/web/js/components/preact/HLSVideoCell.tsx b/web/js/components/preact/HLSVideoCell.tsx index e92edc765..dcdea4597 100644 --- a/web/js/components/preact/HLSVideoCell.tsx +++ b/web/js/components/preact/HLSVideoCell.tsx @@ -92,28 +92,15 @@ export function HLSVideoCell({ const hadPrivacyFocusRef = useRef(false); const previousFocusedElementRef = useRef(null); const tileContainerRef = useRef(null); - const privacyFocusInitializedRef = useRef(false); - const previousPrivacyActiveRef = useRef(privacyActive); useEffect(() => { if (privacyActive) { const focused = document.activeElement; const container = tileContainerRef.current; const focusedInTile = focused instanceof Node && !!container?.contains(focused); - const becamePrivacyActive = !previousPrivacyActiveRef.current && privacyActive; - - if (!privacyFocusInitializedRef.current) { - privacyFocusInitializedRef.current = true; - hadPrivacyFocusRef.current = false; - previousFocusedElementRef.current = null; - previousPrivacyActiveRef.current = privacyActive; - return; - } - - if (!becamePrivacyActive || !focusedInTile) { + if (!focusedInTile && focused !== document.body) { hadPrivacyFocusRef.current = false; previousFocusedElementRef.current = null; - previousPrivacyActiveRef.current = privacyActive; return; } @@ -123,19 +110,14 @@ export function HLSVideoCell({ } privacyResumeButtonRef.current?.focus(); hadPrivacyFocusRef.current = true; - previousPrivacyActiveRef.current = privacyActive; return; } - if (!hadPrivacyFocusRef.current) { - previousPrivacyActiveRef.current = privacyActive; - return; - } + if (!hadPrivacyFocusRef.current) return; if (document.activeElement !== privacyResumeButtonRef.current && document.activeElement !== document.body) { hadPrivacyFocusRef.current = false; previousFocusedElementRef.current = null; - previousPrivacyActiveRef.current = privacyActive; return; } @@ -147,7 +129,6 @@ export function HLSVideoCell({ tileContainerRef.current?.focus(); } previousFocusedElementRef.current = null; - previousPrivacyActiveRef.current = privacyActive; }, [privacyActive]); useEffect(() => { @@ -294,6 +275,7 @@ export function HLSVideoCell({ let nativeLoadedHandler: (() => void) | null = null; let nativePlayingHandler: (() => void) | null = null; let nativeErrorHandler: (() => void) | null = null; + let playbackProgressCleanup: (() => void) | null = null; // Async initialization function - MUST be defined before doInit to avoid TDZ errors const initHls = async () => { @@ -477,18 +459,20 @@ export function HLSVideoCell({ hls.loadSource(hlsStreamUrl); hls.attachMedia(videoRef.current!); - let lastPlaybackTime = -1; + const playbackVideo = videoRef.current!; + let lastPlaybackTime = playbackVideo.currentTime; const handlePlaybackProgress = () => { - if (!isMounted || !videoRef.current) return; - const currentTime = videoRef.current.currentTime; - if (recoveringRef.current && currentTime > lastPlaybackTime && !videoRef.current.paused && !videoRef.current.ended) { + if (!isMounted) return; + const currentTime = playbackVideo.currentTime; + if (recoveringRef.current && currentTime > lastPlaybackTime && !playbackVideo.paused && !playbackVideo.ended) { console.log(`[HLS ${stream.name}] Recovery successful - playback progressed`); recoveringRef.current = false; fatalErrorCountRef.current = 0; } lastPlaybackTime = currentTime; }; - videoRef.current?.addEventListener('timeupdate', handlePlaybackProgress); + playbackVideo.addEventListener('timeupdate', handlePlaybackProgress); + playbackProgressCleanup = () => playbackVideo.removeEventListener('timeupdate', handlePlaybackProgress); hls.on(Hls.Events.MANIFEST_PARSED, function() { if (!isMounted) return; @@ -610,12 +594,6 @@ export function HLSVideoCell({ } }); - // Cleanup playback progress listener - const originalCleanup = cleanup; - cleanup = () => { - videoRef.current?.removeEventListener('timeupdate', handlePlaybackProgress); - originalCleanup(); - }; } // Check if HLS is supported natively (Safari) else if (videoRef.current!.canPlayType('application/vnd.apple.mpegurl')) { @@ -711,6 +689,7 @@ export function HLSVideoCell({ audioPlayRequestTokenRef.current++; manualPlayRequestTokenRef.current++; isMounted = false; + playbackProgressCleanup?.(); // Cancel any queued/in-flight gated preflight if (cellAbortRef.current) {