class RoomRegistry
Since 0.1.0

Owns the set of live rooms, creating them on demand and dropping them once empty.

Constructors

RoomRegistry(
publish?: RoomPublisher,
onMemberJoined?: () => void
)
Parameters
optional
publish: RoomPublisher

Forwards every room broadcast to other replicas. Omit for purely in-process rooms, which is the behavior when no backplane capability is registered.

optional
onMemberJoined: () => void

Invoked whenever a connection joins any room on this replica. Used to open the backplane transport on demand: a replica with a local member has to be able to RECEIVE, and subscribing does not open a transport.

Properties

readonly
size: number

Number of live rooms.

Methods

clear(): void

Discards every room.

Since 0.2.0
deliverRemote(
name: string,
data: string | Uint8Array,
exceptId?: string
): void

Delivers a frame that arrived from another replica to this replica's local members.

A room is looked up but never CREATED here. A remote frame naming a room nobody on this replica has joined has no local audience, and creating one per arriving name would let a cluster-wide namespace grow this replica's room map without bound.

Removes a connection from every room it belongs to, then discards any room left empty.

Costs O(rooms this connection is in) rather than O(all rooms), which for the overwhelmingly common case — a peer in no rooms at all — is a single failed map lookup.

get(name: string): Room

Returns the named room, creating it on first use.

Since 0.4.0
peek(name: string): Room | undefined

Returns the named room if one already exists, without creating it.

The non-allocating counterpart to RoomRegistry.get. It is a bare map read by design: it must not touch RoomRegistry.#neverJoined in either direction, because adding to that set would mark a room already in use as abandoned, and reclaiming from it on a read path would make a lookup that promises to change nothing dispose rooms.

Usage

import { RoomRegistry } from "websocket-plugin/src/index.ts";