From 74af371bc95d3c48ea360c290f0131f24b209552 Mon Sep 17 00:00:00 2001 From: Thanh Dodeur Date: Fri, 21 Apr 2023 20:21:20 +0000 Subject: [PATCH] [FIX] mail: prevents crash when trying to close the audioContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/mail/static/src/rtc/media_monitoring.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/rtc/media_monitoring.js b/addons/mail/static/src/rtc/media_monitoring.js index b50e448fb65..b6841cdae22 100644 --- a/addons/mail/static/src/rtc/media_monitoring.js +++ b/addons/mail/static/src/rtc/media_monitoring.js @@ -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) {