API Reference
Complete reference for all exported functions, types, and hooks in Vuer-RTC.
Core Exports
Graph Factory
createGraph
Create a graph store for managing CRDT-based scene graph state.
Parameters:
| Parameter | Type | Description |
|---|---|---|
options.sessionId | string | Unique session identifier |
options.onSend | (msg: CRDTMessage) => void | Callback invoked when a message is ready to send to the server |
options.onStateChange | (state: ClientState) => void | Optional callback invoked on every state change |
options.initialSnapshot | Snapshot | Optional initial snapshot to restore from |
Returns: GraphStore - A store with methods to edit, commit, undo/redo, and sync state.
Example:
createGraphFromServer
Create a graph store initialized from server state (snapshot + journal).
Parameters:
| Parameter | Type | Description |
|---|---|---|
sessionId | string | Unique session identifier |
snapshot | Snapshot | Server snapshot containing graph state and metadata |
journal | CRDTMessage[] | Array of uncompacted messages from server |
onSend | (msg: CRDTMessage) => void | Optional callback for outgoing messages |
Returns: GraphStore
Client Actions
Low-level state manipulation functions. Most users should use createGraph or React hooks instead.
State Initialization
createInitialState
Create initial client state.
initFromServer
Initialize client state from server snapshot and journal.
Edit Buffer Operations
onEdit
Add an operation to the edit buffer (uncommitted).
commitEdits
Commit pending edits as a single message.
Returns: New state and the message to send (or null if no edits).
cancelEdits
Discard all uncommitted edits.
Server Communication
onRemoteMessage
Process an incoming message from another client or server.
onServerAck
Mark a message as acknowledged by the server.
Undo/Redo
undo
Undo the last committed message.
Returns null when the remaining local edits are already covered by a durable server watermark. Such entries may remain in the journal behind an earlier pending message, but their effects are already part of the server checkpoint.
redo
Redo the last undone message.
Redo likewise skips targets already covered by the durable server watermark.
Compaction
compact
Compact the journal by creating a new snapshot at the current watermark.
Removes all acknowledged messages from the journal and updates the snapshot.
compactToWatermark
Apply a server vector-clock watermark by folding the locally acknowledged, causally represented safe prefix.
Utilities
generateUUID
Generate a compact session ID (12-character nanoid).
getUnackedMessages
Get all messages that have not been acknowledged by the server.
hasPendingMessages
Check if there are any unacknowledged messages.
getPendingCount
Get the count of unacknowledged messages.
React Hooks
Available from @vuer-ai/vuer-rtc/hooks subpath.
Provider
GraphProvider
Wrap your app to provide graph context.
Props:
| Prop | Type | Description |
|---|---|---|
sessionId | string | Unique session identifier |
onSend | (msg: CRDTMessage) => void | Callback for outgoing messages |
children | ReactNode | Child components |
Example:
State Access Hooks
useGraphStore
Access the underlying graph store.
useGraph
Get the current graph state. Re-renders on any graph change.
useNode
Subscribe to a specific node. Re-renders only when that node changes.
useNodeProperty
Subscribe to a specific property of a node. Re-renders only when that property changes.
Example:
Action Hooks
useGraphActions
Get actions to modify the graph.
Example:
useDrag
Helper hook for drag operations with automatic edit buffering.
Example:
useUndoRedoShortcuts
Enable keyboard shortcuts for undo/redo (Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z).
Operations
High-level operation dispatcher and validator.
Dispatcher
applyOperation
Apply a single operation to the graph.
applyMessage
Apply all operations in a message to the graph.
applyMessages
Apply multiple messages to the graph.
createEmptyGraph
Create an empty scene graph with root node.
Validation
OperationValidator
Validator for operation schemas.
Example:
Text CRDT Utilities
getTextDocument
Get the TextRope instance from a node property.
CRDT - TextRope
High-performance text CRDT with B-tree storage. Available from @vuer-ai/vuer-rtc/crdt.
Factory
create
Create a new TextRope instance.
Queries
getText
Get the visible text content.
getLength
Get the visible character count.
getItems
Get all items (including deleted).
getStats
Get statistics about the rope structure.
Local Edits
insert
Insert text at a position.
remove
Remove text range.
replace
Replace text range.
move
Move text range to a new position.
Remote Operations
apply
Apply a remote insert operation.
applyDelete
Apply a remote delete operation.
applyReplace
Apply a remote replace operation.
applyMove
Apply a remote move operation.
Merging & Snapshots
merge
Merge two ropes (used for reconciliation).
snapshot
Create a deep copy of the rope.
compact
Remove tombstones (deleted items) from the rope.
Serialization
toRaw
Serialize to plain object.
fromRaw
Deserialize from plain object.
fromSnapshot
Create from a snapshot object.
Item Utilities
findItemById
Find an item by its ID.
itemIdEquals
Compare two item IDs for equality.
itemIdCompare
Compare two item IDs for ordering.
RangeTree (B-tree)
Low-level B-tree implementation used by TextRope.
State Management
VectorClockManager
Causal ordering utilities.
Example:
DType
Data type registry for server-side conflict resolution.
ConflictResolver
Server-side conflict resolution.
Sync Utilities
Efficient message reconciliation using bloom filters.
BloomFilter
Probabilistic set for message ID reconciliation.
Example:
Sync Digest
buildSyncDigest
Build a sync digest from client state for reconciliation.
Returns: SyncDigest object containing:
vectorClock: Covers all compacted messagesfilter: Bloom filter covering uncompacted journalcount: Journal length
Example:
Types
Core Types
TextRope Types
Operation Types
All operations extend BaseOp:
See the Operations page for the complete list of operation types.
Wire Serialization
encode
Serialize a message using msgpack.
decode
Deserialize a message from msgpack.
Example:
Advanced Usage
Edit Buffer Utilities
isAdditiveOp
Check if an operation is additive (can be merged).
mergeValues
Merge two operation values for the same key+path.
Graph Rebuilding
rebuildGraph
Rebuild the graph from snapshot + journal (used internally after undo/redo).
Related Pages
- Getting Started - Installation and basic usage
- Operations - Complete operation reference
- React Hooks - Detailed hook examples
- Rope (Text CRDT) - In-depth TextRope documentation
- Architecture - System design and concepts