diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php index bb759f7..ffa0500 100644 --- a/modules/turnero/views/lugar.php +++ b/modules/turnero/views/lugar.php @@ -356,8 +356,61 @@ let hayPendientes = false; let pollingColaId = null; let pollingConsentId = null; -const API = 'modules/turnero/api/'; -const BASE_WA = ''; +const API = 'modules/turnero/api/'; +const BASE_WA = ''; +const LUGAR_NOMBRE = document.getElementById('lbl-lugar-titulo')?.textContent || ''; + +// ── 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 {