Reference · 56 exports · mocanvas 4.11.2
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
class
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.
function
A total order on stamps: Lamport first, then client id.
function
Same-origin tabs of one browser.
function
function
function
function
function
A room every joined transport broadcasts into (itself excluded).
function
Two transports wired to each other, going through the same JSON encode and decode as the real ones.
function
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.
function
Joins one room over `transport` and keeps `store` in step with its peers.
function
A WebSocket to a relay (see `scripts/relay.mjs`).
function
Parse a message off the wire.
function
function
Equal apart from `lastActivityTimestamp`, which always moves.
function
function
The id a client's presence record always uses, so updates overwrite in place.
function
Turn a peer's snapshot into a message the ordinary merge can eat: its records supply the values, its state supplies the stamps.
function
Connect an editor's store to a room for as long as the component is mounted.
interface
interface
interface
interface
interface
interface
What one record's registers look like once serialized.
interface
The whole replica's stamps, as carried by a `snapshot` message.
interface
interface
interface
interface
interface
The part of the editor presence reads.
interface
interface
interface
interface
interface
A point in the partial order of writes, made total by the client tiebreak.
interface
What a `diff` message carries: puts and removes, each field stamped.
interface
One record's changed fields.
interface
interface
interface
interface
A duplex channel that carries `SyncMessage`s between peers in one room.
interface
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.
interface
interface
interface
type
Every message is one JSON object with a `type` discriminator and a `version`, which `encodeMessage` stamps on and `decodeMessage` checks.
type
constant
Other people's cursors and selections, drawn in screen space above the canvas.
constant
Version of the `CrdtState` blob on the wire.
constant
A presence record is re-sent this often even when nothing changed.
constant
Presence is sent at most this often (30 Hz).
constant
A collaborator we have not heard from in this long is dropped.
constant
How many collected-and-gone records keep a tombstone before it is dropped.
constant
How long a tombstone for a vanished record is kept.
constant
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.