Creates a room. Normally called by SignalingServer; construct directly only in tests or custom hosts.
The room's stable identifier.
Optional limits.
OptionalidleTimeoutMs?: numberIdle window; the room force-closes if there is no relay/broadcast activity for this long while RoomState.Active.
OptionalkeepAliveOnEmpty?: booleanWhen true, the room stays open after the last peer leaves instead of closing.
OptionalmaxDurationMs?: numberHard lifetime; the room force-closes after this many milliseconds regardless of activity.
OptionalmaxPeers?: numberMaximum concurrent peers; further joins are rejected with CloseReason.RoomFull.
ReadonlyidStable identifier of this room, taken from the joining peers' auth payloads.
Adds a peer to the room and sends it the initial room-joined message.
The peer to add.
OptionaliceServers: IceServerConfig[]ICE servers to include in the peer's room-joined
message, typically from SignalingServerOptions.iceServersHook.
true if the peer was admitted; false if the room was full.
If a peer with the same id is already present, the existing connection is
disconnected with CloseReason.ReplacedByReconnection and replaced
(reconnection semantics). If the room is at capacity, the incoming peer is
disconnected with CloseReason.RoomFull and false is returned.
On a genuinely new peer, the room notifies the others with peer-joined
and presence-online, transitions to RoomState.Active, and emits
RoomEvent.PeerJoined.
Sends a message to every peer in the room.
The server message to fan out.
OptionaliceServers?: { credential?: string; urls: string | string[]; username?: string }[]OptionallocalRole?: stringOptionalpeerMetadata?: Record<string, Record<string, string>>OptionalpeerRoles?: Record<string, string>Optionalv?: numberServer's signaling protocol version; see PROTOCOL_VERSION. Optional for back-compat.
Ids of peers whose send failed (each also emits RoomEvent.PeerError); empty when all sends succeeded.
Sends a message to every peer except one.
Id of the peer to skip (usually the sender).
The server message to fan out.
OptionaliceServers?: { credential?: string; urls: string | string[]; username?: string }[]OptionallocalRole?: stringOptionalpeerMetadata?: Record<string, Record<string, string>>OptionalpeerRoles?: Record<string, string>Optionalv?: numberServer's signaling protocol version; see PROTOCOL_VERSION. Optional for back-compat.
Ids of peers whose send failed; empty when all sends succeeded.
Disconnects a peer and removes it from the room synchronously, without
sending a kicked message.
Id of the peer to disconnect and remove.
WebSocket close code.
WebSocket close reason.
true if the peer was found and removed; false otherwise.
Used by the heartbeat monitor to prune an unresponsive peer. Mirrors
Room.kickPeer's synchronous removal so the peer does not linger in
Room.getPeers (where it would be re-disconnected on every tick) or
keep holding a maxPeers slot while its ws close handshake completes.
Tears down the room's timers and moves it to RoomState.Closed without notifying or disconnecting peers. Used during server shutdown, where connections are closed separately.
Synchronously invokes every listener registered for event, in registration order.
true if at least one listener was invoked, false if there were none.
The listener list is snapshotted before dispatch, so mutations made by handlers take effect only on subsequent emissions. Listeners are isolated: if one throws, the remaining listeners still run and the error is surfaced via console.error rather than swallowed silently (consistent with LocalMessageBus).
The number of peers currently in the room.
A snapshot array of the ids of all peers in the room.
Returns a copy of the metadata a peer supplied at join time.
The peer id.
A shallow copy of the peer's metadata, or undefined if the peer
is unknown or supplied none.
Forcibly removes a peer from the room.
Id of the peer to remove.
Optionalreason: stringOptional human-readable reason sent to the peer and used as the close reason; defaults to CloseReason.Kicked.
true if the peer was found and kicked; false otherwise.
Sends the peer a kicked message, disconnects it with
CloseCode.PolicyViolation, and emits RoomEvent.PeerKicked.
Returns the number of listeners currently registered for event.
The event name to count listeners for.
The count of registered listeners (0 if none).
Marks the room as active, resetting the idle-timeout countdown.
Called on heartbeat pongs so that quiet-but-alive rooms are not closed by SignalingServerOptions.roomIdleTimeoutMs.
Registers a listener that is invoked at most once: it is removed automatically before
being called the first time event is emitted.
This emitter, for chaining.
Remove a pending one-time listener by passing the same function reference to off.
Relays a directed signal from one peer to another and counts as room activity (resets the idle timer).
Id of the sending peer (stamped on the outgoing signal).
Id of the recipient peer.
Opaque signal payload (SDP/ICE, etc.).
true if the recipient existed and the message was sent; false
if the recipient is absent or the send failed (which also emits
RoomEvent.PeerError).
Removes listeners for a single event, or for all events.
Optionalevent: keyof RoomEventsThe event name to clear; if omitted, listeners for every event are removed.
This emitter, for chaining.
Changes a peer's role and notifies the whole room.
Id of the peer whose role is changing.
The new role string.
true if the peer was found and updated; false otherwise.
A group of peers that exchange signaling messages with one another.
Remarks
A room is created lazily by SignalingServer when its first peer joins and, unless kept alive, closes automatically when its last peer leaves. It relays directed signals (Room.relay), fans out broadcasts (Room.broadcast / Room.broadcastExcept), tracks per-peer roles and metadata, and enforces optional capacity, idle-timeout, and max-duration limits. Its lifecycle is modeled by RoomState.
Rooms extend the core
EventEmitterand emit RoomEvent values as peers join, leave, error, or are kicked, and when the room closes. You typically obtain a room from SignalingServer.getRoom or the ServerEvent.RoomCreated event rather than constructing it directly.