diff --git a/web/js/components/preact/HLSVideoCell.tsx b/web/js/components/preact/HLSVideoCell.tsx index ed38ee004..27104ffdf 100644 --- a/web/js/components/preact/HLSVideoCell.tsx +++ b/web/js/components/preact/HLSVideoCell.tsx @@ -95,8 +95,17 @@ export function HLSVideoCell({ useEffect(() => { if (privacyActive) { + const focused = document.activeElement; + const container = tileContainerRef.current; + const focusedInTile = focused instanceof Node && !!container?.contains(focused); + + if (!focusedInTile && focused !== document.body) { + hadPrivacyFocusRef.current = false; + previousFocusedElementRef.current = null; + return; + } + if (!hadPrivacyFocusRef.current) { - const focused = document.activeElement; previousFocusedElementRef.current = focused instanceof HTMLElement && focused !== document.body ? focused : null; } @@ -106,6 +115,13 @@ export function HLSVideoCell({ } if (!hadPrivacyFocusRef.current) return; + if (document.activeElement !== privacyResumeButtonRef.current && + document.activeElement !== document.body) { + hadPrivacyFocusRef.current = false; + previousFocusedElementRef.current = null; + return; + } + hadPrivacyFocusRef.current = false; const previous = previousFocusedElementRef.current; if (previous && previous.isConnected) { @@ -403,8 +419,8 @@ export function HLSVideoCell({ console.log(`Using HLS.js for stream ${stream.name} (mode: ${usingGo2rtc ? 'go2rtc' : 'native'})`); // Shared low-memory budget: keep only a small forward buffer and zero back-buffer. - // backBufferLength: 0 is the single biggest win — HLS.js default keeps decoded - // frames forever for seeking, which multiplies by stream count and crashes the tab. + // backBufferLength: 0 removes played media from the buffer as playback advances, + // which helps reduce memory pressure across many concurrent streams. const sharedMemoryConfig = { maxBufferLength: 4, // seconds of forward buffer (default: 30) maxMaxBufferLength: 8, // hard ceiling (default: 600)