Skip to content
Yjs encoding protocols
JavaScript
Branch: master
Clone or download
Latest commit 32895b9 Jan 13, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.markdownlint.json
LICENSE Add license May 8, 2019
README.md update awareness docs Aug 5, 2019
auth.js update lib0 dep and use native esm module Jan 13, 2020
awareness.js update deps Sep 4, 2019
package-lock.json 0.2.0 Jan 13, 2020
package.json
rollup.config.js
sync.js
tsconfig.json update lib0 dep and use native esm module Jan 13, 2020

README.md

Yjs Protocols

Binary encoding protocols for syncing, awareness, and history inforamtion

This API is unstable and subject to change.

API

Awareness Protocol

import * 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

const awareness = new awarenessProtocol.Awareness()
getLocalState():Object<string,any>|null
Get the local awareness state.
setLocalState(Object<string,any>|null)
Set/Update the local awareness state. Set `null` to mark the local client as offline.
setLocalStateField(string, any)
Only update a single field on the local awareness object. Does not do anything if the local state is not set.
getStates():Map<number,Object<string,any>>
Get all client awareness states (remote and local). Maps from clientID to awareness state.
on('change', ({ added: Array<number>, updated: Array<number> removed: Array<number> }, [transactionOrigin:any]) => ..)
Listen to remote and local changes on the awareness instance.

License

The MIT License © Kevin Jahns

You can’t perform that action at this time.