Reference · 56 exports · mocanvas 4.11.2

@mocanvas/sync

Multiplayer: record diffs over a transport, plus presence.

Read out of the type declarations inside the published package, so a name here is a name in the version above — and its description is the one written next to the code.

56 of 56

Holds the presence records of everyone else: puts them in the store as they arrive, drops them on `bye`, and sweeps clients that went quiet.

A total order on stamps: Lamport first, then client id.

Same-origin tabs of one browser.

createCrdt

function

A room every joined transport broadcasts into (itself excluded).

Two transports wired to each other, going through the same JSON encode and decode as the real ones.

Watches the editor and pushes the local presence record out, at most once per throttle window, plus a heartbeat so that idle collaborators do not time out.

Joins one room over `transport` and keeps `store` in step with its peers.

A WebSocket to a relay (see `scripts/relay.mjs`).

Parse a message off the wire.

Equal apart from `lastActivityTimestamp`, which always moves.

The id a client's presence record always uses, so updates overwrite in place.

Turn a peer's snapshot into a message the ordinary merge can eat: its records supply the values, its state supplies the stamps.

useSync

function

Connect an editor's store to a room for as long as the component is mounted.

ByeMessage

interface

Crdt

interface

CrdtOptions

interface

What one record's registers look like once serialized.

CrdtState

interface

The whole replica's stamps, as carried by a `snapshot` message.

DiffMessage

interface

HelloMessage

interface

LamportClock

interface

MemoryHub

interface

The part of the editor presence reads.

PresenceSync

interface

Stamp

interface

A point in the partial order of writes, made total by the client tiebreak.

StampedDiff

interface

What a `diff` message carries: puts and removes, each field stamped.

StampedPut

interface

One record's changed fields.

StampedRemove

interface

SyncClient

interface

Transport

interface

A duplex channel that carries `SyncMessage`s between peers in one room.

Never sent: `decodeMessage` returns this instead of guessing at a message whose `version` is not ours, so a peer on another protocol is reported once rather than half-parsed.

UseSyncResult

interface

Every message is one JSON object with a `type` discriminator and a `version`, which `encodeMessage` stamps on and `decodeMessage` checks.

Other people's cursors and selections, drawn in screen space above the canvas.

Version of the `CrdtState` blob on the wire.

A presence record is re-sent this often even when nothing changed.

Presence is sent at most this often (30 Hz).

A collaborator we have not heard from in this long is dropped.

How many collected-and-gone records keep a tombstone before it is dropped.

How long a tombstone for a vanished record is kept.

Bumped when the wire format changes incompatibly.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.