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

Task-2734101

closes odoo/odoo#85027

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-03-14 10:37:57 +00:00
parent 8f7d64e2de
commit 94d0c266fd
2 changed files with 17 additions and 14 deletions
+14 -14
View File
@@ -35,11 +35,6 @@ registerModel({
* Contains the RTCDataChannels with the other rtc sessions.
*/
this._dataChannels = {};
/**
* Object { token: timeoutId<Number> }
* Contains the timeoutIds of the reconnection attempts.
*/
this._fallBackTimeouts = {};
/**
* Set of peerTokens, used to track which calls are outgoing,
* which is used when attempting to recover a failed peer connection by
@@ -218,10 +213,13 @@ registerModel({
this.videoTrack && this.videoTrack.stop();
this._dataChannels = {};
this._fallBackTimeouts = {};
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() });
}
this.update({
currentRtcSession: clear(),
disconnectAudioMonitor: clear(),
@@ -690,7 +688,8 @@ registerModel({
* @param {string} [reason]
*/
async _onRecoverConnectionTimeout(token, reason) {
delete this._fallBackTimeouts[token];
const rtcSession = this.messaging.models['RtcSession'].insert({ id: token });
rtcSession.update({ connectionRecoveryTimeout: clear() });
const peerConnection = this._peerConnections[token];
if (!peerConnection || !this.channel) {
return;
@@ -736,13 +735,16 @@ registerModel({
* @param {string} [param1.reason]
*/
_recoverConnection(token, { delay = 0, reason = '' } = {}) {
if (this._fallBackTimeouts[token]) {
const rtcSession = this.messaging.models['RtcSession'].insert({ id: token });
if (rtcSession.connectionRecoveryTimeout) {
return;
}
this._fallBackTimeouts[token] = browser.setTimeout(
this._onRecoverConnectionTimeout.bind(this, token, reason),
delay,
);
rtcSession.update({
connectionRecoveryTimeout: this.messaging.browser.setTimeout(
this._onRecoverConnectionTimeout.bind(this, token, reason),
delay,
),
});
},
/**
* Cleans up a peer by closing all its associated content and the connection.
@@ -766,8 +768,6 @@ registerModel({
peerConnection.close();
}
delete this._peerConnections[token];
browser.clearTimeout(this._fallBackTimeouts[token]);
delete this._fallBackTimeouts[token];
this._outGoingCallTokens.delete(token);
this._addLogEntry(token, 'peer removed', { step: 'peer removed' });
},
@@ -18,11 +18,13 @@ registerModel({
*/
reset() {
this.messaging.browser.clearTimeout(this.broadcastTimeout);
this.messaging.browser.clearTimeout(this.connectionRecoveryTimeout);
this._removeAudio();
this.removeVideo();
this.update({
audioElement: clear(),
broadcastTimeout: clear(),
connectionRecoveryTimeout: clear(),
isTalking: clear(),
});
},
@@ -287,6 +289,7 @@ registerModel({
channel: one('Thread', {
inverse: 'rtcSessions',
}),
connectionRecoveryTimeout: attr(),
/**
* State of the connection with this session, uses RTCPeerConnection.iceConnectionState
* once a peerConnection has been initialized.