[FIX] web_editor: properly stop collaboration bus listeners

Prior to this commit, the collaboration channel was never deleted
when the wysiwyg was destroyed or resetted.

task-2898432

Part-of: odoo/odoo#94875
This commit is contained in:
Nicolas Bayet
2022-09-12 11:37:59 +02:00
parent 4645bdd5a7
commit 586ef5465b
@@ -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();