Files
libredesk/frontend/shared-ui/composables/useNotificationSound.js
T
Abhinav Raut 43ebed1c3a WS rewrite: per-client subscriptions and perf improvements
Targets broadcasts via per-tab list and open subs (validated at subscribe time)
instead of broadcasting message uuid to all agents. Adds frontend list typing, throttled sound,
and many perf improvements to reduce cpu memory & database queries.
Other fixes: Enforce message-to-conversation binding in handleGetMessage
2026-05-20 23:42:07 +05:30

22 lines
482 B
JavaScript

import notificationSound from '../assets/notification.mp3'
const PLAY_THROTTLE_MS = 1500
let audio = null
let lastPlayedAt = 0
export function initAudioContext() {
if (audio) return
audio = new Audio(notificationSound)
audio.volume = 0.5
audio.load()
}
export function playNotificationSound() {
if (!audio) return
const now = Date.now()
if (now - lastPlayedAt < PLAY_THROTTLE_MS) return
lastPlayedAt = now
audio.currentTime = 0
audio.play().catch(() => {})
}