Skip to content
state meaning
joining admitted; no live link yet
connected linked to at least one peer
away the page is hidden on a phone or in desktop Safari, so jsflow said goodbye: it holds no slot and accrues no time. Back to connected when the page returns, with the same id
superseded this room object stopped for good: a newer join took its id (the page was frozen or offline so long that its slot was freed, say). join() again (you get a new id). Two tabs never supersede each other: every join gets its own id
evicted your backend removed this peer (and the other peers cut it off). Final: joining again is refused (blocked) until the block ends. The evicted event carries until, a unix time in seconds
suspended the account’s spend cap is reached: links stay up, but new joins to the account’s apps are refused (quota) until an owner raises the cap or the next period starts. It returns to connected by itself. The suspended event carries reason: 'quota'
left leave() was called

An exhaustive switch on State needs all seven.

A phone goes away and comes back, in three frames: p5 is linked to p2 and p4, then its page is hidden and its links drop, then it rejoins with the same id and its links return. 1. p5, a phone, is linked directly to p2 and p4. 2. p5's page is hidden: it says goodbye, is drawn hollow and labelled away, and its links drop; the other peers route around it. 3. The page returns: p5 rejoins through the introducer (a dotted line) with the same id, and its links to p2 and p4 return. introducer p1 p2 p3 p4 p5 1 · p5 here linked to p2 and p4 introducer p1 p2 p3 p4 p5 · away 2 · page hidden: away it says goodbye; links drop introducer p1 p2 p3 p4 p5 · back 3 · back, same id rejoined via the introducer
A hidden page goes away, its links drop and the others route around it; when it returns it rejoins with the same id.

Joining takes about 1 to 2 seconds until the first peer link (p95 ≤ 3.7 s in lab tests). The first peer in a room has no one to link to and stays in joining until a second one arrives.

A peer joining through the introducer, in three frames: p5 calls join, the introducer introduces it to p2 and p4, then p5 links directly to them while the introducer stays in the background. 1. p5 calls join(); the introducer, outside the room, admits it (a dotted line from the introducer to p5). 2. The introducer introduces p5 to p2 and p4 (dotted lines to all three); it carries only the setup, never the data. 3. p5 is linked directly to p2 and p4; the dotted lines are gone and the introducer stays in the background. introducer p1 p2 p3 p4 p5 · joining 1 · p5 calls join() the introducer admits it introducer p1 p2 p3 p4 p5 · joining 2 · introduced to p2, p4 it carries only the setup introducer p1 p2 p3 p4 p5 3 · linked directly no data via the introducer
The introducer admits you and introduces you to a few peers; then the links are direct and the introducer is out of the data path.

join() resolves once you are admitted to the room, usually before any link is up: listen for state 'connected' or for peer events.

The SDK tells the service when the page goes away, so the room slot frees at once. The page that loads next is a new peer with a new id. Peers that drop without saying goodbye (a crash, a network loss, a killed browser) keep their slot for 15 seconds, so they can reconnect. After that the slot is free.

Mobile browsers freeze hidden pages. When the page is hidden, jsflow sends a goodbye (away) so the others route around it at once. On return it rejoins, usually within about a second. Desktop Chrome keeps running hidden tabs and stays connected. Safari on the desktop does the same as phones, so a background Safari tab is away until it is shown.

bye: false turns the goodbye off, but Safari may freeze the page anyway, and its links then die slowly instead of at once: leave the default. If your app needs to know that a user is away (to skip their turn, say), tell your server from your own visibilitychange handler.

Call room.leave() when the user leaves the room in your UI. Closing the page does the same by itself.

join() rejects with a JoinError: e.status is the HTTP status (0 when the SDK refuses by itself) and e.code is one of the error codes. Branch on e.code, never on the message. A network failure rejects with a TypeError instead.

  • Room full (room_full, 409). The room is at its peer limit. Slots free as peers leave, or 15 seconds after a peer dropped. Retry every 2 to 3 seconds for up to about 30 seconds from the first attempt. Do not use a growing backoff: it turns a 15-second wait into 25 or more.
  • Rate (rate, 429). Too many joins from this IP or this app per minute. Retry after 5 to 10 seconds, a few times.
  • Too many rooms, too many streams (too_many_rooms, too_many_streams, 429). Your app’s room limit, or this IP’s open connections. Do not retry quickly: close rooms you no longer use, or ask for a higher limit.
  • Unknown app or origin (unknown_app, origin, 403). A configuration error. Retrying will not help. See troubleshooting.
  • Ticket (ticket_required, ticket_invalid, ticket_expired). The app requires a join ticket from your backend, or yours was wrong or too old. For ticket_expired, get a fresh ticket and join again.
  • Blocked or over the cap (blocked, quota). Your backend blocked this user, or the account’s spend cap is reached. Retrying will not help until the block ends or the cap is raised.
  • Wire or SDK version (wire, sdk_unsupported). The room runs the other wire version (a 0.1 page in a 1.0 room, or the reverse), or the SDK is older than the service accepts. Update the SDK on every page.
  • The browser (unsupported_browser, worker_failed, status 0). The browser cannot do the cryptography the SDK needs, or the SDK’s worker did not start twice on a busy device: joining again usually works.
import {
join, JoinError, type JoinOptions, type Room,
} from 'jsflow-sdk';
async function joinWithRetry(opts: JoinOptions): Promise<Room> {
for (const t0 = Date.now(); ; ) {
try {
return await join(opts);
} catch (e) {
const full = e instanceof JoinError && e.code === 'room_full';
if (!full || Date.now() - t0 > 30_000) throw e;
await new Promise((r) => setTimeout(r, 2500));
}
}
}

Venue Wi-Fi, or a server-side event that reloads every page. In lab tests with 30 peers, everyone was back within 12 seconds when the pages reloaded, and within 19 seconds when the browsers were killed (their slots were held 15 seconds). Do not make the room wait for one particular peer to come back: pick another one to lead or host.