calibr / y-protocols

Yjs encoding protocols

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yjs Protocols

Binary encoding protocols for syncing, awareness, and history inforamtion

This API is unstable and subject to change.

API

Awareness Protocoll

import * as awarenessProtocol from 'y-protocols/awareness.js'

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.

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

About

Yjs encoding protocols

License:MIT License


Languages

Language:JavaScript 100.0%