RoomRegistry

Documentation for Redweb 0.16.1. Install that exact version when following these examples.

Bounded route-local connection groups. Use asynchronous enterRoom for guarded membership, joinRoom for unguarded rooms, and roomBroadcast for delivery; disconnect cleanup removes all memberships and reclaims empty rooms.

Explain it like I’m five

RoomRegistry is a set of labeled group chats. A socket can join a label, and one message can be delivered to everyone carrying that label.

When should I use it?

Use rooms for match participants, parties, regions, spectators, or any bounded route-local fan-out group.

Follow the example

This API pattern illustrates the named surface; it may require application-owned classes, credentials, or assets. Start from a complete recipe for a runnable application.

js
class MatchRoute extends SocketRoute {
  constructor() {
    super({
      path: '/match',
      handlers: [JoinMatchHandler, MoveMatchHandler, ResumeMatchHandler],
      rooms: { maxRooms: 1000, maxMembersPerRoom: 32 },
    })
  }
}
  1. A join handler awaits socket.enterRoom(roomId) for protected rooms and checks the result before treating entry as accepted.
  2. The move handler broadcasts the accepted update to that room and can exclude the sender.
  3. Disconnect cleanup removes every membership and empty rooms are reclaimed automatically.

Methods and members

socket.joinRoom(roomId)

Idempotently joins an unguarded bounded room and returns whether membership is active. Throws when rooms.authorize is configured; use await socket.enterRoom(roomId) instead.

await socket.enterRoom(roomId)

Applies configured room authorization before committing bounded membership and resolves to whether membership is active. Also works for unguarded rooms.

registry.roomsFor(socket)

Returns a snapshot of the socket's current room IDs. Room membership is delivery state, not a durable game seat.

socket.leaveRoom(roomId)

Idempotently leaves one room and reclaims it when empty.

socket.roomBroadcast(roomId, data, options?)

Serializes once and sends to selected connected members.

What should I watch for?

A room is a delivery group, not authoritative game state. Validate membership and permissions before broadcasting, and configure hard room and membership limits.