[FIX] mail: prevents crash when trying to close the audioContext
Before this commit, since https://github.com/odoo/odoo/pull/119014, the audio context could be closed when already. Until the implementation of AudioContext.state*, we have to catch the error. This commit also removes the forwarding to the destination that was not necessary. `* https://webaudio.github.io/web-audio-api/#widl-AudioContext-state closes odoo/odoo#119444 X-original-commit: 0d28d067d2b848701312deea419acc3fe68ab4c9 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
committed by
Sébastien Theys
parent
68508f8bae
commit
74af371bc9
@@ -46,7 +46,14 @@ export async function monitorAudio(track, processorOptions) {
|
||||
processor.disconnect();
|
||||
source.disconnect();
|
||||
monitoredTrack.stop();
|
||||
await audioContext.close();
|
||||
try {
|
||||
await audioContext.close();
|
||||
} catch (e) {
|
||||
if (e.name === "InvalidStateError") {
|
||||
return; // the audio context is already closed
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,7 +85,6 @@ function _loadScriptProcessor(
|
||||
source.connect(analyser);
|
||||
const scriptProcessorNode = audioContext.createScriptProcessor(bitSize, 1, 1);
|
||||
analyser.connect(scriptProcessorNode);
|
||||
analyser.connect(audioContext.destination);
|
||||
analyser.fftsize = bitSize;
|
||||
scriptProcessorNode.connect(audioContext.destination);
|
||||
|
||||
@@ -158,7 +164,6 @@ async function _loadAudioWorkletProcessor(
|
||||
},
|
||||
});
|
||||
source.connect(thresholdProcessor);
|
||||
source.connect(audioContext.destination);
|
||||
thresholdProcessor.port.onmessage = (event) => {
|
||||
const { isAboveThreshold, volume } = event.data;
|
||||
if (isAboveThreshold !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user