Stable unique identifier for the node.
Region the node resides in.
Optional capacity and logger overrides.
ReadonlycapacityMaximum load the node can carry before it is considered overloaded.
ReadonlyidStable unique identifier for this node.
ReadonlyregionRegion the node resides in; used for region-affinity placement.
Whether the node is currently draining its rooms.
Whether the node is currently marked failed.
Whether reported load has reached or exceeded SfuNode.capacity.
Most recently reported load value.
Number of rooms currently tracked on this node.
Gracefully drain the node.
Marks the node draining (so placement stops selecting it), stops stats
collection, and emits SfuNodeEvent.Draining. Resolves once all
tracked rooms have been untracked, or once timeoutMs elapses — whichever
comes first — after which it clears the draining flag and emits
SfuNodeEvent.Drained. Concurrent calls after the first are no-ops.
Maximum time to wait for rooms to drain before forcing completion.
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 the number of listeners currently registered for event.
The event name to count listeners for.
The count of registered listeners (0 if none).
Mark the node as failed.
Stops any running stats collection, resolves a pending drain if one is in progress, and emits SfuNodeEvent.Failed. Idempotent — a no-op if the node is already failed.
Clear the failed state of a previously failed node.
Emits SfuNodeEvent.Recovered. Idempotent — a no-op if the node is not currently failed.
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 SfuNodeEventsThe event name to clear; if omitted, listeners for every event are removed.
This emitter, for chaining.
Report the node's current load.
Emits SfuNodeEvent.Load on every call, and additionally emits SfuNodeEvent.Overloaded the first time load crosses into the overloaded range.
The current load value.
Begin periodically sampling network statistics and emitting bandwidth quality estimates.
Any previously running collector is stopped first. On each interval the
collector calls getStats, feeds the sample to estimator, and emits
SfuNodeEvent.BandwidthEstimate with the resulting quality tier.
Estimator that maps a stats sample to a BandwidthQuality.
Async provider of the latest network statistics sample.
Sampling interval in milliseconds.
Stop the background stats collector if one is running.
Record that roomId is being served by this node.
The room to track.
Stop tracking roomId on this node.
If the node is draining and this was its last room, any pending drain resolves.
The room to untrack.
A single SFU (Selective Forwarding Unit) instance within a cluster.
Tracks the node's identity, region, capacity, live load, and lifecycle state (failed, draining), and can run a background stats collector that emits BandwidthQuality estimates. Consumed by SfuCluster, CascadingRouter, and CascadeTree to make placement and fan-out decisions.
Emits SfuNodeEvent events.