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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user