Socket
Socket
Sign inDemoInstall

y-protocols

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-protocols - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

4

awareness.js

@@ -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&lt;string,any&gt;|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&lt;number,Object&lt;string,any&gt;&gt;</code></b>
<dd>Get all client awareness states (remote and local). Maps from clientID to awareness state.</dd>
<b><code>on('change', ({ added: Array&lt;number&gt;, updated: Array&lt;number&gt; removed: Array&lt;number&gt; }, [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&lt;number&gt;, updated: Array&lt;number&gt;
removed: Array&lt;number&gt; }, [transactionOrigin:any]) => ..)
</code></b>
<dd>
Listen to remote and local changes on the awareness instance.
</dd>
</dl>
### License
[The MIT License](./LICENSE) © Kevin Jahns
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc