RTCForge API Reference v1.1.1
    Preparing search index...

    Class SfuNode

    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.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    capacity: number

    Maximum load the node can carry before it is considered overloaded.

    id: string

    Stable unique identifier for this node.

    region: string

    Region the node resides in; used for region-affinity placement.

    Accessors

    Methods

    • 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.

      Parameters

      • timeoutMs: number = 30_000

        Maximum time to wait for rooms to drain before forcing completion.

      Returns Promise<void>

      30000
      
    • Synchronously invokes every listener registered for event, in registration order.

      Type Parameters

      • K extends keyof SfuNodeEvents

      Parameters

      • event: K

        The event name to emit.

      • ...args: SfuNodeEvents[K]

        The argument tuple to pass to each listener, matching Events[event].

      Returns boolean

      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.

      Type Parameters

      • K extends keyof SfuNodeEvents

      Parameters

      • event: K

        The event name to count listeners for.

      Returns number

      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.

      Returns void

    • Removes a previously registered listener for event.

      Type Parameters

      • K extends keyof SfuNodeEvents

      Parameters

      • event: K

        The event name the listener was registered for.

      • listener: (...args: SfuNodeEvents[K]) => void

        The exact function reference passed to on or once.

      Returns this

      This emitter, for chaining.

      If the listener is not currently registered, this is a no-op. Only the first matching registration is removed.

    • Registers a listener that is invoked every time event is emitted.

      Type Parameters

      • K extends keyof SfuNodeEvents

      Parameters

      • event: K

        The event name to listen for.

      • listener: (...args: SfuNodeEvents[K]) => void

        Callback invoked with the event's argument tuple.

      Returns this

      This emitter, for chaining.

    • Registers a listener that is invoked at most once: it is removed automatically before being called the first time event is emitted.

      Type Parameters

      • K extends keyof SfuNodeEvents

      Parameters

      • event: K

        The event name to listen for.

      • listener: (...args: SfuNodeEvents[K]) => void

        Callback invoked with the event's argument tuple on the next emission.

      Returns this

      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.

      Parameters

      • Optionalevent: keyof SfuNodeEvents

        The event name to clear; if omitted, listeners for every event are removed.

      Returns this

      This emitter, for chaining.

    • 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.

      Parameters

      • estimator: BandwidthEstimator

        Estimator that maps a stats sample to a BandwidthQuality.

      • getStats: () => Promise<NetworkStats>

        Async provider of the latest network statistics sample.

      • intervalMs: number = 5000

        Sampling interval in milliseconds.

      Returns void

      5000
      
    • Record that roomId is being served by this node.

      Parameters

      • roomId: string

        The room to track.

      Returns void

    • Stop tracking roomId on this node.

      If the node is draining and this was its last room, any pending drain resolves.

      Parameters

      • roomId: string

        The room to untrack.

      Returns void