RoomClient: readyState property
Available since
@irtio/client 5.0BrowsersNodeThe readyState read-only property of the RoomClient interface says where the client’s connection is, as WebSocket.readyState does.
Value
A string, one of these:
"connecting"- The client is connecting for the first time. It’s the value when the client is constructed.
"waking"- The room isn’t running, and the router holds the connection while it starts. The client has fired a
wakingevent. "open"- The router accepted the connection. The first time,
readyresolves when the full state update that follows is applied. "reconnecting"- The connection dropped after the client had been ready, and the client is connecting again. The client has fired a
reconnectingevent. "closed"- The connection ended for good, after
close()or a close code the client doesn’t retry, or the first connection failed: it couldn’t be dialled,timeoutpassed orsignalaborted. The client has fired thecloseevent, and it never connects again.
Description
A connection that drops before the client was first ready goes back to "connecting", not "reconnecting". A room that sleeps while the router holds the connection stays "open"; asleep says it’s sleeping.
Examples
Labelling the connection in a debug overlay
A debug overlay turns each ready state into a label, and says when the room is asleep.
// overlay.ts
import type { ReadyState, RoomClient } from "@irtio/client";
const labels: Record<ReadyState, string> = {
connecting: "Connecting",
waking: "Starting the room",
open: "Connected",
reconnecting: "Reconnecting",
closed: "Disconnected",
};
export function connectionLabel(room: RoomClient): string {
return room.asleep ? "Connected, room asleep" : labels[room.readyState];
}
See also
RoomClient.readyRoomClient.asleep- Errors and close codes, for the codes the client reconnects after
Runtime availability
| Browsers | Node | |
|---|---|---|
readyState | 5.0 | 5.0 |