Skip to content

Commit

Permalink
Seperated _beforeUnloadHandler for NodeJS
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquidibrium committed Apr 24, 2022
1 parent c059b86 commit c6a88a1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/y-webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,18 @@ export class Room {
broadcastRoomMessage(this, encoding.toUint8Array(encoderAwareness))
}

window.addEventListener('beforeunload', () => {
this._beforeUnloadHandler = () => {
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
rooms.forEach(room => {
room.disconnect()
})
})
}

if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', this._beforeUnloadHandler)
} else if (typeof process !== 'undefined') {
process.on('exit', this._beforeUnloadHandler)
}
}

connect () {
Expand Down

0 comments on commit c6a88a1

Please sign in to comment.