fix(scanner): agregar metodos de audio faltantes y blindar handleAdminQrDetected contra excepciones

This commit is contained in:
unknown
2026-10-04 23:27:35 -06:00
parent f1366e5fd5
commit 9ab515fe1a
3 changed files with 136 additions and 78 deletions
+2 -2
View File
@@ -1244,8 +1244,8 @@
</button> </button>
</nav> </nav>
<script src="/js/sounds.js?v=9.2"></script> <script src="/js/sounds.js?v=9.3"></script>
<script src="/js/jsQR.js"></script> <script src="/js/jsQR.js"></script>
<script src="/js/app.js?v=9.2"></script> <script src="/js/app.js?v=9.3"></script>
</body> </body>
</html> </html>
+37 -7
View File
@@ -3004,6 +3004,14 @@ async function startScanAdminCamera() {
} }
}, 1500); }, 1500);
} }
}).catch(err => {
console.error('Error no capturado en detección:', err);
isProcessingAdminScan = false;
if (statusEl && isScanAdminLoopRunning) {
statusEl.textContent = '📷 Enfoca el código QR del carné';
statusEl.style.color = '#0284c7';
statusEl.style.background = '#e0f2fe';
}
}); });
} }
} }
@@ -3047,10 +3055,15 @@ async function handleAdminQrDetected(token) {
const statusEl = document.getElementById('adminScanModalStatus'); const statusEl = document.getElementById('adminScanModalStatus');
const modal = document.getElementById('modalAdminScanQr'); const modal = document.getElementById('modalAdminScanQr');
if (window.sounds) window.sounds.playBeep(); try {
if (window.sounds && typeof window.sounds.playScanChirp === 'function') {
window.sounds.playScanChirp();
}
} catch (e) {}
try {
const parsed = parseScannedStudentToken(token); const parsed = parseScannedStudentToken(token);
const clean = parsed.toLowerCase(); const clean = (parsed || '').toLowerCase();
if (statusEl) { if (statusEl) {
statusEl.textContent = '⏳ Verificando estudiante...'; statusEl.textContent = '⏳ Verificando estudiante...';
@@ -3066,7 +3079,7 @@ async function handleAdminQrDetected(token) {
); );
// 2. Si no se encontró en cache local, buscar en el servidor // 2. Si no se encontró en cache local, buscar en el servidor
if (!student) { if (!student && parsed) {
try { try {
const res = await fetch(`/api/estudiantes/qr/${encodeURIComponent(parsed)}`); const res = await fetch(`/api/estudiantes/qr/${encodeURIComponent(parsed)}`);
if (res.ok) { if (res.ok) {
@@ -3078,7 +3091,7 @@ async function handleAdminQrDetected(token) {
} }
// 3. Fallback con token original sin parsear // 3. Fallback con token original sin parsear
if (!student && parsed !== token) { if (!student && parsed !== token && token) {
try { try {
const res = await fetch(`/api/estudiantes/qr/${encodeURIComponent(String(token).trim())}`); const res = await fetch(`/api/estudiantes/qr/${encodeURIComponent(String(token).trim())}`);
if (res.ok) { if (res.ok) {
@@ -3120,13 +3133,30 @@ async function handleAdminQrDetected(token) {
stopScanAdminCamera(); stopScanAdminCamera();
if (modal) modal.style.display = 'none'; if (modal) modal.style.display = 'none';
if (window.sounds) window.sounds.playSuccess(); try {
if (window.sounds && typeof window.sounds.playSuccess === 'function') {
window.sounds.playSuccess();
}
} catch (e) {}
return true; return true;
} else { } else {
// Si no se encontró, NO cerrar el modal: dar feedback visual claro // Si no se encontró, NO cerrar el modal: dar feedback visual claro
if (window.sounds) window.sounds.playError(); try {
if (window.sounds && typeof window.sounds.playError === 'function') {
window.sounds.playError();
}
} catch (e) {}
if (statusEl) { if (statusEl) {
statusEl.textContent = `❌ Código no reconocido: "${parsed.slice(0, 20)}". Enfoca de nuevo.`; statusEl.textContent = `❌ Código no reconocido: "${String(parsed || token).slice(0, 20)}". Enfoca de nuevo.`;
statusEl.style.color = '#dc2626';
statusEl.style.background = '#fee2e2';
}
return false;
}
} catch (err) {
console.error('Error crítico en handleAdminQrDetected:', err);
if (statusEl) {
statusEl.textContent = '⚠️ Error al verificar estudiante. Intenta de nuevo.';
statusEl.style.color = '#dc2626'; statusEl.style.color = '#dc2626';
statusEl.style.background = '#fee2e2'; statusEl.style.background = '#fee2e2';
} }
+28
View File
@@ -119,6 +119,34 @@ class SoundEffects {
osc.stop(now + 0.35); osc.stop(now + 0.35);
} catch (e) {} } catch (e) {}
} }
// Sonido de clic / tap sutil
playTap() {
try {
this.init();
const now = this.ctx.currentTime;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = 'sine';
osc.frequency.setValueAtTime(600, now);
osc.frequency.exponentialRampToValueAtTime(300, now + 0.04);
gain.gain.setValueAtTime(0.08, now);
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.04);
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.start(now);
osc.stop(now + 0.04);
} catch (e) {}
}
// Sonido de escaneo / beep
playBeep() {
this.playScanChirp();
}
} }
window.sounds = new SoundEffects(); window.sounds = new SoundEffects();