release for Yjs@13.0.0-80
This commit is contained in:
parent
01519447ca
commit
cb50b2fbcf
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
dist
|
||||
node_modules
|
||||
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "websocket server",
|
||||
"program": "${workspaceFolder}/bin/server.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
13133
package-lock.json
generated
13133
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -2,7 +2,9 @@
|
||||
"name": "y-websocket",
|
||||
"version": "0.0.0",
|
||||
"description": "Websockets provider for Yjs",
|
||||
"main": "",
|
||||
"main": "./dist/y-websocket.js",
|
||||
"module": "./src/y-websocket.js",
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"start": "node ./bin/server.js",
|
||||
"dist": "rm -rf dist/* && rollup -c",
|
||||
@ -14,6 +16,9 @@
|
||||
"bin": {
|
||||
"y-websocket-server": "./bin/server.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/*"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/y-js/y-websocket.git"
|
||||
@ -27,22 +32,19 @@
|
||||
"url": "https://github.com/y-js/y-websocket/issues"
|
||||
},
|
||||
"homepage": "https://github.com/y-js/y-websocket#readme",
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"y-protocols": "0.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rollup": "^1.1.2",
|
||||
"rollup-cli": "^1.0.9",
|
||||
"standard": "^12.0.1",
|
||||
"lib0": "file:/../lib0",
|
||||
"y-leveldb": "file:../y-leveldb",
|
||||
"y-protocols": "file:../y-protocols",
|
||||
"yjs": "file:../yjs"
|
||||
"standard": "^12.0.1"
|
||||
},
|
||||
"peerDependenies": {
|
||||
"lib0": "^0.0.1",
|
||||
"yjs": "*"
|
||||
"lib0": "*",
|
||||
"yjs": "13.0.0-80"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"ws": "^6.2.1",
|
||||
"y-leveldb": "*"
|
||||
"ws": "^6.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,12 +41,12 @@ const readMessage = (doc, buf) => {
|
||||
switch (messageType) {
|
||||
case messageSync:
|
||||
encoding.writeVarUint(encoder, messageSync)
|
||||
doc.mux(() =>
|
||||
syncProtocol.readSyncMessage(decoder, encoder, doc)
|
||||
)
|
||||
syncProtocol.readSyncMessage(decoder, encoder, doc, doc.ws)
|
||||
break
|
||||
case messageAwareness:
|
||||
awarenessProtocol.readAwarenessMessage(decoder, doc)
|
||||
doc.mux(() =>
|
||||
awarenessProtocol.readAwarenessMessage(decoder, doc)
|
||||
)
|
||||
break
|
||||
case messageAuth:
|
||||
authProtocol.readAuthMessage(decoder, doc, permissionDeniedHandler)
|
||||
@ -86,7 +86,9 @@ const setupWS = (doc, url) => {
|
||||
doc.emit('status', [{
|
||||
status: 'disconnected'
|
||||
}])
|
||||
setTimeout(setupWS, reconnectTimeout, doc, url)
|
||||
if (doc.shouldReconnect) {
|
||||
setTimeout(setupWS, reconnectTimeout, doc, url)
|
||||
}
|
||||
}
|
||||
websocket.onopen = () => {
|
||||
doc.wsconnected = true
|
||||
@ -108,21 +110,19 @@ const setupWS = (doc, url) => {
|
||||
* @param {WebsocketsSharedDocument} y
|
||||
*/
|
||||
const broadcastUpdate = (transaction, y) => {
|
||||
if (transaction.updateMessage !== null) {
|
||||
y.mux(() => {
|
||||
const updateMessage = transaction.updateMessage
|
||||
if (updateMessage !== null) {
|
||||
const encoder = encoding.createEncoder()
|
||||
encoding.writeVarUint(encoder, messageSync)
|
||||
syncProtocol.writeUpdate(encoder, updateMessage)
|
||||
const buf = encoding.toBuffer(encoder)
|
||||
if (y.wsconnected) {
|
||||
// @ts-ignore We know that wsconnected = true
|
||||
y.ws.send(buf)
|
||||
}
|
||||
bc.publish(y.url, buf)
|
||||
if (transaction.origin !== y.ws && transaction.updateMessage !== null) {
|
||||
const updateMessage = transaction.updateMessage
|
||||
if (updateMessage !== null) {
|
||||
const encoder = encoding.createEncoder()
|
||||
encoding.writeVarUint(encoder, messageSync)
|
||||
syncProtocol.writeUpdate(encoder, updateMessage)
|
||||
const buf = encoding.toBuffer(encoder)
|
||||
if (y.wsconnected) {
|
||||
// @ts-ignore We know that wsconnected = true
|
||||
y.ws.send(buf)
|
||||
}
|
||||
})
|
||||
bc.publish(y.url, buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,8 +146,7 @@ class WebsocketsSharedDocument extends Y.Y {
|
||||
* @type {WebSocket?}
|
||||
*/
|
||||
this.ws = null
|
||||
setupWS(this, url)
|
||||
this.on('afterTransaction', broadcastUpdate)
|
||||
this.shouldReconnect = true
|
||||
/**
|
||||
* @param {ArrayBuffer} data
|
||||
*/
|
||||
@ -159,14 +158,30 @@ class WebsocketsSharedDocument extends Y.Y {
|
||||
}
|
||||
})
|
||||
}
|
||||
bc.subscribe(url, this._bcSubscriber)
|
||||
// send sync step1 to bc
|
||||
this.mux(() => {
|
||||
const encoder = encoding.createEncoder()
|
||||
encoding.writeVarUint(encoder, messageSync)
|
||||
syncProtocol.writeSyncStep1(encoder, this.store)
|
||||
bc.publish(url, encoding.toBuffer(encoder))
|
||||
})
|
||||
this.connect()
|
||||
}
|
||||
disconnect () {
|
||||
this.shouldReconnect = false
|
||||
if (this.ws !== null) {
|
||||
this.ws.close()
|
||||
bc.unsubscribe(this.url, this._bcSubscriber)
|
||||
this.off('afterTransaction', broadcastUpdate)
|
||||
}
|
||||
}
|
||||
connect () {
|
||||
this.shouldReconnect = true
|
||||
if (!this.wsconnected && this.ws === null) {
|
||||
setupWS(this, this.url)
|
||||
bc.subscribe(this.url, this._bcSubscriber)
|
||||
// send sync step1 to bc
|
||||
this.mux(() => {
|
||||
const encoder = encoding.createEncoder()
|
||||
encoding.writeVarUint(encoder, messageSync)
|
||||
syncProtocol.writeSyncStep1(encoder, this.store)
|
||||
bc.publish(this.url, encoding.toBuffer(encoder))
|
||||
})
|
||||
this.on('afterTransaction', broadcastUpdate)
|
||||
}
|
||||
}
|
||||
getLocalAwarenessInfo () {
|
||||
return this._localAwarenessState
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user