From d7dea4c68d6877df0b0bd30445eca47f63cc0d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 21 Feb 2022 15:02:22 +0000 Subject: [PATCH] [IMP] mail: turn "Rtc/pingInterval" into field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2734101 closes odoo/odoo#85029 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/models/rtc.js | 53 ++++++++++++++++++---------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/addons/mail/static/src/models/rtc.js b/addons/mail/static/src/models/rtc.js index 4d10b6c8967..3f1f50a1e44 100644 --- a/addons/mail/static/src/models/rtc.js +++ b/addons/mail/static/src/models/rtc.js @@ -43,30 +43,12 @@ registerModel({ browser.addEventListener('keyup', this._onKeyUp); // Disconnects the RTC session if the page is closed or reloaded. browser.addEventListener('beforeunload', this._onBeforeUnload); - /** - * Call all sessions for which no peerConnection is established at - * a regular interval to try to recover any connection that failed - * to start. - * - * This is distinct from this._recoverConnection which tries to restores - * connection that were established but failed or timed out. - */ - this._intervalId = browser.setInterval(async () => { - if (!this.currentRtcSession || !this.channel) { - return; - } - await this._pingServer(); - if (!this.currentRtcSession || !this.channel) { - return; - } - this._callSessions(); - }, 30000); // 30 seconds }, async _willDelete() { browser.removeEventListener('beforeunload', this._onBeforeUnload); browser.removeEventListener('keydown', this._onKeyDown); browser.removeEventListener('keyup', this._onKeyUp); - browser.clearInterval(this._intervalId); + this.messaging.browser.clearInterval(this.pingInterval); }, }, recordMethods: { @@ -423,6 +405,13 @@ registerModel({ _computeIsClientRtcCompatible() { return window.RTCPeerConnection && window.MediaStream; }, + /** + * @private + * @returns {integer} + */ + _computePingInterval() { + return this.messaging.browser.setInterval(this._onPingInterval, 30000); // 30 seconds + }, /** * Creates and setup a RTCPeerConnection. * @@ -1195,6 +1184,19 @@ registerModel({ this.messaging.userSetting.voiceActiveDuration || 0, ); }, + /** + * @private + */ + async _onPingInterval() { + if (!this.currentRtcSession || !this.channel) { + return; + } + await this._pingServer(); + if (!this.currentRtcSession || !this.channel) { + return; + } + this._callSessions(); + }, /** * @private * @param {boolean} isAboveThreshold @@ -1278,6 +1280,19 @@ registerModel({ peerNotificationWaitDelay: attr({ default: 50, }), + /** + * Interval to regularly ping and connect to RTC sessions. + * + * - Ping is to update rtc sessions of the channel, i.e. add or remove rtc sessions. + * This also deals with possible race conditions that could make us unaware of some sessions. + * - Connect to RTC sessions for which no peerConnection is established, to try to recover any + * connection that failed to start. + * This is distinct from this._recoverConnection which tries to restores connection that were + * established but failed or timed out. + */ + pingInterval: attr({ + compute: '_computePingInterval', + }), /** * How long to wait before considering a connection as needing recovery in ms. */