[IMP] mail: move rtc recover timeout in its own method

Task-2734101

closes odoo/odoo#85127

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-03-04 19:04:42 +00:00
parent 6f4f3699bf
commit cc789f82d5
+27 -19
View File
@@ -684,6 +684,29 @@ registerModel({
}
}
},
/**
* @param {string} token
* @param {string} [reason]
*/
async _onRecoverConnectionTimeout(token, reason) {
delete this._fallBackTimeouts[token];
const peerConnection = this._peerConnections[token];
if (!peerConnection || !this.channel) {
return;
}
if (this._outGoingCallTokens.has(token)) {
return;
}
if (peerConnection.iceConnectionState === 'connected') {
return;
}
this._addLogEntry(token, `calling back to recover ${peerConnection.iceConnectionState} connection, reason: ${reason}`);
await this._notifyPeers([token], {
event: 'disconnect',
});
this._removePeer(token);
this._callPeer(token);
},
/**
* Pings the server to ensure this session is kept alive.
*/
@@ -715,25 +738,10 @@ registerModel({
if (this._fallBackTimeouts[token]) {
return;
}
this._fallBackTimeouts[token] = browser.setTimeout(async () => {
delete this._fallBackTimeouts[token];
const peerConnection = this._peerConnections[token];
if (!peerConnection || !this.channel) {
return;
}
if (this._outGoingCallTokens.has(token)) {
return;
}
if (peerConnection.iceConnectionState === 'connected') {
return;
}
this._addLogEntry(token, `calling back to recover ${peerConnection.iceConnectionState} connection, reason: ${reason}`);
await this._notifyPeers([token], {
event: 'disconnect',
});
this._removePeer(token);
this._callPeer(token);
}, delay);
this._fallBackTimeouts[token] = browser.setTimeout(
this._onRecoverConnectionTimeout.bind(this, token, reason),
delay,
);
},
/**
* Cleans up a peer by closing all its associated content and the connection.