y-websocket
Advanced tools
Comparing version 0.0.0 to 1.0.0-0
@@ -42,9 +42,9 @@ 'use strict'; | ||
encoding.writeVarUint(encoder, messageSync); | ||
syncProtocol.readSyncMessage(decoder, encoder, doc, doc.ws); | ||
break | ||
case messageAwareness: | ||
doc.mux(() => | ||
syncProtocol.readSyncMessage(decoder, encoder, doc) | ||
awarenessProtocol.readAwarenessMessage(decoder, doc) | ||
); | ||
break | ||
case messageAwareness: | ||
awarenessProtocol.readAwarenessMessage(decoder, doc); | ||
break | ||
case messageAuth: | ||
@@ -88,3 +88,5 @@ authProtocol.readAuthMessage(decoder, doc, permissionDeniedHandler); | ||
}]); | ||
setTimeout(setupWS, reconnectTimeout, doc, url); | ||
if (doc.shouldReconnect) { | ||
setTimeout(setupWS, reconnectTimeout, doc, url); | ||
} | ||
}; | ||
@@ -111,17 +113,15 @@ websocket.onopen = () => { | ||
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); | ||
} | ||
} | ||
@@ -150,4 +150,3 @@ }; | ||
this.ws = null; | ||
setupWS(this, url); | ||
this.on('afterTransaction', broadcastUpdate); | ||
this.shouldReconnect = true; | ||
/** | ||
@@ -164,11 +163,27 @@ * @param {ArrayBuffer} data | ||
}; | ||
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 () { | ||
@@ -175,0 +190,0 @@ return this._localAwarenessState |
{ | ||
"name": "y-websocket", | ||
"version": "0.0.0", | ||
"version": "1.0.0-0", | ||
"description": "Websockets provider for Yjs", | ||
@@ -20,3 +20,4 @@ "main": "./dist/y-websocket.js", | ||
"files": [ | ||
"dist/*" | ||
"dist/*", | ||
"bin/*" | ||
], | ||
@@ -23,0 +24,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27470
4
423
4
1