fix: Catch audio context errors (#5051)

Prevent errors in decoding and playing sounds from propagating
by catching them in the promise chain.

Fixes #4281.
This commit is contained in:
Chad Burggraf 2022-07-18 20:29:50 -07:00 committed by GitHub
parent 1dc7ce526e
commit 558e3c7499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,19 +16,18 @@ export const getAlertAudio = async (baseUrl = '', type = 'dashboard') => {
};
};
try {
const resourceUrl = `${baseUrl}/audio/${type}/ding.mp3`;
const audioRequest = new Request(resourceUrl);
const resourceUrl = `${baseUrl}/audio/${type}/ding.mp3`;
const audioRequest = new Request(resourceUrl);
fetch(audioRequest)
.then(response => response.arrayBuffer())
.then(buffer => {
audioCtx.decodeAudioData(buffer).then(playsound);
return new Promise(res => res());
});
} catch (error) {
// error
}
fetch(audioRequest)
.then(response => response.arrayBuffer())
.then(buffer => {
audioCtx.decodeAudioData(buffer).then(playsound);
return new Promise(res => res());
})
.catch(() => {
// error
});
};
export const notificationEnabled = (enableAudioAlerts, id, userId) => {