Creates a signaling server. No socket is opened until SignalingServer.start is called.
Server configuration; see SignalingServerOptions.
Defaults to an empty object (unauthenticated, port 3000, 30s ping /
60s pong). When opts.cluster is provided, a RoomRouter is
constructed for room sharding.
The TCP port the server is actually listening on, or undefined before
SignalingServer.start resolves. Resolves the OS-assigned port when
the server was created with port: 0.
Registers a JSON health endpoint on an existing HTTP server.
The HTTP server to add the listener to.
The URL path to serve.
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).
Returns a snapshot of current server activity.
Live room count, peer count, and uptime. See ServerStats.
Returns the number of listeners currently registered for event.
The event name to count listeners for.
The count of registered listeners (0 if none).
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.
Removes listeners for a single event, or for all events.
Optionalevent: keyof SignalingServerEventsThe event name to clear; if omitted, listeners for every event are removed.
This emitter, for chaining.
Starts listening for connections and begins the heartbeat.
A promise that resolves when the server is listening.
If SignalingServerOptions.server was provided, the WebSocket server attaches to it; otherwise a new HTTP server is created and bound to SignalingServerOptions.port (default 3000). Resolves once the server is accepting connections.
Gracefully shuts the server down.
A promise that resolves once all sockets are closed.
Stops the heartbeat, disposes the cluster RoomRouter (if any), disconnects every peer with CloseReason.ServerStopping, and closes the WebSocket server (and the owned HTTP server, if one was created). Idempotent — calling it more than once is a no-op.
WebSocket signaling server that brokers WebRTC negotiation between peers grouped into rooms.
Remarks
The server accepts WebSocket connections, authenticates each one through the AuthFunction configured in SignalingServerOptions.auth, places the peer into the room named by its auth payload, and relays directed
signaland room-widebroadcastmessages between peers. It also enforces per-peer rate limiting (SignalingServerOptions.rateLimit), prunes dead connections with a ping/pong heartbeat (SignalingServerOptions.pingInterval / SignalingServerOptions.pongTimeout), and — when SignalingServerOptions.cluster is set — shards rooms across nodes via a RoomRouter, redirecting connections that reach the wrong node.It extends the core
EventEmitterand emits ServerEvent values: ServerEvent.RoomCreated, ServerEvent.RoomClosed, and ServerEvent.Error.Example