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

    Class SfuCluster

    Manages a set of SfuNode instances and selects nodes for rooms via a pluggable PlacementStrategy.

    The cluster can optionally reconcile its membership against an external Membership source and run periodic health checks that mark failing nodes as failed and trigger a rebalance. Placement always considers only active nodes — those that are neither failed nor draining.

    Emits SfuClusterEvent events.

    const cluster = new SfuCluster({
    placementStrategy: new LeastLoadedStrategy(),
    healthCheck: {
    intervalMs: 10_000,
    onCheck: async (id) => probe(id),
    },
    onRebalance: (nodeId, reason) => migrateRooms(nodeId, reason),
    })

    cluster.addNode(new SfuNode('sfu-eu-1', 'eu'))
    cluster.addNode(new SfuNode('sfu-eu-2', 'eu'))
    cluster.startHealthChecks()

    const node = cluster.assignNode('eu', 'room-42')

    Call SfuCluster.dispose when the cluster is no longer needed to stop membership reconciliation and health checks.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    Methods

    • Select an active node for a room using the configured placement strategy.

      Parameters

      • Optionalregion: string

        Optional preferred region for region-affinity placement.

      • Optionalkey: string

        Optional routing key (for example a room id) for deterministic strategies.

      Returns SfuNode | undefined

      The chosen node, or undefined when no active node is available.

    • Release cluster resources: stop membership reconciliation and health checks. Does not remove nodes or emit membership events.

      Returns void

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

      Type Parameters

      • K extends keyof SfuClusterEvents

      Parameters

      • event: K

        The event name to emit.

      • ...args: SfuClusterEvents[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 SfuClusterEvents

      Parameters

      • event: K

        The event name to count listeners for.

      Returns number

      The count of registered listeners (0 if none).

    • Removes a previously registered listener for event.

      Type Parameters

      • K extends keyof SfuClusterEvents

      Parameters

      • event: K

        The event name the listener was registered for.

      • listener: (...args: SfuClusterEvents[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 SfuClusterEvents

      Parameters

      • event: K

        The event name to listen for.

      • listener: (...args: SfuClusterEvents[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 SfuClusterEvents

      Parameters

      • event: K

        The event name to listen for.

      • listener: (...args: SfuClusterEvents[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 SfuClusterEvents

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

      Returns this

      This emitter, for chaining.

    • Remove a node from the cluster and detach its overload listener. Emits SfuClusterEvent.NodeRemoved when a node was removed.

      Parameters

      • id: string

        Identifier of the node to remove.

      Returns boolean

      true if a node was removed, false if no node had that id.