From 7544078420326d93d0671adf9fe1d769a0314efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 21 Feb 2022 15:06:44 +0000 Subject: [PATCH] [IMP] mail: turn "RtcSession/isConnected" into field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2734101 closes odoo/odoo#85032 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/models/rtc.js | 20 ++++++++++---------- addons/mail/static/src/models/rtc_session.js | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/addons/mail/static/src/models/rtc.js b/addons/mail/static/src/models/rtc.js index 125a7f71d62..4315c0d9f0b 100644 --- a/addons/mail/static/src/models/rtc.js +++ b/addons/mail/static/src/models/rtc.js @@ -35,11 +35,6 @@ registerModel({ */ this._dataChannels = {}; /** - * Set of RtcSession.ids, used to track which calls are outgoing, - * which is used when attempting to recover a failed peer connection by - * inverting the call direction. - */ - this._outGoingCallTokens = new Set(); /** * Object { token: peerConnection } * Contains the RTCPeerConnection established with the other rtc sessions. @@ -212,12 +207,14 @@ registerModel({ this.videoTrack && this.videoTrack.stop(); this._dataChannels = {}; - this._outGoingCallTokens = new Set(); this._peerConnections = {}; for (const rtcSession of this.messaging.models['RtcSession'].all()) { this.messaging.browser.clearTimeout(rtcSession.connectionRecoveryTimeout); - rtcSession.update({ connectionRecoveryTimeout: clear() }); + rtcSession.update({ + connectionRecoveryTimeout: clear(), + isConnected: clear(), + }); } this.update({ currentRtcSession: clear(), @@ -402,7 +399,7 @@ registerModel({ for (const trackKind of TRANSCEIVER_ORDER) { await this._updateRemoteTrack(peerConnection, trackKind, { initTransceiver: true, sessionId: rtcSession.id }); } - this._outGoingCallTokens.add(rtcSession.id); + rtcSession.update({ isConnected: true }); }, /** * Call all the sessions that do not have an already initialized peerConnection. @@ -692,7 +689,7 @@ registerModel({ if (!peerConnection || !this.channel) { return; } - if (this._outGoingCallTokens.has(rtcSession.id)) { + if (rtcSession.isConnected) { return; } if (peerConnection.iceConnectionState === 'connected') { @@ -765,7 +762,10 @@ registerModel({ peerConnection.close(); } delete this._peerConnections[sessionId]; - this._outGoingCallTokens.delete(sessionId); + this.messaging.models['RtcSession'].insert({ + id: sessionId, + isConnected: false, + }); this._addLogEntry(sessionId, 'peer removed', { step: 'peer removed' }); }, /** diff --git a/addons/mail/static/src/models/rtc_session.js b/addons/mail/static/src/models/rtc_session.js index 3f1fb88320d..365969e9705 100644 --- a/addons/mail/static/src/models/rtc_session.js +++ b/addons/mail/static/src/models/rtc_session.js @@ -327,6 +327,14 @@ registerModel({ isCameraOn: attr({ default: false, }), + /** + * States whether this RTC session is connected. + * Useful when attempting to recover a failed peer connection by + * inverting the call direction. + */ + isConnected: attr({ + default: false, + }), /** * Determines if the user is deafened, which means that all incoming * audio tracks are disabled.