diff --git a/package-lock.json b/package-lock.json index c9a8990..2194e59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1552,9 +1552,9 @@ }, "dependencies": { "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true } } diff --git a/package.json b/package.json index 4066a1f..482fb0f 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "start": "node ./bin/server.js", "dist": "rm -rf dist && rollup -c && tsc", "lint": "standard && tsc", + "test": "npm run lint", "preversion": "npm run lint && npm run dist" }, "bin": { @@ -40,18 +41,18 @@ ] }, "dependencies": { - "lib0": "^0.2.15", - "y-protocols": "^0.2.0" + "lib0": "^0.2.22", + "y-protocols": "^0.2.3" }, "devDependencies": { "rollup": "^1.31.1", "rollup-cli": "^1.0.9", "standard": "^12.0.1", "typescript": "^3.7.5", - "yjs": "13.0.4" + "yjs": "13.0.5" }, "peerDependenies": { - "yjs": "^13.0.4" + "yjs": "^13.0.0" }, "optionalDependencies": { "ws": "^6.2.1" diff --git a/src/y-websocket.js b/src/y-websocket.js index 9bb95f2..1831cc9 100644 --- a/src/y-websocket.js +++ b/src/y-websocket.js @@ -48,13 +48,14 @@ const readMessage = (provider, buf, emitSynced) => { const encoder = encoding.createEncoder() const messageType = decoding.readVarUint(decoder) switch (messageType) { - case messageSync: + case messageSync: { encoding.writeVarUint(encoder, messageSync) const syncMessageType = syncProtocol.readSyncMessage(decoder, encoder, provider.doc, provider) if (emitSynced && syncMessageType === syncProtocol.messageYjsSyncStep2 && !provider.synced) { provider.synced = true } break + } case messageQueryAwareness: encoding.writeVarUint(encoder, messageAwareness) encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(provider.awareness, Array.from(provider.awareness.getStates().keys()))) @@ -257,18 +258,21 @@ export class WebsocketProvider extends Observable { this.connect() } } + /** * @type {boolean} */ get synced () { return this._synced } + set synced (state) { if (this._synced !== state) { this._synced = state this.emit('sync', [state]) } } + destroy () { clearInterval(this._checkInterval) this.disconnect() @@ -276,6 +280,7 @@ export class WebsocketProvider extends Observable { this.doc.off('update', this._updateHandler) super.destroy() } + connectBc () { if (!this.bcconnected) { bc.subscribe(this.bcChannel, this._bcSubscriber) @@ -304,6 +309,7 @@ export class WebsocketProvider extends Observable { bc.publish(this.bcChannel, encoding.toUint8Array(encoderAwarenessState)) }) } + disconnectBc () { // broadcast message with local awareness state set to null (indicating disconnect) const encoder = encoding.createEncoder() @@ -315,6 +321,7 @@ export class WebsocketProvider extends Observable { this.bcconnected = false } } + disconnect () { this.shouldConnect = false this.disconnectBc() @@ -322,6 +329,7 @@ export class WebsocketProvider extends Observable { this.ws.close() } } + connect () { this.shouldConnect = true if (!this.wsconnected && this.ws === null) { diff --git a/tsconfig.json b/tsconfig.json index 235a1cd..f263390 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -39,16 +39,12 @@ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ "paths": { - "yjs": ["node_modules/yjs/src/index.js"], - "lib0/*": ["node_modules/lib0/*"], - "lib0/dist/*": ["node_modules/lib0/dist/*"], - "y-protocols/*": ["node_modules/y-protocols/*"] }, // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ @@ -60,7 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - "maxNodeModuleJsDepth": 5 + // "maxNodeModuleJsDepth": 5 }, "include": ["./src/y-websocket.js"] }