From 714854a9cbccbb01ac65c4953854279a47517838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 21 Feb 2022 14:21:33 +0000 Subject: [PATCH] [IMP] mail: turn "RtcSession/broadcastTimeout" into field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2734101 closes odoo/odoo#85020 Signed-off-by: Sébastien Theys (seb) --- .../src/models/rtc_session/rtc_session.js | 63 ++++++++----------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/addons/mail/static/src/models/rtc_session/rtc_session.js b/addons/mail/static/src/models/rtc_session/rtc_session.js index f6136d2b254..f478e93abfc 100644 --- a/addons/mail/static/src/models/rtc_session/rtc_session.js +++ b/addons/mail/static/src/models/rtc_session/rtc_session.js @@ -1,7 +1,5 @@ /** @odoo-module **/ -import { browser } from "@web/core/browser/browser"; - import { registerModel } from '@mail/model/model_core'; import { attr, many, one } from '@mail/model/model_field'; import { clear } from '@mail/model/model_field_command'; @@ -10,9 +8,6 @@ registerModel({ name: 'RtcSession', identifyingFields: ['id'], lifecycleHooks: { - _created() { - this._timeoutId = undefined; - }, _willDelete() { this.reset(); }, @@ -22,11 +17,12 @@ registerModel({ * restores the session to its default values */ reset() { - this._timeoutId && browser.clearTimeout(this._timeoutId); + this.messaging.browser.clearTimeout(this.broadcastTimeout); this._removeAudio(); this.removeVideo(); this.update({ audioElement: clear(), + broadcastTimeout: clear(), isTalking: clear(), }); }, @@ -147,28 +143,10 @@ registerModel({ return; } this.update(data); - this._debounce(async () => { - if (!this.exists()) { - return; - } - await this.async(() => { - this.env.services.rpc( - { - route: '/mail/rtc/session/update_and_broadcast', - params: { - session_id: this.id, - values: { - is_camera_on: this.isCameraOn, - is_deaf: this.isDeaf, - is_muted: this.isSelfMuted, - is_screen_sharing_on: this.isScreenSharingOn, - }, - }, - }, - { shadow: true } - ); - }); - }, 3000); + this.messaging.browser.clearTimeout(this.broadcastTimeout); + this.update({ + broadcastTimeout: this.messaging.browser.setTimeout(this._onBroadcastTimeout, 3000), + }); }, /** * @private @@ -239,14 +217,26 @@ registerModel({ /** * @private */ - _debounce(f, delay) { - this._timeoutId && browser.clearTimeout(this._timeoutId); - this._timeoutId = browser.setTimeout(() => { - if (!this.exists()) { - return; - } - f(); - }, delay); + _onBroadcastTimeout() { + if (!this.exists()) { + return; + } + this.update({ broadcastTimeout: clear() }); + this.env.services.rpc( + { + route: '/mail/rtc/session/update_and_broadcast', + params: { + session_id: this.id, + values: { + is_camera_on: this.isCameraOn, + is_deaf: this.isDeaf, + is_muted: this.isSelfMuted, + is_screen_sharing_on: this.isScreenSharingOn, + }, + }, + }, + { shadow: true }, + ); }, /** * cleanly removes the audio stream of the session @@ -289,6 +279,7 @@ registerModel({ avatarUrl: attr({ compute: '_computeAvatarUrl', }), + broadcastTimeout: attr(), /** * The mail.channel of the session, rtc sessions are part and managed by * mail.channel