Room

Room: a realtime room's server side. Publish to the pages in it, see who's there, ask them, and mint a token for a page to join (the TypeScript SDK's Room.join).

Rooms are named by what they're about: workflow:{id} (everyone who may open the workflow) and owner (your own open tabs, as a signed-in person). Publishing and asking need edit access to a workflow's room; an event you publish names you (from), where NoClick's own events name nobody.

class Room

A room by its name (workflow:{id}, owner). Nothing is read until you call a method.

Attributes
namestring

membersstatic

static members(
  name: string,
  options?: { client?: NoClick },
): Promise<RoomMember[]>

Who is in the room now, read through the API (no socket needed).

Parameters
namestringrequired
options.clientNoClick
Returns

Every member: the pages in the room, and the members NoClick holds (server).

history

history(
  options?: { since?: string | null; client?: NoClick },
): Promise<{ events: RoomEvent[]; reset: boolean }>

The room's recent events (at most its last 500 of the last ten minutes), after since when it names one still kept; reset when it doesn't (read what you show again).

Parameters
options.sincestring | null
options.clientNoClick
Returns

{"events": [RoomEvent, ...], "reset": bool}; reset True when since was too old, so read what you show again.

publishstatic

static publish(
  name: string,
  event: string,
  data?: unknown,
  options?: { client?: NoClick },
): Promise<string>

Publishes event with data (at most 64 KB as JSON) to everyone in the room, named as from you (needs edit access to a workflow's room); its id in the room. From a server: a page in the room broadcasts instead.

Parameters
eventstringrequired
dataunknowndefault null
namestringrequired
options.clientNoClick
Returns

The event's id in the room.

askstatic

static ask(
  name: string,
  ask: string,
  args?: JsonObject,
  options?: { client?: NoClick; timeoutS?: number; collectMs?: number },
): Promise<JsonObject>

Asks the room's pages that answer ask (room.answer) and waits for an answer, at most timeoutS (25 at most); with collectMs, that long after the first for the others'. { answer }, { answers }, or { error } (no_viewer, timeout). Needs edit access to a workflow's room.

Parameters
namestringrequired
argsJsonObject
askstringrequired
options.collectMsnumberdefault 0
options.clientNoClick
options.timeoutSnumberdefault 10
Returns

{"answer": {...}} (or {"answers": [...]} collecting), each naming the member that gave it, or {"error": "no_viewer" | "timeout"}.

Types
type JsonObject = { [key: string]: unknown };

tokenstatic

static token(name: string, options?: RoomTokenOptions): Promise<RoomToken>

A single-use token for the room's socket, for a page to open with Room.join(name, { token }).

Parameters
namestringrequired
options.originstring

The page's origin the socket will come from (a browser sends its own).

options.clientNoClick
Returns

The token, the socket's url (carrying its ticket) and what it lets the page do (access).

accessTypeScript only

access: RoomAccess

What your token lets you do here (renewed in place, so it follows an access change).

Types
/** What a token lets you do in a room: edit or view a workflow's, or your own tabs (`own`). */
type RoomAccess = "edit" | "view" | "own";

meTypeScript only

me: RoomMember | null

Your own member, once the room let you in.

statusTypeScript only

status: RoomStatus
Types
/** Where the room's socket stands: `connecting`, `live`, `reconnecting` (it will on its own), or `stopped`. */
type RoomStatus = "connecting" | "live" | "reconnecting" | "stopped";

runsTypeScript only

runs: RoomRun[]

The runs in flight on a workflow's room as you last joined.

Types
/** A run in flight on a workflow's room, as a page joining mid-run is told it. */
interface RoomRun {
  executionId: string;
  nodeStates: Record<string, string>;
  nodeOutputs: Record<string, unknown>;
}

presenceTypeScript only

presence: { set: (data: JsonObject) => void; list: () => RoomMember[] }

Your presence: set merges what you say of yourself; list is everyone here now, you included.

Types
type JsonObject = { [key: string]: unknown };

onTypeScript only

on(event: "presence", handler: (members: RoomMember[]) => void): () => void
on(event: "event", handler: (event: RoomEvent) => void): () => void
on(event: "status", handler: (status: RoomStatus) => void): () => void
on(event: "access", handler: (access: RoomAccess) => void): () => void
on(event: string, handler: BroadcastHandler): () => void

Everyone's presence as it changes (members, you included). The server's events. What your token lets you do, each time it changes (a renewal after an access change). What another member broadcast under this name.

Parameters
event"presence"required
handler(members: RoomMember[]) => voidrequired

broadcastTypeScript only

broadcast(event: string, data?: unknown): void

Tells the room's other members something (relayed only where the room's kind allows it).

Parameters
eventstringrequired
dataunknowndefault null

answerTypeScript only

answer(name: string, handler: (args: JsonObject) => unknown): () => void

Answers what the server asks this page under name (the first answer, or each with collecting, wins).

Parameters
namestringrequired
handler(args: JsonObject) => unknownrequired
Types
type JsonObject = { [key: string]: unknown };

scopeTypeScript only

scope(workflowId: string | null): void

On your own room: hear only events for one workflow (and those for none); null hears every one.

Parameters
workflowIdstring | nullrequired

stopTypeScript only

stop(executionId: string): void

On a workflow's room: stop a run (if you may edit, or it's yours).

