This commit is contained in:
2026-06-30 10:43:11 +07:00
parent d9c8e3930b
commit 6e284e66fa
10 changed files with 247 additions and 51 deletions

View File

@@ -27,6 +27,34 @@ let chatOpen = false;
let chatMessages = [];
let chatConversations = [];
let activeStaffId = 0;
let chatAudioCtx = null;
function playChatSound() {
try {
const Ctx = window.AudioContext || window.webkitAudioContext;
if (!chatAudioCtx) chatAudioCtx = new Ctx();
const ctx = chatAudioCtx;
if (ctx.state === 'suspended') ctx.resume();
const tone = (freq, start, dur) => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.type = 'sine';
osc.frequency.value = freq;
gain.gain.setValueAtTime(0.0001, start);
gain.gain.exponentialRampToValueAtTime(0.15, start + 0.02);
gain.gain.exponentialRampToValueAtTime(0.0001, start + dur);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(start);
osc.stop(start + dur + 0.02);
};
const t = ctx.currentTime;
tone(880, t, 0.12);
tone(1174, t + 0.14, 0.14);
} catch {
/* ignore */
}
}
// Quản lý webcam
let webcamStream = null;
@@ -51,14 +79,18 @@ function init() {
window.runtime.EventsOn('start_webcam_stream', startWebcam);
window.runtime.EventsOn('stop_webcam_stream', stopWebcam);
window.runtime.EventsOn('chat:message', () => {
window.runtime.EventsOn('chat:message', (data) => {
updateChatBadge();
loadChatConversations().catch(console.error);
if (chatOpen && activeStaffId) loadChatMessages(activeStaffId).catch(console.error);
if (data?.senderRole === 'staff') {
playChatSound();
}
});
window.runtime.EventsOn('chat:notify', (data) => {
updateChatBadge();
showChatToast(data);
playChatSound();
});
checkLogin();
}