diff --git a/modules/turnero/api/cambiar_estado.php b/modules/turnero/api/cambiar_estado.php index 8a244f0..3c1b312 100644 --- a/modules/turnero/api/cambiar_estado.php +++ b/modules/turnero/api/cambiar_estado.php @@ -145,7 +145,6 @@ try { break; } - $sets[] = 'actualizado_at = NOW()'; $sql = 'UPDATE turnero_turnos SET ' . implode(', ', $sets) . ' WHERE id = ?'; $binds[] = $turnoId; diff --git a/modules/turnero/views/display.php b/modules/turnero/views/display.php index a9b6348..290eb3a 100644 --- a/modules/turnero/views/display.php +++ b/modules/turnero/views/display.php @@ -425,23 +425,32 @@ function escHtml(str) { return d.innerHTML; } -// ── Carga inicial ───────────────────────────────────────────── -async function cargarInicial() { +// ── Carga/polling ───────────────────────────────────────────── +let pollTimer = null; + +async function cargarSnapshot() { const url = new URL(BASE_API + 'get_cola.php', location.href); url.searchParams.set('area', area); if (lugarId) url.searchParams.set('lugar_id', lugarId); try { - const res = await fetch(url.toString()); + const res = await fetch(url.toString(), { cache: 'no-store' }); const json = await res.json(); if (json.ok) renderSnapshot(json); - } catch (_) { /* SSE tomará el relevo */ } + } catch (_) {} +} + +// Arrancar polling cada 4 s (funciona aunque SSE falle por proxy) +function iniciarPolling() { + cargarSnapshot(); + pollTimer = setInterval(cargarSnapshot, 4000); } // ── SSE ─────────────────────────────────────────────────────── const chipEstado = document.getElementById('chip-estado'); let esSource = null; let reconnectDelay = 2000; +let sseViva = false; function conectarSSE() { const sseUrl = new URL(BASE_API + 'sse_turno.php', location.href); @@ -452,6 +461,7 @@ function conectarSSE() { esSource.addEventListener('open', () => { reconnectDelay = 2000; + sseViva = true; chipEstado.className = 'estado-chip conectado'; chipEstado.innerHTML = 'En vivo'; }); @@ -464,6 +474,7 @@ function conectarSSE() { }); esSource.addEventListener('error', () => { + sseViva = false; chipEstado.className = 'estado-chip error'; chipEstado.innerHTML = 'Reconectando…'; esSource.close(); @@ -473,7 +484,7 @@ function conectarSSE() { } // ── Inicio ──────────────────────────────────────────────────── -cargarInicial(); +iniciarPolling(); conectarSSE();