fix(ui): throttle audio notification (#869)

This commit is contained in:
Jannis Mattheis 2025-11-06 20:15:12 +01:00 committed by GitHub
commit 2b67bc33cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,8 @@ import {reaction} from 'mobx';
import * as Notifications from './snack/browserNotification';
import {StoreMapping} from './stores';
const AUDIO_REPEAT_DELAY = 1000;
export const registerReactions = (stores: StoreMapping) => {
const clearAll = () => {
stores.messagesStore.clearAll();
@ -10,13 +12,19 @@ export const registerReactions = (stores: StoreMapping) => {
stores.userStore.clear();
stores.wsStore.close();
};
let audio: HTMLAudioElement | undefined;
let lastAudio = 0;
const loadAll = () => {
stores.wsStore.listen((message) => {
stores.messagesStore.publishSingleMessage(message);
Notifications.notifyNewMessage(message);
if (message.priority >= 4) {
const src = 'static/notification.ogg';
const audio = new Audio(src);
if (message.priority >= 4 && Date.now() > lastAudio + AUDIO_REPEAT_DELAY) {
lastAudio = Date.now();
audio ??= new Audio('static/notification.ogg');
audio.currentTime = 0;
audio.play();
}
});