diff --git a/addons/web_editor/static/src/js/wysiwyg/PeerToPeer.js b/addons/web_editor/static/src/js/wysiwyg/PeerToPeer.js index bf76695b9c1..36072e7a054 100644 --- a/addons/web_editor/static/src/js/wysiwyg/PeerToPeer.js +++ b/addons/web_editor/static/src/js/wysiwyg/PeerToPeer.js @@ -84,7 +84,7 @@ const baseNotificationMethods = { 'An offer has been received for a non-existent peer connection - client: ' + notification.fromClientId, ); - console.trace(pc.connectionState); + console.trace(pc && pc.connectionState); console.groupEnd(); } return; @@ -181,8 +181,8 @@ export class PeerToPeer { return Object.entries(this.clientsInfos) .filter( ([id, infos]) => - infos.peerConnection.iceConnectionState === 'connected' && - infos.dataChannel.readyState === 'open', + infos.peerConnection && infos.peerConnection.iceConnectionState === 'connected' && + infos.dataChannel && infos.dataChannel.readyState === 'open', ) .map(([id]) => id); } @@ -194,8 +194,8 @@ export class PeerToPeer { if (!clientInfos) return; clearTimeout(clientInfos.fallbackTimeout); clearTimeout(clientInfos.zombieTimeout); - clientInfos.dataChannel.close(); - clientInfos.peerConnection.close(); + clientInfos.dataChannel && clientInfos.dataChannel.close(); + clientInfos.peerConnection && clientInfos.peerConnection.close(); delete this.clientsInfos[clientId]; } @@ -381,6 +381,10 @@ export class PeerToPeer { iceCandidateBuffer: [], backoffFactor: 0, }; + + if (!navigator.onLine) { + return this.clientsInfos[clientId]; + } const pc = new RTCPeerConnection(this.options.peerConnectionConfig); if (makeOffer) { @@ -425,10 +429,12 @@ export class PeerToPeer { this.removeClient(clientId); break; case 'disconnected': - await this._recoverConnection(clientId, { - delay: 3000, - reason: 'ice connection disconnected', - }); + if (navigator.onLine) { + await this._recoverConnection(clientId, { + delay: 3000, + reason: 'ice connection disconnected', + }); + } break; case 'connected': this.clientsInfos[clientId].backoffFactor = 0; @@ -445,10 +451,12 @@ export class PeerToPeer { this.removeClient(clientId); break; case 'disconnected': - await this._recoverConnection(clientId, { - delay: 3000, - reason: 'connection disconnected', - }); + if (navigator.onLine) { + await this._recoverConnection(clientId, { + delay: 3000, + reason: 'connection disconnected', + }); + } break; case 'connected': case 'completed': @@ -618,7 +626,7 @@ export class PeerToPeer { // If there is no connection after 10 seconds, terminate. clientInfos.zombieTimeout = setTimeout(() => { - if (clientInfos && clientInfos.dataChannel.readyState !== 'open') { + if (clientInfos && clientInfos.dataChannel && clientInfos.dataChannel.readyState !== 'open') { if (debugShowLog) console.log(`%c KILL ZOMBIE ${clientId}`, 'background: red;'); this.removeClient(clientId); } else { diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index ab7c6d0e51f..3dc9d3ad648 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -829,7 +829,7 @@ export class Wysiwyg extends Component { const clientsInfos = Object.values(this.ptp.clientsInfos); const couldBeDisconnected = Boolean(clientsInfos.length) && - clientsInfos.every((x) => PTP_CLIENT_DISCONNECTED_STATES.includes(x.peerConnection.connectionState)); + clientsInfos.every((x) => PTP_CLIENT_DISCONNECTED_STATES.includes(x.peerConnection && x.peerConnection.connectionState)); if (couldBeDisconnected) { this._offlineTimeout = setTimeout(() => {