You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only components that read `players` will re-render when the players map changes.
85
85
86
+
### `useRoomMessage(room, type, callback)`
87
+
88
+
Subscribes to Colyseus room messages. The callback is kept in a ref so it is always up-to-date without re-subscribing. Automatically unsubscribes when the room changes or the component unmounts.
Pass `"*"` as the type to listen to all message types.
110
+
111
+
### `useLobbyRoom(callback, deps?)`
112
+
113
+
Connects to a Colyseus [Lobby Room](https://docs.colyseus.io/builtin-rooms/lobby/) and provides a live-updating list of available rooms. The list is automatically maintained as rooms are created, updated, and removed.
|`rooms`|`RoomAvailable<Metadata>[]`| Live list of available rooms |
146
+
|`room`|`Room \| undefined`| The underlying lobby room connection |
147
+
|`error`|`Error \| undefined`| Connection error, if any |
148
+
|`isConnecting`|`boolean`|`true` while connecting to the lobby |
149
+
150
+
### `useQueueRoom(connect, consume, deps?)`
151
+
152
+
Manages the full lifecycle of a Colyseus matchmaking queue: connecting to the queue room, tracking group size, receiving a seat reservation, confirming, and consuming the seat to join the match room. Cleans up both rooms on unmount.
if (isWaiting) return <p>Waiting for match... {clients} players in group</p>;
169
+
return <p>Connecting...</p>;
170
+
}
171
+
```
172
+
173
+
The first argument connects to the queue room. The second argument is called with the `SeatReservation` once a match is found — use `client.consumeSeatReservation()` to join the match room.
174
+
175
+
**Return value:**
176
+
177
+
| Field | Type | Description |
178
+
|---|---|---|
179
+
|`room`|`Room \| undefined`| The match room, once the seat has been consumed |
180
+
|`queue`|`Room \| undefined`| The queue room while waiting (undefined after match is joined) |
181
+
|`clients`|`number`| Number of clients in the current matchmaking group |
182
+
|`seat`|`SeatReservation \| undefined`| The seat reservation, once received |
183
+
|`error`|`Error \| undefined`| Connection or matchmaking error |
184
+
|`isWaiting`|`boolean`|`true` while connected to the queue and waiting for a match |
185
+
186
+
## Contexts
187
+
86
188
### `createRoomContext()`
87
189
88
190
Creates a set of hooks and a `RoomProvider` component that share a single room connection across React reconciler boundaries (e.g. DOM + React Three Fiber). The room is stored in a closure-scoped external store rather than React Context, so the hooks work in any reconciler tree that imports them.
@@ -129,6 +231,62 @@ function UI() {
129
231
130
232
The returned `useRoom()` and `useRoomState(selector?)` work identically to the standalone hooks but don't require you to pass the room as an argument.
131
233
234
+
### `createLobbyContext()`
235
+
236
+
Creates a `LobbyProvider` and `useLobby` hook for sharing lobby room data globally across your app — useful when you need room metadata available persistently alongside an active game room, not just on a lobby screen. Like `createRoomContext`, it uses a closure-scoped external store so the hook works across reconciler boundaries.
`LobbyProvider` accepts a `connect` callback (same as `useLobbyRoom`) and an optional `deps` array. The lobby connection persists independently of the game room.
266
+
267
+
**Access lobby data from any component — even deep inside the game:**
0 commit comments