Multiplayer · In depth

RoomRegistry

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

The simple mental model

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 it fits

When should I use it?

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

A practical API pattern

Follow the example

This pattern explains the named API. Application classes, credentials, and assets may need to be supplied; use a complete recipe for a runnable starting point.

Read this article as Markdown

JavaScript
class MatchRoute extends SocketRoute {
  constructor() {
    super({
      path: '/match',
      handlers: [JoinMatchHandler, MoveMatchHandler, ResumeMatchHandler],
      rooms: { maxRooms: 1000, maxMembersPerRoom: 32 },
    })
  }
}
  1. 1

    A join handler awaits socket.enterRoom(roomId) for protected rooms and checks the result before treating entry as accepted.

  2. 2

    The move handler broadcasts the accepted update to that room and can exclude the sender.

  3. 3

    Disconnect cleanup removes every membership and empty rooms are reclaimed automatically.

Surface area

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.