# Realtime rooms

> Who else has a workflow open and where they are, the events NoClick publishes as it changes, and asking the pages open on it.

A room is a realtime place your pages join. In it they see **who else is there** and what each says of themselves (a cursor, a selection), hear **the events the server publishes** (a write's changes, a run's steps), and can **answer what the server asks them**. It's what the NoClick app's canvas runs on, and it's yours through the SDKs.

Rooms are named by what they're about:

| Room | Who's in it | What a token lets you do |
| --- | --- | --- |
| `workflow:{id}` | Everyone who may open the workflow | `edit` or `view`, as the workflow's sharing says |
| `owner` | Your own open tabs, signed in to NoClick | `own` |

NoClick's API decides who joins from the key or session your client holds: a room you can't open answers as one that doesn't exist. Rooms for your own apps (`app:{project}:{name}`, tokens minted by your app's server for its users) come with their metering.

## Join a room from a page

```ts
import { Room } from "noclick";

const workflowId = "3f1c2a9e-5b7d-4c1e-9a2b-7d6e5f4c3b2a";
const room = await Room.join(`workflow:${workflowId}`, { presence: { cursor: null, selection: [] } });

room.on("presence", (members) => {
  for (const member of members) {
    if (member.id !== room.me?.id) console.log(member.user?.name, member.color, member.data.cursor);
  }
});
room.on("event", (event) => {
  if (event.from === null && event.event === "workflow:graph_changed") console.log("the workflow changed: read it again");
});
room.presence.set({ cursor: { x: 120, y: 40 } });
console.log(room.access); // "edit" or "view"

// later
room.leave();
```

Each member is shown under who they are (`user`, from their token) with a `color` the room gave them; their `data` is what they said of themselves with `presence.set`, at most 1 KB. One person's two tabs are two members. A member NoClick holds, such as an agent's sandbox at work, has `server: true` and no `user`.

`join` resolves once you're in and stays in: it reconnects by itself, resuming after the last event it gave you, and renews its connection in place before it ends, so `room.access` follows a change to the workflow's sharing without a reload (`room.on("access", ...)`). It throws only what trying again can't fix: a room you can't open, or the room refusing two fresh tokens in a row (`RoomRefused`).

In a browser whose server holds your key, hand `join` a `token` function that asks your server for one (`Room.token(name)` there, or `noclick.Room(name).token()` in Python), and pass its `url` and `token` on as they are.

## Events and broadcasts

The server's events come with an `id` and `from`: NoClick's own name nobody (`from: null`); one a member published through the API names them. Read the room's recent events (at most its last 500 of the last ten minutes) with `room.history({ since })`; `reset` says your `since` was too old, so read what you show again.

A broadcast goes from one member to the others, only where the room's kind allows it. On a workflow's room, someone who may edit can broadcast their builder's progress (`ai_editing.start`, `ai_editing.update`, `ai_editing.end`); anything else is refused, and the sender is told once with a `refused` frame.

```python
import noclick

workflow_id = "3f1c2a9e-5b7d-4c1e-9a2b-7d6e5f4c3b2a"
room = noclick.Room(f"workflow:{workflow_id}")
room.publish("review.ready", {"step": "draft"})   # needs edit access; named as from you
for member in room.members():
    print(member.user and member.user["name"], member.data.get("selection"))
```

```ts
import { Room } from "noclick";

const workflowId = "3f1c2a9e-5b7d-4c1e-9a2b-7d6e5f4c3b2a";
const room = await Room.join(`workflow:${workflowId}`);
room.broadcast("ai_editing.start", { nodeIds: ["draft"] });   // needs edit access
for (const member of await Room.members(`workflow:${workflowId}`)) {
  console.log(member.user?.name, member.data.selection);
}
room.leave();
```

## Ask the pages in a room

The server asks the pages that answer a name, and waits for the first answer (or, with `collect_ms`, each within that window); a page answers by name:

```python
import noclick

workflow_id = "3f1c2a9e-5b7d-4c1e-9a2b-7d6e5f4c3b2a"
reply = noclick.Room(f"workflow:{workflow_id}").ask("canvas.get_selected", timeout=5)
if "error" in reply:          # "no_viewer": nobody answers it; "timeout"
    print("no page answered:", reply["error"])
else:
    print(reply["answer"]["result"])
```

```ts
import { Room } from "noclick";

const workflowId = "3f1c2a9e-5b7d-4c1e-9a2b-7d6e5f4c3b2a";
const selected: string[] = ["draft"];
const room = await Room.join(`workflow:${workflowId}`);
room.answer("canvas.get_selected", async () => ({ nodes: selected }));
```

Asking needs edit access to a workflow's room. The NoClick app's workflow MCP asks your open canvas this way.

## Limits

- A token opens one connection, within a minute; a connection lasts at most 15 minutes and renews in place.
- Presence: 1 KB a member; presence changes and broadcasts, 30 a second a member.
- A broadcast or a published event: 64 KB of data.
- An ask waits 25 seconds at most.

The REST routes are `POST /v1/rooms/{room}/tokens`, `GET /v1/rooms/{room}/presence`, `GET /v1/rooms/{room}/events`, `POST /v1/rooms/{room}/events` and `POST /v1/rooms/{room}/ask`. A room's token is a bearer for a socket, so no MCP connection gets one; [watch](https://www.noclick.com/docs/guide/watch.md) is the stream of which of your objects changed.