Parameters
executionIdstringrequired

leaveTypeScript only

leave(): void

Leaves the room: the socket closes and nothing more is heard.

joinstaticTypeScript only

static join(name: string, options?: RoomJoinOptions): Promise<Room>

Joins the room: resolves once you're in (with members as they are), and stays in, reconnecting by itself, until leave (or signal). Throws what trying again can't fix: the token call refused (a room you can't open, a key without the scope) or the room refusing two fresh tokens in a row (RoomRefused).

Parameters
namestringrequired
options.presenceJsonObject

What you say of yourself as you join (merged; null removes a key). At most 1 KB as JSON.

options.token() => Promise<{ url: string; token: string }>

Where a token comes from, when not this client: your server's endpoint passing url and token on.

options.onStatus(status: RoomStatus) => void
options.signalAbortSignal

Stops the room (as leave).

options.WebSockettypeof WebSocket

A WebSocket class, where the runtime has none of its own (Node before 22).

options.clientNoClick
options.originstring

The page's origin the socket will come from (a browser sends its own).

Types
type JsonObject = { [key: string]: unknown };

/** Where the room's socket stands: `connecting`, `live`, `reconnecting` (it will on its own), or `stopped`. */
type RoomStatus = "connecting" | "live" | "reconnecting" | "stopped";

RoomEvent

interface RoomEvent

What the server published: NoClick's own (from null), or a member's through the API.

Attributes
idstring

Its place in the room (what a reconnect resumes after, and history({ since }) reads after).

eventstring
dataunknown
from{ id: string; name: string } | null
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

RoomMember

interface RoomMember

One member of a room: a page (user who they are, color the room gave them, data what they say of themselves) or one NoClick holds (server: an agent's sandbox at work, user None).

Attributes
idstring

This connection's id in the room: one person's two tabs are two members.

userRoomUser | null
colorstring | null

The colour the room gave them; null for a member NoClick holds.

dataJsonObject

What they say of themselves (presence.set).

serverboolean

One NoClick holds, such as an agent's sandbox at work.

joinedAtDate | null
rawJsonObject

The response JSON exactly as the API sent it.

Types
/** Who a member is, as their token says: null for one NoClick holds (an agent's sandbox). */
interface RoomUser {
  id: string;
  name: string;
  avatar: string | null;
  /** NoClick's staff viewing the account as its owner. */
  staff: boolean;
}

type JsonObject = { [key: string]: unknown };

RoomToken

interface RoomToken

A single-use token for a room's socket (POST /v1/rooms/{room}/tokens).

Attributes
urlstring
tokenstring
accessRoomAccess
expiresAtDate | null
connectionEndsAtDate | null
rawJsonObject

The response JSON exactly as the API sent it.

Types
/** What a token lets you do in a room: edit or view a workflow's, or your own tabs (`own`). */
type RoomAccess = "edit" | "view" | "own";

type JsonObject = { [key: string]: unknown };