From cc789f82d5bab3f64ef04dde174997ff97e8e233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 22 Feb 2022 13:35:35 +0000 Subject: [PATCH] [IMP] mail: move rtc recover timeout in its own method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2734101 closes odoo/odoo#85127 Signed-off-by: Sébastien Theys (seb) --- addons/mail/static/src/models/rtc/rtc.js | 46 ++++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/addons/mail/static/src/models/rtc/rtc.js b/addons/mail/static/src/models/rtc/rtc.js index 726fada0c99..bc4cb642152 100644 --- a/addons/mail/static/src/models/rtc/rtc.js +++ b/addons/mail/static/src/models/rtc/rtc.js @@ -684,6 +684,29 @@ registerModel({ } } }, + /** + * @param {string} token + * @param {string} [reason] + */ + async _onRecoverConnectionTimeout(token, reason) { + delete this._fallBackTimeouts[token]; + const peerConnection = this._peerConnections[token]; + if (!peerConnection || !this.channel) { + return; + } + if (this._outGoingCallTokens.has(token)) { + return; + } + if (peerConnection.iceConnectionState === 'connected') { + return; + } + this._addLogEntry(token, `calling back to recover ${peerConnection.iceConnectionState} connection, reason: ${reason}`); + await this._notifyPeers([token], { + event: 'disconnect', + }); + this._removePeer(token); + this._callPeer(token); + }, /** * Pings the server to ensure this session is kept alive. */ @@ -715,25 +738,10 @@ registerModel({ if (this._fallBackTimeouts[token]) { return; } - this._fallBackTimeouts[token] = browser.setTimeout(async () => { - delete this._fallBackTimeouts[token]; - const peerConnection = this._peerConnections[token]; - if (!peerConnection || !this.channel) { - return; - } - if (this._outGoingCallTokens.has(token)) { - return; - } - if (peerConnection.iceConnectionState === 'connected') { - return; - } - this._addLogEntry(token, `calling back to recover ${peerConnection.iceConnectionState} connection, reason: ${reason}`); - await this._notifyPeers([token], { - event: 'disconnect', - }); - this._removePeer(token); - this._callPeer(token); - }, delay); + this._fallBackTimeouts[token] = browser.setTimeout( + this._onRecoverConnectionTimeout.bind(this, token, reason), + delay, + ); }, /** * Cleans up a peer by closing all its associated content and the connection.