Multiplayer · In depth

RoomRegistry

Bounded route-local connection groups. Sockets normally use joinRoom, leaveRoom, and roomBroadcast; 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 adds the socket to the requested match room.

  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 a bounded room and returns whether membership is active.

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.