fix: don't clear bells when browser tab is hidden

sendHeartbeat() always reported _viewingSession even when the user
switched to another browser tab. The server saw 'device is watching
session X' and cleared bells immediately. Fix: use Page Visibility API
(document.hidden) to send viewing_session=null when the tab is in the
background. Bells accumulate correctly, favicon badge shows activity,
and indicators appear in the dashboard/sidebar. When the user switches
back to the muxplex tab, the next heartbeat restores the real session.
This commit is contained in:
Brian Krabach
2026-03-30 19:03:27 -07:00
parent 79576bcbfe
commit 70da8dad38
+8 -1
View File
@@ -764,7 +764,14 @@ function handleBellTransitions(prevSessions, nextSessions) {
*/
async function sendHeartbeat() {
try {
const payload = buildHeartbeatPayload(_deviceId, _viewingSession, _viewMode, _lastInteractionAt);
// When the browser tab is hidden (user switched tabs or minimized), report
// viewing_session as null. This prevents the server from clearing bells on
// the session — the user isn't actually looking at it, so activity should
// accumulate and show in the favicon badge / tab indicators.
var effectiveSession = (typeof document !== 'undefined' && document.hidden)
? null
: _viewingSession;
const payload = buildHeartbeatPayload(_deviceId, effectiveSession, _viewMode, _lastInteractionAt);
await api('POST', '/api/heartbeat', payload);
} catch (err) {
console.warn('[sendHeartbeat] heartbeat failed:', err);