RoomClient: setLobbyReady() method
@irtio/client 5.0BrowsersNodeThe setLobbyReady() method of the RoomClient interface marks this player ready in a lobby, or not ready. It’s the lobby’s call ready.
Syntax
setLobbyReady(ready)
Parameters
ready- A boolean:
trueto mark this player ready,falseto mark them not ready.
Return value
A Promise that resolves with undefined once the lobby has taken the change.
Exceptions
IrtError-
Rejects with this if the call fails. Its
namesays why:OperationError- The lobby is handing off, which its
reasonsays. In a room that isn’t a lobby, the room has noreadycall to answer. TimeoutError- The lobby didn’t answer within 10 seconds.
NetworkError- The connection dropped before the answer, or the client is reconnecting.
InvalidStateError- The client hasn’t been ready yet, or it’s closed.
Description
A lobby is a room type with lobby settings in irt.config.ts; see Lobbies and parties. room.lobby holds its state, with the ready players in ready, and the lobby event fires when it changes, including after setLobbyReady().
A player’s ready flag lasts as long as their last connection to the lobby. Under the "allReady" start rule, the countdown starts once every person is ready, and a player marking themselves not ready during the countdown stops it. Bots are always ready.
Examples
Toggling a ready button
The button marks the player ready or not ready, and its label follows the lobby’s state.
// ready-button.ts
import { connect, IrtError } from "@irtio/client";
const room = await connect("lobby", { type: "lobby" });
const button = document.querySelector("#ready")!;
room.addEventListener("lobby", ({ detail }) => {
button.textContent = detail.ready.includes(room.player) ? "Not ready" : "Ready";
});
button.addEventListener("click", async () => {
const ready = !room.lobby?.ready.includes(room.player);
try {
await room.setLobbyReady(ready);
} catch (e) {
// Such as a lobby that's handing off, or a dropped connection
if (e instanceof IrtError) console.warn(`Couldn't change ready: ${e.message}`);
else throw e;
}
});
See also
RoomClient.startCountdown()RoomClient.lobby- Lobbies and parties
<irt-lobby>, for a whole lobby screen
Runtime availability
| Browsers | Node | |
|---|---|---|
setLobbyReady() | 5.0 | 5.0 |