Update lugar.php

This commit is contained in:
Lizandro Guarnizo
2026-06-16 13:28:14 -05:00
parent b11a7f5f98
commit 1b9c8efaad
+57 -2
View File
@@ -356,8 +356,61 @@ let hayPendientes = false;
let pollingColaId = null;
let pollingConsentId = null;
const API = '<?= BASE_URL ?>modules/turnero/api/';
const BASE_WA = '<?= BASE_URL ?>';
const API = '<?= BASE_URL ?>modules/turnero/api/';
const BASE_WA = '<?= BASE_URL ?>';
const LUGAR_NOMBRE = document.getElementById('lbl-lugar-titulo')?.textContent || '<?= addslashes($lugarNombre) ?>';
// ── Audio / anuncio ───────────────────────────────────────────
let _audioCtx = null;
let _sonidoListo = false;
function _desbloquearAudio() {
if (_sonidoListo) return;
try {
_audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const g = _audioCtx.createGain(); g.gain.value = 0.001;
const o = _audioCtx.createOscillator();
o.connect(g); g.connect(_audioCtx.destination);
o.start(); o.stop(_audioCtx.currentTime + 0.05);
} catch (_) {}
_sonidoListo = true;
}
document.addEventListener('click', _desbloquearAudio, { once: false });
document.addEventListener('touchstart', _desbloquearAudio, { once: false });
function _playBeep() {
if (!_audioCtx) return;
try {
const osc = _audioCtx.createOscillator();
const gain = _audioCtx.createGain();
osc.type = 'sine';
osc.connect(gain); gain.connect(_audioCtx.destination);
osc.frequency.setValueAtTime(880, _audioCtx.currentTime);
osc.frequency.setValueAtTime(1100, _audioCtx.currentTime + 0.1);
osc.frequency.setValueAtTime(880, _audioCtx.currentTime + 0.2);
gain.gain.setValueAtTime(0.35, _audioCtx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.0001, _audioCtx.currentTime + 0.65);
osc.start(_audioCtx.currentTime);
osc.stop(_audioCtx.currentTime + 0.65);
} catch (_) {}
}
function anunciarTurno(codigo) {
_desbloquearAudio();
_playBeep();
if ('speechSynthesis' in window) {
setTimeout(() => {
window.speechSynthesis.cancel();
const letras = codigo.split('').join(' ');
const utt = new SpeechSynthesisUtterance(`Turno ${letras}, pase a ${LUGAR_NOMBRE}`);
utt.lang = 'es-CO';
utt.rate = 0.85;
utt.pitch = 1.05;
utt.volume = 1;
window.speechSynthesis.speak(utt);
}, 700);
}
}
// ── Arranque ──────────────────────────────────────────────────
document.addEventListener('DOMContentLoaded', () => {
@@ -463,6 +516,7 @@ async function _llamar(extra) {
const json = await res.json();
if (!json.ok) { alert('Error: ' + json.error); return; }
if (!json.turno) { alert('Cola del lugar vacía.'); return; }
anunciarTurno(json.turno.codigo);
await abrirFicha(json.turno);
cargarCola();
} catch (err) {
@@ -815,6 +869,7 @@ async function rellamarTurno() {
});
const json = await res.json();
if (!json.ok) alert('Error: ' + json.error);
else if (json.turno) anunciarTurno(json.turno.codigo);
} catch (err) {
alert('Error: ' + err.message);
} finally {