Seperated _beforeUnloadHandler for NodeJS
This commit is contained in:
parent
c059b8679e
commit
c6a88a130b
1 changed files with 8 additions and 2 deletions
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue