Live apps: Room()
For apps a few people use together at the same time (planning poker, polls and quizzes, idea walls, drawing together), Room() gives you the same room as Game() with no game UI: no canvas, score, pause, touch pad or countdown. Your page draws, with plain HTML, a canvas of its own or any library, and reads the room every frame.
<script src="room.js"></script><script src="game.js"></script><script>const room = Room({ title: "Planning Poker", max: 12, player: { v: [0, 12] }, // each person's own state: here, the card they picked actions: { // run on the host's browser: the one writer of the shared state reveal(room) { room.shared.set({ shown: 1 }); }, }, update(room) { draw(room.players, room.shared); }, // every frame, every page});cardButton.onclick = () => room.me.set({ v: 6 });revealButton.onclick = () => room.act("reveal");</script>- It starts by itself: nobody presses Start. A page opened without a room link gets a new private room; the invite link (
#room=CODE) brings people into that room, straight into the session. - A small chip in a corner shows the room code, how many are here, Room and Invite. Room opens the room menu: the code and the invite link, who is here, join with a code, a new room, and with
roomList: truethe open rooms of this app and Join an open room (Esc or Close shuts it; the session goes on underneath).chip: falsehides the chip;room.room.code,room.invite()androom.roomMenu()do the same from your own UI. - Who writes what is the same as in a game: each person their own state (
room.me.set), the host the shared state (inside an action handler,hostorsetup), anyone asks the host withroom.act(name, data), androom.fx(name, data)sends something once without storing it (a stroke, a reaction). - Other people’s
x,y,z,angle,rot(and the quaternion) are eased between updates, so cursors glide; any other number (a vote, a colour) shows as sent. save: truekeeps the shared state between sessions, as a saved world (needs saves on the server).- Options:
title,max(16 at most),player,save,open,actions,setup,host,update,onAction,onFx,chip,roomList(false),exit.Game()takes the same room options at the top too (max,player,save,open,actions;maxorplayerthere makes it multiplayer), or insidemultiplayer: {...}as before. - Actions: one entry per name in
actions, run on the host, so there is noif (name === ...)chain. An entry is a handler(room, from, data)(returnfalseto refuse) or{ check, run }:checkis a Standard Schema (Zod 3.24+, Valibot 1, ArkType 2, nothing to install from tickcli) or a function(data) => true | "why not". The check runs on the asking page first (a mistake shows there,room.actresolves{ok: false, error: "bad_value: ...", issues}with no round trip) and again on the host, andrungets the value the schema returns (defaults filled in, numbers coerced). Withactionsset, a name with no entry goes toonActionwhen there is one, else it is refused (unknown action).onAction(room, from, name, data)still works alone.actions: {note: { check: z.object({ text: z.string().min(1).max(200), x: z.number(), y: z.number() }),run(room, from, n) { room.shared.set({ notes: { [from + "-" + Date.now()]: { ...n, by: from } } }); } },clear(room) { room.shared.set({ notes: null }); },}, - Types:
client/game.d.tstypesGame()andRoom()for editor hints and checks (TypeScript, or plain JavaScript with// @ts-check):Room<Me, Shared, Actions>({...})typesroom.me.set,room.shared(read-only,set/put) androom.act(a name with no entry or the wrong data is an error in the editor). Load it with/// <reference path="./node_modules/tickcli-js/client/game.d.ts" />orimport "tickcli-js/client/game.d.ts". - Undo:
room.undo()/room.redo()(alsog.undo()in games) take back your own last action: the host remembers what each action wrote to the shared state and writes the old values back, except where someone changed that spot since (then it answers{ok: false, error: "changed"}and theirs stays). A spot is the key the action wrote (Pixel Wall: a row of the wall), actions of the same name less than a second apart are one step (a stroke sent in batches), 50 steps per person. The history lives in the host’s page: a new host starts without one. - Shared text and long documents:
room.doc("notes")(alsog.docin games) is a YjsY.Doceveryone in the room edits together:Y.Textfor notes and descriptions,Y.Array/Y.Mapfor lists and boards. Edits merge, so two people typing at once both land, without the shared state’s 200-character and 64 KB limits. Load<script src="lib:yjs"></script>beforelib:game(Yjs 13.6 ships with tickcli as one script; MIT, notice inclient/vendor/yjs.LICENSE.txt). The hub never reads documents: it numbers each update, sends it to the others, gives a page that joins the whole document, and when updates pile up asks the page that wrote the last one to pack them into one. A page merges its own updates and sends at most every 60 ms; edits made while the line is down are sent as one difference after the reconnect. A room with a save keeps its documents beside it (<save>#docsin the store), so a board’s notes come back with its link. Viewers read but never write. Up to 4 documents a room, 256 KB each (docsPerRoom,docBytes). Cursors and who is typing stay in each person’s own state (room.me.set). - Writes without the host’s round trip: list keys in
open: ["cells"]and anyone (not a viewer) writes them withroom.shared.put({cells: {"3,4": 2}}). It shows on the writer’s screen at once and the server orders it: the last write to a spot wins on every screen, also over the host’s. An action goes page, hub, host page, hub, pages; a put goes page, hub, pages. Measured in real browsers through a proxy holding each message rtt/2 each way, median to another screen: about the same on one machine (32 vs 36 ms), 182 vs 89 ms at a 60 ms round trip, 358 vs 199 ms at 150 ms. Use it for data keyed per spot (a cell, a sticky note, a stroke by id): a value that is one long text or a whole list loses one of two writes made at once, so keep those on actions (Pixel Wall’s rows) or use per-item keys. Open keys are top-level (up to 16) and still follow the write limits. - View-only links: the room menu’s Copy view-only link (
room.inviteView()) makes a#view=link. People who open it see the room live (and show as watching) but cannot change anything: the hub refuses their actions (view_only), effects and shared writes and never makes them host, so it is not just hidden buttons. The link carries a token, not the room code (the edit key); the hub turns it back into the room, and a made-up token gets nowhere.room.vieweris true on their page (Pixel Wall hides its tools). A saved board opened by viewers alone opens from its save. Tokens are signed with the server’s secret: keep the secret across restarts (as for seats) or old view links stop working. - Boards people come back to:
save: "room"keeps each room’s shared state as its own save, under the room’s code. Those rooms get a 12-letter code (about 8 x 10^17 of them, shown asABCD-EFGH-JKMN, so it cannot be guessed), the address keeps#room=CODE, and opening that link again (tomorrow, after a restart) continues the same board. A page without a link starts a new one. A short code typed by hand still opens a room, but an unsaved one.save: truekeeps one save per app instead (one board for everyone). - Fits sessions, not documents: 64 KB of shared state, 64 items a list, 200 characters a text, 16 people a room. Long documents, rich-text co-editing and offline edits need a CRDT such as Yjs; a room can still carry the cursors beside it.
Examples: planning-poker.html (plain HTML), pixel-wall.html (a 2D canvas, saved between sessions), both in examples/games/ and played by real browsers in e2e/apps.ts. Two boards built on room.doc(), played in e2e/boards.ts: sketch-board.html (draw together: smooth pen strokes, sticky notes, eraser, undo of your own changes, PNG export; strokes in progress show live as effects and land as one document change) and brainstormy.html (an idea wall that turns into a sprint board: sticky notes placed and dragged live on a wall, the same notes as cards in four columns ordered by fractional keys, each person picks the view, and each view keeps its own placement; shared note text, dot votes hidden until Reveal, a shared timer, anonymous mode, Copy as Markdown). Both keep a board per room (save: "room") and hide their tools for view-only links.