y-protocols
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -10,3 +10,3 @@ /** | ||
import { Observable } from 'lib0/observable.js' | ||
import * as Y from 'yjs' | ||
import * as Y from 'yjs' // eslint-disable-line | ||
@@ -57,3 +57,3 @@ const outdatedTimeout = 30000 | ||
const now = time.getUnixTime() | ||
if (this.getLocalState() !== null && outdatedTimeout / 2 <= now - /** @type {{lastUpdated:number}} */ (this.meta.get(doc.clientID)).lastUpdated) { | ||
if (this.getLocalState() !== null && (outdatedTimeout / 2 <= now - /** @type {{lastUpdated:number}} */ (this.meta.get(doc.clientID)).lastUpdated)) { | ||
// renew local clock | ||
@@ -67,3 +67,3 @@ this.setLocalState(this.getLocalState()) | ||
this.meta.forEach((meta, clientid) => { | ||
if (outdatedTimeout <= now - meta.lastUpdated) { | ||
if (outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
remove.push(clientid) | ||
@@ -79,2 +79,3 @@ } | ||
}) | ||
this.setLocalState({}) | ||
} | ||
@@ -153,5 +154,6 @@ destroy () { | ||
const curMeta = /** @type {MetaClientState} */ (awareness.meta.get(clientID)) | ||
curMeta.clock++ | ||
curMeta.lastUpdated = time.getUnixTime() | ||
awareness.meta.set(clientID, curMeta) | ||
awareness.meta.set(clientID, { | ||
clock: curMeta.clock + 1, | ||
lastUpdated: time.getUnixTime() | ||
}) | ||
} | ||
@@ -171,3 +173,3 @@ removed.push(clientID) | ||
*/ | ||
export const encodeAwarenessUpdate = (awareness, clients) => { | ||
export const encodeAwarenessUpdate = (awareness, clients, states = awareness.states) => { | ||
const len = clients.length | ||
@@ -178,3 +180,3 @@ const encoder = encoding.createEncoder() | ||
const clientID = clients[i] | ||
const state = awareness.states.get(clientID) || null | ||
const state = states.get(clientID) || null | ||
const clock = /** @type {MetaClientState} */ (awareness.meta.get(clientID)).clock | ||
@@ -202,9 +204,16 @@ encoding.writeVarUint(encoder, clientID) | ||
const clientID = decoding.readVarUint(decoder) | ||
const clock = decoding.readVarUint(decoder) | ||
let clock = decoding.readVarUint(decoder) | ||
const state = JSON.parse(decoding.readVarString(decoder)) | ||
const clientMeta = awareness.meta.get(clientID) | ||
const uClock = clientMeta === undefined ? 0 : clientMeta.clock | ||
if (uClock < clock || (uClock === clock && state === null && awareness.states.has(clientID))) { | ||
const currClock = clientMeta === undefined ? 0 : clientMeta.clock | ||
if (currClock < clock || (currClock === clock && state === null && awareness.states.has(clientID))) { | ||
if (state === null) { | ||
awareness.states.delete(clientID) | ||
// never let a remote client remove this local state | ||
if (clientID === awareness.doc.clientID && awareness.getLocalState() != null) { | ||
// remote client removed the local state. Do not remote state. Broadcast a message indicating | ||
// that this client still exists by increasing the clock | ||
clock++ | ||
} else { | ||
awareness.states.delete(clientID) | ||
} | ||
} else { | ||
@@ -211,0 +220,0 @@ awareness.states.set(clientID, state) |
@@ -38,3 +38,3 @@ 'use strict'; | ||
exports.messagePermissionDenied = messagePermissionDenied; | ||
exports.writePermissionDenied = writePermissionDenied; | ||
exports.readAuthMessage = readAuthMessage; | ||
exports.writePermissionDenied = writePermissionDenied; |
@@ -60,3 +60,3 @@ 'use strict'; | ||
const now = time.getUnixTime(); | ||
if (this.getLocalState() !== null && outdatedTimeout / 2 <= now - /** @type {{lastUpdated:number}} */ (this.meta.get(doc.clientID)).lastUpdated) { | ||
if (this.getLocalState() !== null && (outdatedTimeout / 2 <= now - /** @type {{lastUpdated:number}} */ (this.meta.get(doc.clientID)).lastUpdated)) { | ||
// renew local clock | ||
@@ -70,3 +70,3 @@ this.setLocalState(this.getLocalState()); | ||
this.meta.forEach((meta, clientid) => { | ||
if (outdatedTimeout <= now - meta.lastUpdated) { | ||
if (outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
remove.push(clientid); | ||
@@ -82,2 +82,3 @@ } | ||
}); | ||
this.setLocalState({}); | ||
} | ||
@@ -156,5 +157,6 @@ destroy () { | ||
const curMeta = /** @type {MetaClientState} */ (awareness.meta.get(clientID)); | ||
curMeta.clock++; | ||
curMeta.lastUpdated = time.getUnixTime(); | ||
awareness.meta.set(clientID, curMeta); | ||
awareness.meta.set(clientID, { | ||
clock: curMeta.clock + 1, | ||
lastUpdated: time.getUnixTime() | ||
}); | ||
} | ||
@@ -174,3 +176,3 @@ removed.push(clientID); | ||
*/ | ||
const encodeAwarenessUpdate = (awareness, clients) => { | ||
const encodeAwarenessUpdate = (awareness, clients, states = awareness.states) => { | ||
const len = clients.length; | ||
@@ -181,3 +183,3 @@ const encoder = encoding.createEncoder(); | ||
const clientID = clients[i]; | ||
const state = awareness.states.get(clientID) || null; | ||
const state = states.get(clientID) || null; | ||
const clock = /** @type {MetaClientState} */ (awareness.meta.get(clientID)).clock; | ||
@@ -205,9 +207,16 @@ encoding.writeVarUint(encoder, clientID); | ||
const clientID = decoding.readVarUint(decoder); | ||
const clock = decoding.readVarUint(decoder); | ||
let clock = decoding.readVarUint(decoder); | ||
const state = JSON.parse(decoding.readVarString(decoder)); | ||
const clientMeta = awareness.meta.get(clientID); | ||
const uClock = clientMeta === undefined ? 0 : clientMeta.clock; | ||
if (uClock < clock || (uClock === clock && state === null && awareness.states.has(clientID))) { | ||
const currClock = clientMeta === undefined ? 0 : clientMeta.clock; | ||
if (currClock < clock || (currClock === clock && state === null && awareness.states.has(clientID))) { | ||
if (state === null) { | ||
awareness.states.delete(clientID); | ||
// never let a remote client remove this local state | ||
if (clientID === awareness.doc.clientID && awareness.getLocalState() != null) { | ||
// remote client removed the local state. Do not remote state. Broadcast a message indicating | ||
// that this client still exists by increasing the clock | ||
clock++; | ||
} else { | ||
awareness.states.delete(clientID); | ||
} | ||
} else { | ||
@@ -237,4 +246,4 @@ awareness.states.set(clientID, state); | ||
exports.Awareness = Awareness; | ||
exports.removeAwarenessStates = removeAwarenessStates; | ||
exports.encodeAwarenessUpdate = encodeAwarenessUpdate; | ||
exports.applyAwarenessUpdate = applyAwarenessUpdate; | ||
exports.encodeAwarenessUpdate = encodeAwarenessUpdate; | ||
exports.removeAwarenessStates = removeAwarenessStates; |
@@ -49,3 +49,3 @@ 'use strict'; | ||
exports.writeHistorySnapshot = writeHistorySnapshot; | ||
exports.readHistorySnapshot = readHistorySnapshot; | ||
exports.writeHistorySnapshot = writeHistorySnapshot; |
@@ -61,3 +61,3 @@ 'use strict'; | ||
* @param {Y.Doc} doc | ||
* @param {Uint8Array} encodedStateVector | ||
* @param {Uint8Array|undefined} encodedStateVector | ||
*/ | ||
@@ -135,8 +135,8 @@ const writeSyncStep2 = (encoder, doc, encodedStateVector) => { | ||
exports.messageYjsUpdate = messageYjsUpdate; | ||
exports.readSyncMessage = readSyncMessage; | ||
exports.writeSyncStep1 = writeSyncStep1; | ||
exports.writeSyncStep2 = writeSyncStep2; | ||
exports.readSyncStep1 = readSyncStep1; | ||
exports.readSyncStep2 = readSyncStep2; | ||
exports.writeUpdate = writeUpdate; | ||
exports.readUpdate = readUpdate; | ||
exports.writeSyncStep1 = writeSyncStep1; | ||
exports.writeSyncStep2 = writeSyncStep2; | ||
exports.writeUpdate = writeUpdate; | ||
exports.readSyncMessage = readSyncMessage; |
{ | ||
"name": "y-protocols", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Yjs encoding protocols", | ||
@@ -28,2 +28,8 @@ "files": [ | ||
"license": "MIT", | ||
"standard": { | ||
"ignore": [ | ||
"/dist", | ||
"/node_modules" | ||
] | ||
}, | ||
"bugs": { | ||
@@ -37,3 +43,3 @@ "url": "https://github.com/y-js/y-protocols/issues" | ||
"devDependencies": { | ||
"yjs": "13.0.0-83", | ||
"yjs": "13.0.0-94", | ||
"rollup": "^1.1.2", | ||
@@ -40,0 +46,0 @@ "rollup-cli": "^1.0.9", |
@@ -8,3 +8,3 @@ # Yjs Protocols | ||
### Awareness Protocoll | ||
### Awareness Protocol | ||
@@ -11,0 +11,0 @@ ```js |
@@ -57,3 +57,3 @@ /** | ||
* @param {Y.Doc} doc | ||
* @param {Uint8Array} encodedStateVector | ||
* @param {Uint8Array|undefined} encodedStateVector | ||
*/ | ||
@@ -60,0 +60,0 @@ export const writeSyncStep2 = (encoder, doc, encodedStateVector) => { |
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
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
33150
839