RoomClient: waking event
@irtio/client 5.0BrowsersNodeThe waking event of the RoomClient interface fires when the room isn’t running and the router holds the connection while it starts.
Syntax
addEventListener("waking", (event) => {})
Event type
A plain Event, with no properties of its own.
Description
The router sends waking before it has looked up whether the room has room state, so it fires for every start, not only a wake: a hibernated room waking, the first start of a room this connection creates and a restart after a crash. Show something neutral, such as “Starting the room”.
When it fires, readyState is "waking". On the first connection it fires before connect() resolves, so a listener added after await connect(...) never sees it. To show a room starting, construct the client with new RoomClient(input, init), which connects as connect() does without waiting, add the listener, then await its ready.
The time a start took is in joinTime once the client is ready, whose started is true when the router sent waking on the way.
Examples
Showing a loader while the room starts
The loader says the room is starting only when the router reports it, and clears once the client holds the room’s state.
// loader.ts
import { RoomClient } from "@irtio/client";
const loader = document.querySelector("#loader")!;
const client = new RoomClient("https://rooms.irt.io/my-game/castle");
client.addEventListener("waking", () => {
loader.textContent = "Starting the room";
});
try {
const room = await client.ready;
loader.textContent = "";
console.log(`joined as ${room.player}`);
} catch (e) {
loader.textContent = "Couldn't reach the room";
console.error(e);
}
See also
openeventRoomClient.joinTime- How a room wakes, for what the room does meanwhile
- Join loader, for a ready-made loader
Runtime availability
| Browsers | Node | |
|---|---|---|
waking event | 5.0 | 5.0 |