add on exit handler for Node.js environments

This commit is contained in:
Hans Pagel 2021-02-23 23:22:21 +01:00 committed by GitHub
parent 9d7e5eaec8
commit 42cf230ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,9 +276,18 @@ export class WebsocketProvider extends Observable {
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, changedClients))
broadcastMessage(this, encoding.toUint8Array(encoder))
}
if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', () => {
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
})
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload');
});
}
else if (typeof process !== 'undefined') {
process.on('exit', () => {
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload');
});
}
awareness.on('update', this._awarenessUpdateHandler)
this._checkInterval = /** @type {any} */ (setInterval(() => {
if (this.wsconnected && messageReconnectTimeout < time.getUnixTime() - this.wsLastMessageReceived) {