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
+1 -1
View File
@@ -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 = ?');
+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>
+11
View File
@@ -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(); });
}
</script>
</body>
</html>
@@ -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(); });
}
</script>
</body>
</html>