diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index f5a1b156b1e..2af7a468c6a 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -390,7 +390,7 @@ const Wysiwyg = Widget.extend({ this._collaborationChannelName = channelName; Wysiwyg.activeCollaborationChannelNames.add(channelName); - this.call('bus_service', 'addEventListener', 'notification', ({ detail: notifications}) => { + const collaborationBusListener = ({ detail: notifications}) => { for (const { payload, type } of notifications) { if ( type === 'editor_collaboration' && @@ -401,8 +401,14 @@ const Wysiwyg = Widget.extend({ this._peerToPeerLoading.then(() => this.ptp.handleNotification(payload)); } } - }); + } + this.call('bus_service', 'addEventListener', 'notification', collaborationBusListener); this.call('bus_service', 'addChannel', this._collaborationChannelName); + this._collaborationStopBus = () => { + Wysiwyg.activeCollaborationChannelNames.delete(this._collaborationChannelName); + this.call('bus_service', 'removeEventListener', 'notification', collaborationBusListener); + this.call('bus_service', 'deleteChannel', this._collaborationChannelName); + } // const syncHistory = async (fromClientId) => { // } @@ -680,7 +686,7 @@ const Wysiwyg = Widget.extend({ // If peer to peer is initializing, wait for properly closing it. if (this._peerToPeerLoading) { this._peerToPeerLoading.then(()=> { - this.call('bus_service', 'deleteChannel', this._collaborationChannelName); + this._collaborationStopBus(); this.ptp.closeAllConnections(); }); } @@ -2347,11 +2353,15 @@ const Wysiwyg = Widget.extend({ // No need for secure random number. return Math.floor(Math.random() * Math.pow(2, 52)).toString(); }, - _resetEditor: function (value) { + resetEditor: function (value, { collaborationChannel } = {}) { if (!this.ptp) { return; } this.ptp.stop(); + if (collaborationChannel) { + this._collaborationStopBus(); + this.setupCollaboration(collaborationChannel); + } this._currentClientId = this._generateClientId(); this._startCollaborationTime = new Date().getTime(); this.ptp = this._getNewPtp();