RoomClient: lobby property
Available since
@irtio/client 5.0BrowsersNodeThe lobby read-only property of the RoomClient interface is the state of the lobby the client is in: its phase, who is ready and when the countdown ends.
Value
An object with these properties, or undefined in a room that isn’t a lobby:
phase"waiting"while players get ready,"countdown"once the countdown runs or"handing-off"while the lobby moves its players to the match.ready- An array of the player IDs of the ready people, in the order they joined, then of every bot.
startsAt- A number: when the countdown ends, in the room’s wall-clock milliseconds, to compare with
serverTime().nulloutside the countdown. min- A number: the lobby’s
minPlayers. max- A number: the lobby’s
maxPlayers. failed- Why the last handoff failed, until the next countdown:
"players"when too few people were left,"limit"for a room limit,"spending"for a spending limit,"unavailable"for anything else.nullwhen no handoff failed.
Description
A lobby sends its state after the client’s first state update and whenever it changes, and the lobby event fires each time. Players change it with setLobbyReady(), and the lobby’s leader with startCountdown() and cancelCountdown().
Examples
Showing the countdown
The lobby screen shows how many players are ready and, during the countdown, the seconds until the match.
// lobby-screen.ts
import type { RoomClient } from "@irtio/client";
export function lobbyLine(room: RoomClient): string {
const lobby = room.lobby;
if (!lobby) return "";
const now = room.serverTime();
if (lobby.phase === "countdown" && lobby.startsAt !== null && now !== undefined) {
return `Starting in ${Math.ceil((lobby.startsAt - now) / 1000)}`;
}
if (lobby.phase === "handing-off") return "Starting the match";
return `${lobby.ready.length} of ${lobby.min} needed are ready`;
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
lobby | 5.0 | 5.0 |