y-protocols
Advanced tools
Comparing version 0.0.7 to 0.1.0
@@ -12,3 +12,3 @@ /** | ||
const outdatedTimeout = 30000 | ||
export const outdatedTimeout = 30000 | ||
@@ -66,3 +66,3 @@ /** | ||
this.meta.forEach((meta, clientid) => { | ||
if (outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
if (clientid !== doc.clientID && outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
remove.push(clientid) | ||
@@ -69,0 +69,0 @@ } |
@@ -69,3 +69,3 @@ 'use strict'; | ||
this.meta.forEach((meta, clientid) => { | ||
if (outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
if (clientid !== doc.clientID && outdatedTimeout <= now - meta.lastUpdated && this.states.has(clientid)) { | ||
remove.push(clientid); | ||
@@ -239,2 +239,3 @@ } | ||
exports.outdatedTimeout = outdatedTimeout; | ||
exports.Awareness = Awareness; | ||
@@ -241,0 +242,0 @@ exports.removeAwarenessStates = removeAwarenessStates; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
* @property {Y.DeleteStore} HistorySnapshot.ds | ||
* @property {Map<number,number>} HistorySnapshot.sm | ||
* @property {Map<number,number>} HistorySnapshot.sv | ||
* @property {Map<number,string>} HistorySnapshot.userMap | ||
@@ -15,0 +15,0 @@ */ |
@@ -9,3 +9,3 @@ | ||
* @property {Y.DeleteStore} HistorySnapshot.ds | ||
* @property {Map<number,number>} HistorySnapshot.sm | ||
* @property {Map<number,number>} HistorySnapshot.sv | ||
* @property {Map<number,string>} HistorySnapshot.userMap | ||
@@ -12,0 +12,0 @@ */ |
{ | ||
"name": "y-protocols", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"description": "Yjs encoding protocols", | ||
@@ -21,3 +21,3 @@ "files": [ | ||
"type": "git", | ||
"url": "git+https://github.com/y-js/y-protocols.git" | ||
"url": "git+https://github.com/yjs/y-protocols.git" | ||
}, | ||
@@ -36,7 +36,7 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/y-js/y-protocols/issues" | ||
"url": "https://github.com/yjs/y-protocols/issues" | ||
}, | ||
"homepage": "https://github.com/y-js/y-protocols#readme", | ||
"homepage": "https://github.com/yjs/y-protocols#readme", | ||
"dependencies": { | ||
"lib0": "0.0.5" | ||
"lib0": "^0.1.0" | ||
}, | ||
@@ -50,4 +50,4 @@ "devDependencies": { | ||
"peerDependenies": { | ||
"yjs": "*" | ||
"yjs": ">13.0.0-97" | ||
} | ||
} |
@@ -14,6 +14,22 @@ # Yjs Protocols | ||
The Awareness protocol implements a simple network agnostic algorithm that | ||
manages user status (who is online?) and propagate awareness information like | ||
cursor location, username, or email address. Each client can update its own | ||
local state and listen to state changes of remote clients. | ||
Each client has an awareness state. Remote awareness are stored in a Map that | ||
maps from remote client id to remote awareness state. An *awareness state* is an | ||
increasing clock attached to a schemaless json object. | ||
Whenever the client changes its local state, it increases the clock and | ||
propagates its own awareness state to all peers. When a client receives a remote | ||
awareness state, and overwrites the clients state if the received state is newer | ||
than the local awareness state for that client. If the state is `null`, the | ||
client is marked as offline. If a client doesn't receive updates from a remote | ||
peer for 30 seconds, it marks the remote client as offline. Hence each client | ||
must broadcast its own awareness state in a regular interval to make sure that | ||
remote clients don't mark it as offline. | ||
#### awarenessProtocol.Awareness Class | ||
The Awareness class implements a simple network agnostic protocol to propagate awareness information like cursor, username, or status. Each client can update its own local state and listen to state changes of remote clients. | ||
```js | ||
@@ -27,15 +43,27 @@ const awareness = new awarenessProtocol.Awareness() | ||
<b><code>setLocalState(Object<string,any>|null)</code></b> | ||
<dd>Set/Update the local awareness state. Set `null` to mark the local client as offline.</dd> | ||
<dd> | ||
Set/Update the local awareness state. Set `null` to mark the local client as | ||
offline. | ||
</dd> | ||
<b><code>setLocalStateField(string, any)</code></b> | ||
<dd>Only update a single field on the local awareness object. Does not do anything if the local state is not set.</dd> | ||
<dd> | ||
Only update a single field on the local awareness object. Does not do | ||
anything if the local state is not set. | ||
</dd> | ||
<b><code>getStates():Map<number,Object<string,any>></code></b> | ||
<dd>Get all client awareness states (remote and local). Maps from clientID to awareness state.</dd> | ||
<b><code>on('change', ({ added: Array<number>, updated: Array<number> removed: Array<number> }, [transactionOrigin:any]) => ..)</code></b> | ||
<dd>Listen to remote and local changes on the awareness instance.</dd> | ||
<dd> | ||
Get all client awareness states (remote and local). Maps from clientID to | ||
awareness state. | ||
</dd> | ||
<b><code> | ||
on('change', ({ added: Array<number>, updated: Array<number> | ||
removed: Array<number> }, [transactionOrigin:any]) => ..) | ||
</code></b> | ||
<dd> | ||
Listen to remote and local changes on the awareness instance. | ||
</dd> | ||
</dl> | ||
### License | ||
[The MIT License](./LICENSE) © Kevin Jahns | ||
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
34150
840
68
+ Addedlib0@0.1.7(transitive)
- Removedlib0@0.0.5(transitive)
Updatedlib0@^0.1.0