Handle undefined AudioContext, resolves #6422 (#6424)

This commit is contained in:
Lee Salminen 2024-11-23 03:52:23 -06:00 committed by GitHub
parent c6fc0302d2
commit 76f87011a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,7 +92,7 @@ function initApp() {
const srvModel = initialSrvModel; const srvModel = initialSrvModel;
return { return {
srvModel, srvModel,
audioContext: new AudioContext(), audioContext: window.AudioContext ? new AudioContext() : null,
displayPaymentDetails: false, displayPaymentDetails: false,
remainingSeconds: srvModel.expirationSeconds, remainingSeconds: srvModel.expirationSeconds,
emailAddressInput: "", emailAddressInput: "",
@ -351,7 +351,7 @@ function initApp() {
}, },
playSound (soundName) { playSound (soundName) {
const audioBuffer = this[soundName + 'Sound']; const audioBuffer = this[soundName + 'Sound'];
if (!audioBuffer || this.audioContext.state === 'suspended') return; if (!audioBuffer || !this.audioContext || this.audioContext.state === 'suspended') return;
const source = this.audioContext.createBufferSource(); const source = this.audioContext.createBufferSource();
source.buffer = audioBuffer; source.buffer = audioBuffer;
source.connect(this.audioContext.destination); source.connect(this.audioContext.destination);
@ -375,6 +375,7 @@ function initApp() {
} }
}, },
async prepareSound (url) { async prepareSound (url) {
if (!this.audioContext) return;
const response = await fetch(url) const response = await fetch(url)
if (!response.ok) return console.error(`Could not load payment sound, HTTP error ${response.status}`); if (!response.ok) return console.error(`Could not load payment sound, HTTP error ${response.status}`);
const arrayBuffer = await response.arrayBuffer(); const arrayBuffer = await response.arrayBuffer();