ass
This commit is contained in:
@@ -973,17 +973,20 @@ func (a *App) connectWS() {
|
||||
case "stop_webcam_stream":
|
||||
runtime.EventsEmit(a.ctx, "stop_webcam_stream")
|
||||
case "chat:message":
|
||||
if staffVal, ok := msg.Data["staffId"].(float64); ok {
|
||||
a.mu.Lock()
|
||||
a.replyStaffID = uint(staffVal)
|
||||
a.chatUnread++
|
||||
unread := a.chatUnread
|
||||
a.mu.Unlock()
|
||||
runtime.EventsEmit(a.ctx, "chat:notify", map[string]any{
|
||||
"unread": unread,
|
||||
"preview": msg.Data["body"],
|
||||
"from": msg.Data["staffName"],
|
||||
})
|
||||
senderRole, _ := msg.Data["senderRole"].(string)
|
||||
if senderRole == "staff" {
|
||||
if staffVal, ok := msg.Data["staffId"].(float64); ok {
|
||||
a.mu.Lock()
|
||||
a.replyStaffID = uint(staffVal)
|
||||
a.chatUnread++
|
||||
unread := a.chatUnread
|
||||
a.mu.Unlock()
|
||||
runtime.EventsEmit(a.ctx, "chat:notify", map[string]any{
|
||||
"unread": unread,
|
||||
"preview": msg.Data["body"],
|
||||
"from": msg.Data["staffName"],
|
||||
})
|
||||
}
|
||||
}
|
||||
runtime.EventsEmit(a.ctx, "chat:message", msg.Data)
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user