diff --git a/modules/turnero/api/sse_turno.php b/modules/turnero/api/sse_turno.php index a9c57a8..713f09e 100644 --- a/modules/turnero/api/sse_turno.php +++ b/modules/turnero/api/sse_turno.php @@ -130,7 +130,7 @@ $stmt->execute([$sesionId]); $lastPing = $stmt->fetchColumn() ?: null; while (!connection_aborted()) { - sleep(2); + sleep(1); // Leer el último sse_ping_at de la sesión $stmt = $pdo->prepare('SELECT sse_ping_at FROM turnero_sesiones WHERE id = ?'); diff --git a/modules/turnero/views/display.php b/modules/turnero/views/display.php index dba6518..deff002 100644 --- a/modules/turnero/views/display.php +++ b/modules/turnero/views/display.php @@ -558,8 +558,8 @@ function conectarSSE() { esSource.addEventListener('open', () => { reconnectDelay = 2000; sseViva = true; - // SSE conectado → ocultar chip (el polling garantiza actualización) chipEstado.style.display = 'none'; + cargarSnapshot(); // re-fetch inmediato al reconectar (cubre gaps de SSE caído) }); esSource.addEventListener('cola_update', (e) => { @@ -582,6 +582,24 @@ function conectarSSE() { // ── Inicio ──────────────────────────────────────────────────── iniciarPolling(); conectarSSE(); + +// ── Resistir throttling de browser en TVs ──────────────────── +// visibilitychange: pantalla vuelve de reposo o tab recupera foco +document.addEventListener('visibilitychange', () => { + if (!document.hidden) cargarSnapshot(); +}); +window.addEventListener('focus', cargarSnapshot); + +// Wake Lock: evita que el browser suspenda el tab +if ('wakeLock' in navigator) { + async function pedirWakeLock() { + try { await navigator.wakeLock.request('screen'); } catch (_) {} + } + pedirWakeLock(); + document.addEventListener('visibilitychange', () => { + if (!document.hidden) pedirWakeLock(); + }); +} diff --git a/modules/turnero/views/display_global.php b/modules/turnero/views/display_global.php index df1674f..af0f50b 100644 --- a/modules/turnero/views/display_global.php +++ b/modules/turnero/views/display_global.php @@ -739,6 +739,17 @@ async function cargarSnapshot() { cargarSnapshot(); setInterval(cargarSnapshot, 2000); + +document.addEventListener('visibilitychange', () => { if (!document.hidden) cargarSnapshot(); }); +window.addEventListener('focus', cargarSnapshot); + +if ('wakeLock' in navigator) { + async function pedirWakeLock() { + try { await navigator.wakeLock.request('screen'); } catch (_) {} + } + pedirWakeLock(); + document.addEventListener('visibilitychange', () => { if (!document.hidden) pedirWakeLock(); }); +} diff --git a/modules/turnero/views/display_recepcion.php b/modules/turnero/views/display_recepcion.php index a98e4bd..7726787 100644 --- a/modules/turnero/views/display_recepcion.php +++ b/modules/turnero/views/display_recepcion.php @@ -373,6 +373,17 @@ async function cargar() { cargar(); setInterval(cargar, 2000); + +document.addEventListener('visibilitychange', () => { if (!document.hidden) cargar(); }); +window.addEventListener('focus', cargar); + +if ('wakeLock' in navigator) { + async function pedirWakeLock() { + try { await navigator.wakeLock.request('screen'); } catch (_) {} + } + pedirWakeLock(); + document.addEventListener('visibilitychange', () => { if (!document.hidden) pedirWakeLock(); }); +}