# RoomClient: lobby event

> The lobby event of the RoomClient interface fires when a lobby's state changes.

The **`lobby`** event of the [`RoomClient`](/docs/client/room-client) interface fires when the state of the lobby the client is in changes, and sets [`lobby`](/docs/client/room-client/lobby).

## Syntax

```ts
addEventListener("lobby", (event) => {})
```

## Event type

A `CustomEvent` whose `detail` is the new `room.lobby`, an object with these properties:

`phase`
: A string: `"waiting"`, `"countdown"` or `"handing-off"`.

`ready`
: An array of player IDs: the ready people in the order they joined, then every bot, which is always ready.

`startsAt`
: A number or `null`. When the countdown ends, in the room's wall-clock milliseconds, so compare it with [`serverTime()`](/docs/client/room-client/servertime). `null` outside the countdown.

`min`
: A number. The lobby's `minPlayers`.

`max`
: A number. The lobby's `maxPlayers`.

`failed`
: A string or `null`. 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. `null` when no handoff failed.

## Description

A lobby sends its state after the client's first state update and whenever it changes, so `lobby` fires once the client has joined and again on every change. It never fires in a room that isn't a lobby.

The event fires on changes only, so a countdown display needs its own timer between them. [`setLobbyReady()`](/docs/client/room-client/setlobbyready), [`startCountdown()`](/docs/client/room-client/startcountdown) and [`cancelCountdown()`](/docs/client/room-client/cancelcountdown) change the lobby's state, and the change arrives as a `lobby` event.

## Examples

### Showing a lobby's progress

A party game's lobby screen shows how many are ready, the countdown and the last failure.

```ts
// lobby-screen.ts
import { connect } from "@irtio/client";

const room = await connect("https://rooms.irt.io/my-game/lobby", { type: "lobby" });
const status = document.querySelector("#lobby-status")!;

room.addEventListener("lobby", ({ detail: lobby }) => {
  if (lobby.failed) console.warn(`the last start failed: ${lobby.failed}`);
  if (lobby.phase === "waiting") status.textContent = `${lobby.ready.length} ready, ${lobby.min} needed`;
  if (lobby.phase === "countdown" && lobby.startsAt !== null) {
    const seconds = Math.ceil((lobby.startsAt - (room.serverTime() ?? Date.now())) / 1000);
    status.textContent = `Starting in ${seconds} s`;
  }
  if (lobby.phase === "handing-off") status.textContent = "Finding a match";
});
```

`serverTime()` is `undefined` before the client's first ping is answered, so the example falls back to the local clock.

## See also

- [`RoomClient.lobby`](/docs/client/room-client/lobby)
- [`handoff` event](/docs/client/room-client/handoff-event)
- [`RoomClient.setLobbyReady()`](/docs/client/room-client/setlobbyready)
- [Lobbies and parties](/docs/room/guides/lobbies), the guide
