mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
fix: initOnEvents not removed [CW-3594] (#10200)
The `initOnEvents` was used to get the notification sound file and trigger the 30 second loop, but since the function was replaced to using class syntax, the removeEvent listener was not working. This PR fixes it by reverting to the old syntax but moving it inside the constructor instead and also adding a `once: true` to ensure it is always removed automatically
This commit is contained in:
@@ -22,6 +22,21 @@ class DashboardAudioNotificationHelper {
|
||||
this.currentUser = null;
|
||||
this.currentUserId = null;
|
||||
this.audioAlertTone = 'ding';
|
||||
|
||||
this.onAudioListenEvent = async () => {
|
||||
try {
|
||||
await getAlertAudio('', {
|
||||
type: 'dashboard',
|
||||
alertTone: this.audioAlertTone,
|
||||
});
|
||||
initOnEvents.forEach(event => {
|
||||
document.removeEventListener(event, this.onAudioListenEvent, false);
|
||||
});
|
||||
this.playAudioEvery30Seconds();
|
||||
} catch (error) {
|
||||
// Ignore audio fetch errors
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
setInstanceValues({
|
||||
@@ -38,26 +53,13 @@ class DashboardAudioNotificationHelper {
|
||||
this.currentUserId = currentUser.id;
|
||||
this.audioAlertTone = audioAlertTone;
|
||||
initOnEvents.forEach(e => {
|
||||
document.addEventListener(e, this.onAudioListenEvent, false);
|
||||
document.addEventListener(e, this.onAudioListenEvent, {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
initFaviconSwitcher();
|
||||
}
|
||||
|
||||
async onAudioListenEvent() {
|
||||
try {
|
||||
await getAlertAudio('', {
|
||||
type: 'dashboard',
|
||||
alertTone: this.audioAlertTone,
|
||||
});
|
||||
initOnEvents.forEach(event => {
|
||||
document.removeEventListener(event, this.onAudioListenEvent, false);
|
||||
});
|
||||
this.playAudioEvery30Seconds();
|
||||
} catch (error) {
|
||||
// Ignore audio fetch errors
|
||||
}
|
||||
}
|
||||
|
||||
executeRecurringNotification() {
|
||||
if (!window.WOOT_STORE) {
|
||||
this.clearSetTimeout();
|
||||
|
||||
Reference in New Issue
Block a user