Merge branch 'master' into master
This commit is contained in:
commit
af5906907d
@ -85,7 +85,7 @@ wsOpts = {
|
||||
<b><code>wsProvider.bcconnected: boolean</code></b>
|
||||
<dd>True if this instance is currently communicating to other browser-windows via BroadcastChannel.</dd>
|
||||
<b><code>wsProvider.synced: boolean</code></b>
|
||||
<dd>True if this instance is currently connected and synced with the server./dd>
|
||||
<dd>True if this instance is currently connected and synced with the server.</dd>
|
||||
<b><code>wsProvider.disconnect()</code></b>
|
||||
<dd>Disconnect from the server and don't try to reconnect.</dd>
|
||||
<b><code>wsProvider.connect()</code></b>
|
||||
|
||||
2125
package-lock.json
generated
Normal file
2125
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "y-websocket",
|
||||
"version": "1.3.11",
|
||||
"version": "1.3.15",
|
||||
"description": "Websockets provider for Yjs",
|
||||
"main": "./dist/y-websocket.cjs",
|
||||
"module": "./src/y-websocket.js",
|
||||
@ -25,6 +25,13 @@
|
||||
"bin/*",
|
||||
"src/*"
|
||||
],
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": "./src/y-websocket.js",
|
||||
"require": "./dist/y-websocket.cjs"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/yjs/y-websocket.git"
|
||||
@ -45,9 +52,9 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"lib0": "^0.2.35",
|
||||
"lib0": "^0.2.42",
|
||||
"lodash.debounce": "^4.0.8",
|
||||
"y-protocols": "^1.0.4"
|
||||
"y-protocols": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rollup": "^1.32.1",
|
||||
@ -56,8 +63,8 @@
|
||||
"typescript": "^3.9.9",
|
||||
"yjs": "^13.5.0"
|
||||
},
|
||||
"peerDependenies": {
|
||||
"yjs": "^13.5.0"
|
||||
"peerDependencies": {
|
||||
"yjs": "^13.5.6"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"ws": "^6.2.1",
|
||||
|
||||
@ -8,9 +8,9 @@ export default {
|
||||
sourcemap: true,
|
||||
paths: path => {
|
||||
if (/^lib0\//.test(path)) {
|
||||
return `lib0/dist${path.slice(4, -3)}.cjs`
|
||||
return `lib0/dist${path.slice(4)}.cjs`
|
||||
} else if (/^y-protocols\//.test(path)) {
|
||||
return `y-protocols/dist${path.slice(11, -3)}.cjs`
|
||||
return `y-protocols/dist${path.slice(11)}.cjs`
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
@ -9,17 +9,17 @@ Unlike stated in the LICENSE file, it is not necessary to include the copyright
|
||||
/* eslint-env browser */
|
||||
|
||||
import * as Y from 'yjs' // eslint-disable-line
|
||||
import * as bc from 'lib0/broadcastchannel.js'
|
||||
import * as time from 'lib0/time.js'
|
||||
import * as encoding from 'lib0/encoding.js'
|
||||
import * as decoding from 'lib0/decoding.js'
|
||||
import * as syncProtocol from 'y-protocols/sync.js'
|
||||
import * as authProtocol from 'y-protocols/auth.js'
|
||||
import * as awarenessProtocol from 'y-protocols/awareness.js'
|
||||
import * as mutex from 'lib0/mutex.js'
|
||||
import { Observable } from 'lib0/observable.js'
|
||||
import * as math from 'lib0/math.js'
|
||||
import * as url from 'lib0/url.js'
|
||||
import * as bc from 'lib0/broadcastchannel'
|
||||
import * as time from 'lib0/time'
|
||||
import * as encoding from 'lib0/encoding'
|
||||
import * as decoding from 'lib0/decoding'
|
||||
import * as syncProtocol from 'y-protocols/sync'
|
||||
import * as authProtocol from 'y-protocols/auth'
|
||||
import * as awarenessProtocol from 'y-protocols/awareness'
|
||||
import * as mutex from 'lib0/mutex'
|
||||
import { Observable } from 'lib0/observable'
|
||||
import * as math from 'lib0/math'
|
||||
import * as url from 'lib0/url'
|
||||
|
||||
const messageSync = 0
|
||||
const messageQueryAwareness = 3
|
||||
@ -276,18 +276,14 @@ export class WebsocketProvider extends Observable {
|
||||
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, changedClients))
|
||||
broadcastMessage(this, encoding.toUint8Array(encoder))
|
||||
}
|
||||
|
||||
this._beforeUnloadHandler = () => {
|
||||
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
|
||||
}
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('beforeunload', () => {
|
||||
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload');
|
||||
});
|
||||
window.addEventListener('beforeunload', this._beforeUnloadHandler)
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.on('exit', () => this._beforeUnloadHandler)
|
||||
}
|
||||
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) {
|
||||
@ -322,6 +318,11 @@ export class WebsocketProvider extends Observable {
|
||||
}
|
||||
clearInterval(this._checkInterval)
|
||||
this.disconnect()
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('beforeunload', this._beforeUnloadHandler)
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.off('exit', () => this._beforeUnloadHandler)
|
||||
}
|
||||
this.awareness.off('update', this._awarenessUpdateHandler)
|
||||
this.doc.off('update', this._updateHandler)
|
||||
super.destroy()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user