From 20c8e02c12eabee2016baea5ef46a49ebd7ab702 Mon Sep 17 00:00:00 2001 From: Yousef Date: Tue, 9 Nov 2021 17:48:33 +0100 Subject: [PATCH] Update y-webrtc.js --- src/y-webrtc.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/y-webrtc.js b/src/y-webrtc.js index 33422df..4b141cb 100644 --- a/src/y-webrtc.js +++ b/src/y-webrtc.js @@ -358,8 +358,7 @@ export class Room { encoding.writeVarUint8Array(encoderAwareness, awarenessProtocol.encodeAwarenessUpdate(this.awareness, changedClients)) broadcastRoomMessage(this, encoding.toUint8Array(encoderAwareness)) } - this.doc.on('update', this._docUpdateHandler) - this.awareness.on('update', this._awarenessUpdateHandler) + window.addEventListener('beforeunload', () => { awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload') rooms.forEach(room => { @@ -369,6 +368,9 @@ export class Room { } connect () { + this.doc.on('update', this._docUpdateHandler) + this.awareness.on('update', this._awarenessUpdateHandler) + // signal through all available signaling connections announceSignalingInfo(this) const roomName = this.name