RoomClient: ready property
@irtio/client 5.0BrowsersNodeThe ready read-only property of the RoomClient interface is a Promise that resolves to the client once it holds the room’s full state, when connect() would resolve.
Value
A Promise that resolves to the same client as a ReadyRoomClient, the client typed with state and private set.
It rejects with an IrtError when the client fails for good before it’s ready, as connect() rejects:
NetworkErrorwhen the room can’t be reached over WebTransport or WebSocket- an error named for the close code when the router closes the connection with a code the client doesn’t retry, such as
VersionErrorfor 4004 TimeoutErrorwhen thetimeoutoption passes first, or thesignaloption comes fromAbortSignal.timeout()NotSupportedErrorwhen the runtime has no globalWebSocket, as Node before 24AbortErrorwhen anothersignalaborts, with its reason ascause, or whenclose()is called first
Description
ready settles once. It resolves when the client applies the room’s first full state update, and later reconnects don’t change it. After it resolves, the client reconnects by itself and fires an open event after each reconnect.
connect() is new RoomClient(input, init) followed by awaiting ready. Construct the client and await ready yourself when a listener must be added before the client connects, such as one for the waking event.
Examples
Showing that the room is starting
The player sees “Starting the room” while a hibernated room wakes, and an error if the client can’t connect.
// join-screen.ts
import { IrtError, RoomClient } from "@irtio/client";
const client = new RoomClient("main", { timeout: 20_000 });
client.addEventListener("waking", () => console.log("Starting the room"));
try {
const room = await client.ready;
console.log(`joined as ${room.player}`);
} catch (e) {
if (!(e instanceof IrtError)) throw e;
console.error(`couldn't join: ${e.name}`);
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
ready | 5.0 | 5.0 |