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