Queue message sound while audio is priming
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
let audio: HTMLAudioElement | null = null;
|
||||
let priming = false;
|
||||
let pendingMessagePlay = false;
|
||||
|
||||
async function primeSound(): Promise<void> {
|
||||
if (priming) return;
|
||||
@@ -14,9 +15,14 @@ async function primeSound(): Promise<void> {
|
||||
window.removeEventListener('pointerdown', primeSound);
|
||||
window.removeEventListener('keydown', primeSound);
|
||||
} catch {
|
||||
try { if (audio) audio.muted = false; } catch { /* Audio may be unavailable. */ }
|
||||
// Keep gesture listeners so the next gesture can retry.
|
||||
} finally {
|
||||
try { if (audio) audio.muted = false; } catch { /* Audio may be unavailable. */ }
|
||||
priming = false;
|
||||
if (pendingMessagePlay) {
|
||||
pendingMessagePlay = false;
|
||||
playMessageNotificationSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +30,10 @@ window.addEventListener('pointerdown', primeSound);
|
||||
window.addEventListener('keydown', primeSound);
|
||||
|
||||
export function playMessageNotificationSound(): void {
|
||||
if (priming) {
|
||||
pendingMessagePlay = true;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
audio ??= new Audio('/message-notification.mp3');
|
||||
audio.currentTime = 0;
|
||||
|
||||
Reference in New Issue
Block a user