Merge pull request #34 from Liquidibrium/master
Removed dependency on window
This commit is contained in:
commit
3037783947
1 changed files with 13 additions and 2 deletions
|
@ -359,12 +359,18 @@ export class Room {
|
||||||
broadcastRoomMessage(this, encoding.toUint8Array(encoderAwareness))
|
broadcastRoomMessage(this, encoding.toUint8Array(encoderAwareness))
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('beforeunload', () => {
|
this._beforeUnloadHandler = () => {
|
||||||
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
|
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
|
||||||
rooms.forEach(room => {
|
rooms.forEach(room => {
|
||||||
room.disconnect()
|
room.disconnect()
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.addEventListener('beforeunload', this._beforeUnloadHandler)
|
||||||
|
} else if (typeof process !== 'undefined') {
|
||||||
|
process.on('exit', this._beforeUnloadHandler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect () {
|
connect () {
|
||||||
|
@ -422,6 +428,11 @@ export class Room {
|
||||||
|
|
||||||
destroy () {
|
destroy () {
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.removeEventListener('beforeunload', this._beforeUnloadHandler)
|
||||||
|
} else if (typeof process !== 'undefined') {
|
||||||
|
process.off('exit', this._beforeUnloadHandler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue