[IMP] mail: turn "RtcSession/broadcastTimeout" into field

Task-2734101

closes odoo/odoo#85020

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-03-11 17:04:50 +00:00
parent 0386f1432a
commit 714854a9cb
@@ -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