Installations
npm install y-protocols
Developer
yjs
Developer Guide
Module System
ESM
Min. Node Version
>=16.0.0
Typescript Support
No
Node Version
20.5.1
NPM Version
9.8.0
Statistics
118 Stars
82 Commits
41 Forks
7 Watching
1 Branches
11 Contributors
Updated on 17 Nov 2024
Languages
JavaScript (99.24%)
HTML (0.76%)
Total Downloads
Cumulative downloads
Total Downloads
27,568,072
Last day
4.8%
69,276
Compared to previous day
Last week
0.4%
345,752
Compared to previous week
Last month
10.3%
1,523,736
Compared to previous month
Last year
108.6%
14,529,458
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
Yjs Protocols
Binary encoding protocols for syncing, awareness, and history information
This API is unstable and subject to change.
API
Awareness Protocol
1import * as awarenessProtocol from 'y-protocols/awareness.js'
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
1const ydoc = new Y.Doc()
2const awareness = new awarenessProtocol.Awareness(ydoc)
- A unique identifier that identifies this client.
- Get the local awareness state.
- Set/Update the local awareness state. Set `null` to mark the local client as offline.
- Only update a single field on the local awareness object. Does not do anything if the local state is not set.
- Get all client awareness states (remote and local). Maps from clientID to awareness state.
- Listen to remote and local state changes on the awareness instance.
- Listen to remote and local awareness changes on the awareness instance. This event is called even when the awarenes state does not change.
clientID:number
getLocalState():Object<string,any>|null
setLocalState(Object<string,any>|null)
setLocalStateField(string, any)
getStates():Map<number,Object<string,any>>
on('change', ({ added: Array<number>, updated: Array<number>
removed: Array<number> }, [transactionOrigin:any]) => ..)
on('update', ({ added: Array<number>, updated: Array<number>
removed: Array<number> }, [transactionOrigin:any]) => ..)
License
The MIT License © Kevin Jahns
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
Found 7/22 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More