Skip to content
Yjs encoding protocols
Branch: master
Clone or download
Latest commit 32895b9 Jan 13, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Add license May 8, 2019 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
tsconfig.json update lib0 dep and use native esm module Jan 13, 2020

Yjs Protocols

Binary encoding protocols for syncing, awareness, and history inforamtion

This API is unstable and subject to change.


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()
Get the local awareness state.
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.
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.


The MIT License © Kevin Jahns

You can’t perform that action at this time.