Skip to content

Realtime (Tier 3)

Live, multiplayer collaboration powered by Y.js — shared text, arrays, and maps, plus presence (cursors, who’s here). Access via sdk.realtime(docId).

const doc = sdk.realtime('workspace');
await doc.connect();
const text = doc.text('content'); // collaborative text
const list = doc.array('items'); // collaborative array
const meta = doc.map('metadata'); // collaborative map
text.insert(0, 'Hello');
text.observe(() => render(text.toString()));
list.push([{ id: 1, name: 'Item' }]);
list.observe(() => render(list.toArray()));
doc.presence.set({ user: { name: 'Alice', color: '#2161FF' }, cursor: { x: 100, y: 200 } });
doc.presence.subscribe(users => {
for (const [clientId, state] of users) renderCursor(clientId, state.cursor);
});
doc.transact(() => { list.push(['a']); list.push(['b']); });
const undo = doc.undoManager([text]);
undo.undo();
undo.redo();

on('status' | 'sync' | 'update', handler) — status is connecting, connected, or disconnected. Clean up with doc.disconnect().

<script type="shareout/manifest">
{ "version": "2.0", "sources": { "realtime": ["workspace", "cursors"] } }
</script>

For structured but non-collaborative data, use tables instead.