Skip to content

Commit aeb10f3

Browse files
authored
Merge branch 'yjs:master' into master
2 parents 0fb45ce + 25ee3f0 commit aeb10f3

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "y-websocket",
3-
"version": "1.5.0",
3+
"version": "1.5.3",
44
"description": "Websockets provider for Yjs",
55
"main": "./dist/y-websocket.cjs",
66
"module": "./src/y-websocket.js",
@@ -33,7 +33,8 @@
3333
".": {
3434
"module": "./src/y-websocket.js",
3535
"import": "./src/y-websocket.js",
36-
"require": "./dist/y-websocket.cjs"
36+
"require": "./dist/y-websocket.cjs",
37+
"types": "./dist/src/y-websocket.d.ts"
3738
}
3839
},
3940
"repository": {
@@ -73,5 +74,9 @@
7374
"optionalDependencies": {
7475
"ws": "^6.2.1",
7576
"y-leveldb": "^0.1.0"
77+
},
78+
"engines": {
79+
"npm": ">=8.0.0",
80+
"node": ">=16.0.0"
7681
}
7782
}

src/y-websocket.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as awarenessProtocol from 'y-protocols/awareness'
1515
import { Observable } from 'lib0/observable'
1616
import * as math from 'lib0/math'
1717
import * as url from 'lib0/url'
18+
import * as env from 'lib0/environment'
1819

1920
export const messageSync = 0
2021
export const messageQueryAwareness = 3
@@ -350,17 +351,15 @@ export class WebsocketProvider extends Observable {
350351
)
351352
broadcastMessage(this, encoding.toUint8Array(encoder))
352353
}
353-
this._unloadHandler = () => {
354+
this._exitHandler = () => {
354355
awarenessProtocol.removeAwarenessStates(
355356
this.awareness,
356357
[doc.clientID],
357-
'window unload'
358+
'app closed'
358359
)
359360
}
360-
if (typeof window !== 'undefined') {
361-
window.addEventListener('unload', this._unloadHandler)
362-
} else if (typeof process !== 'undefined') {
363-
process.on('exit', this._unloadHandler)
361+
if (env.isNode && typeof process !== 'undefined') {
362+
process.on('exit', this._exitHandler)
364363
}
365364
awareness.on('update', this._awarenessUpdateHandler)
366365
this._checkInterval = /** @type {any} */ (setInterval(() => {
@@ -400,10 +399,8 @@ export class WebsocketProvider extends Observable {
400399
}
401400
clearInterval(this._checkInterval)
402401
this.disconnect()
403-
if (typeof window !== 'undefined') {
404-
window.removeEventListener('unload', this._unloadHandler)
405-
} else if (typeof process !== 'undefined') {
406-
process.off('exit', this._unloadHandler)
402+
if (typeof process !== 'undefined') {
403+
process.off('exit', this._exitHandler)
407404
}
408405
this.awareness.off('update', this._awarenessUpdateHandler)
409406
this.doc.off('update', this._updateHandler)

0 commit comments

Comments
 (0)