Browse Source

Gestion beep mp3 ok et error

master
scayac 2 months ago
parent
commit
7cf42ea1d4
  1. 42
      main/templates/scan.html

42
main/templates/scan.html

@ -105,16 +105,18 @@ document.addEventListener('DOMContentLoaded', function() { @@ -105,16 +105,18 @@ document.addEventListener('DOMContentLoaded', function() {
// plus de bouton OK, plus de gestion de clic
});
function beep() {
const ctx = new(window.AudioContext || window.webkitAudioContext)();
const oscillator = ctx.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(1000, ctx.currentTime);
oscillator.connect(ctx.destination);
oscillator.start();
setTimeout(() => { oscillator.stop(); ctx.close(); }, 150);
function playSound(type) {
if (typeof window.beepEnabled !== 'undefined' && !window.beepEnabled) return;
let audio;
if (type === 'ok') {
audio = new Audio("{% static 'mp3/ok.mp3' %}");
} else {
audio = new Audio("{% static 'mp3/error.mp3' %}");
}
audio.play();
}
let lastScanned = '';
let html5Qrcode;
@ -187,7 +189,6 @@ function onScanSuccess(decodedText, decodedResult) { @@ -187,7 +189,6 @@ function onScanSuccess(decodedText, decodedResult) {
if (decodedText === lastScanned || window.scanDebounce) return;
window.scanDebounce = true;
lastScanned = decodedText;
beep();
const courseId = getCourseIdFromUrl();
if (!courseId) {
window.scanDebounce = false;
@ -205,21 +206,28 @@ function onScanSuccess(decodedText, decodedResult) { @@ -205,21 +206,28 @@ function onScanSuccess(decodedText, decodedResult) {
.then(response => response.text())
.then(html => {
document.getElementById('scanResult').innerHTML = html;
// Détecte succès ou erreur selon la présence d'une classe d'erreur dans la réponse
if (html.includes('alert-danger')) {
playSound('error');
} else {
playSound('ok');
}
setTimeout(function() {
window.scanDebounce = false;
}, 100); // 100ms de délai avant d'autoriser un nouveau scan
})
.catch(() => {
playSound('error');
window.scanDebounce = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
const beepBtn = document.getElementById('toggleBeep');
const beepIcon = document.getElementById('beepIcon');
let beepEnabled = true;
window.beepEnabled = true;
beepBtn.onclick = function() {
beepEnabled = !beepEnabled;
if (beepEnabled) {
window.beepEnabled = !window.beepEnabled;
if (window.beepEnabled) {
beepIcon.classList.remove('fa-volume-mute');
beepIcon.classList.add('fa-volume-up');
beepBtn.title = 'Désactiver bip scan';
@ -229,16 +237,6 @@ document.addEventListener('DOMContentLoaded', function() { @@ -229,16 +237,6 @@ document.addEventListener('DOMContentLoaded', function() {
beepBtn.title = 'Activer bip scan';
}
};
window.beep = function() {
if (!beepEnabled) return;
const ctx = new(window.AudioContext || window.webkitAudioContext)();
const oscillator = ctx.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(1000, ctx.currentTime);
oscillator.connect(ctx.destination);
oscillator.start();
setTimeout(() => { oscillator.stop(); ctx.close(); }, 150);
};
});
Html5Qrcode.getCameras().then(cameras => {

Loading…
Cancel
Save