@nextgensoftwares/folio-canvas-collab
Realtime collaboration for canvas boards on Folio's one collaboration engine: a board is a ProseMirror document (canvasPage, canvasObject), so board edits are ordinary steps through folio-plugin-collab, folio-sync and folio-server-node, with the same server verification, roles, comments and storage as documents and decks. Strokes and laser trails being drawn, and pointers, ride presence. Guide: Collaborating on boards.
ts
import { joinCanvas } from '@nextgensoftwares/folio-canvas-collab';
// Load (or create) the shared board on a folio-server-node and keep it live.
const live = await joinCanvas({ server: 'https://collab.example.com', docId: 'lecture-7', user: { name: 'Mona', color: '#2563eb' }, initial });
createCanvasBoard(el, { store: live.store });The same, step by step (your own transport or document API):
ts
import { canvasDocSchema, createCollabCanvas, loadCanvasDoc } from '@nextgensoftwares/folio-canvas-collab';
const pm = toProseMirrorSchema(canvasDocSchema()); // the server uses the same schema
const { doc, version } = await loadCanvasDoc(api, 'lecture-7');
const live = createCollabCanvas({ doc: pm.nodeFromJSON(doc), version, clientID, docId: 'lecture-7', user, transport });
createCanvasBoard(el, { store: live.store });Document
| Export | Description |
|---|---|
canvasSchema, canvasDocSchema(base?), CANVAS_COMMENT_TYPES | the board nodes (a Folio SchemaSpec part); the full schema: a host schema (default standardSchema) + board nodes + comment anchors on pages and objects |
OBJECT_FIELDS, PAGE_FIELDS | properties with their own attribute (the unit of last-writer-wins); anything else is stored in more |
CANVAS_ATTR_CHARS | largest JSON attribute (a long stroke's points), in characters |
canvasToDoc(doc), docToCanvas(node) | board ⇄ document (always at least one page) |
readObject(node), readPageMeta(node) | one object / page from its node; memoized per node, and a node's own id, kind and stacking key always win over more |
objectNodeJSON(object), pageNodeJSON(page, order) | node JSON for one object / page |
Sync
| Export | Description |
|---|---|
eventTransaction(state, event) | the steps that make the document follow a board document event (create, update, delete, batch, page-add, page-remove, page-update), or null |
docChanges(prev, next) | the board events that take a store from one document to the next (peers' steps, rebases), unchanged pages and objects skipped by identity |
bindCanvasDocument(store, editor) | keeps a store and an editor's document in step, whatever syncs the editor (collab client or REST); returns unbind |
dedupeTransaction(state) | removes extra copies of a page or object id on a confirmed document |
Session
| Export | Description |
|---|---|
createCollabCanvas(options) → CollabCanvas | a store (options.store or a new one) on the shared document through the engine's CollabClient; setPointer([x, y] | null), present({ camera, viewport } | null) (share this view while presenting; the board's view-camera events keep it current), presenter() → Presenter | null (the collaborator presenting: id, name, colour, page, camera, viewport), destroy(). CollabCanvasOptions extends the client's options with doc, version, store, session |
joinCanvas(options) → Promise<CollabCanvas>, JoinCanvasOptions | joins docId on a collaboration server: loads it over HTTP (creating it from initial the first time), then live over a WebSocket (/docs/<id>/collab, folio-server-node's route); api, headers, socketUrl and the session options override |
createCanvasDoc(api, docId, board, title?), loadCanvasDoc(api, docId, opts?) | store a board as a new shared document; load one whole with its version and manifest |
Presence
| Export | Description |
|---|---|
CanvasPresence (with view, a PresenterView, while presenting) | what extra.canvas carries: page, pointer, and rolling windows of the strokes (live) and laser trails (trail) being drawn |
LocalInk | tracks this client's strokes and trails in flight and encodes them within the presence size limit |
PeerInk | applies collaborators' presence to a store: cursors, live strokes growing point by point, trails |
readPresence(extra) | a peer's presence, validated (malformed entries dropped) |
peerStreamId(clientID, id) | the id a peer's stroke or trail has in this store (namespaced, unambiguous) |
PEER_LIMITS | caps per remote stream: points kept and age |