RoomRegistry

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

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

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 adds the socket to the requested match room.
  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 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.

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.