fix(display): corregir turnos que no aparecen en pantalla TV

- sse_turno.php: sleep(2)→sleep(1) para detectar notificarSSE en máx 1s
- display*.php: visibilitychange + focus → fetch inmediato al despertar pantalla
- display*.php: Wake Lock API para evitar throttling del browser en TVs
- display.php: SSE open → cargarSnapshot() inmediato al reconectar

Causa raíz: browsers throttlean setInterval a >1min en tabs sin foco;
las TVs inactivas dejaban de recibir actualizaciones aunque el servidor
las enviara correctamente.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-07 22:47:13 -05:00
co-authored by Claude Sonnet 4.6
parent 8760b685ad
commit d24b234e30
4 changed files with 42 additions and 2 deletions
+19 -1
View File
@@ -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();
});
}
</script>
</body>
</html>