fix: AudioContext warning when loading widget on Chrome (#3956)

* fix: AudioContext warning when loading widget on Chrome

* minor fixes

* Minor fixes

* adds event on document

* Play audio from parent window through SDK

* Adds notification to dashboard

Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
This commit is contained in:
Sivin Varghese
2022-02-28 21:43:24 +05:30
committed by GitHub
parent eee89bf0d8
commit a3cb26a317
4 changed files with 58 additions and 11 deletions

View File

@@ -21,7 +21,10 @@ import App from '../dashboard/App';
import i18n from '../dashboard/i18n';
import createAxios from '../dashboard/helper/APIHelper';
import commonHelpers, { isJSONValid } from '../dashboard/helper/commons';
import { getAlertAudio } from '../shared/helpers/AudioNotificationHelper';
import {
getAlertAudio,
initOnEvents,
} from '../shared/helpers/AudioNotificationHelper';
import { initFaviconSwitcher } from '../shared/helpers/faviconHelper';
import router from '../dashboard/routes';
import store from '../dashboard/store';
@@ -102,6 +105,13 @@ window.onload = () => {
vueActionCable.init();
};
const setupAudioListeners = () => {
getAlertAudio().then(() => {
initOnEvents.forEach(event => {
document.removeEventListener(event, setupAudioListeners, false);
});
});
};
window.addEventListener('load', () => {
verifyServiceWorkerExistence(registration =>
registration.pushManager.getSubscription().then(subscription => {
@@ -110,6 +120,9 @@ window.addEventListener('load', () => {
}
})
);
getAlertAudio();
window.playAudioAlert = () => {};
initOnEvents.forEach(e => {
document.addEventListener(e, setupAudioListeners, false);
});
initFaviconSwitcher();
});