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

    Class CascadingRouter

    Assigns rooms to SFU nodes and grows per-room cascades across additional nodes on top of an SfuCluster.

    Each room gets one primary node via the cluster's placement strategy. When a room is attached again and placement resolves to a different node, that node is added as a cascade link — letting a single room span multiple SFUs (for example across regions). The router watches the cluster through a NodeFailureTracker: when a node fails or is removed, its room assignments are cleared and its cascade links dropped, emitting the corresponding detach and drop events.

    Emits CascadingRouterEvent events. Pair with an SfuBridge to apply these decisions onto a concrete media plane.

    const router = new CascadingRouter(cluster)
    router.on(CascadingRouterEvent.RoomAssigned, (roomId, node) => {
    console.log(`${roomId} -> ${node.id}`)
    })

    const primary = router.attachRoom('room-1', 'us-east')
    // A second attach that resolves elsewhere creates a cascade link:
    router.attachRoom('room-1', 'eu-west')

    router.detachRoom('room-1')

    Call CascadingRouter.dispose to detach from cluster events when the router is no longer needed.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    Methods

    • Attach a room to an SFU node, or extend it with a cascade link.

      On first attach the room is assigned a primary node and CascadingRouterEvent.RoomAssigned is emitted. On subsequent attaches that resolve to a different node, that node is added as a cascade link and CascadingRouterEvent.CascadeCreated is emitted (once per distinct node). Attaches that resolve to an already-linked node are no-ops.

      Parameters

      • roomId: string

        Identifier of the room to attach.

      • OptionalpreferredRegion: string

        Optional region hint passed to the placement strategy.

      Returns SfuNode

      The node selected for this attach (primary on first call, cascade target otherwise).

      NoAvailableNodeError when the cluster has no active node to assign.

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

      Type Parameters

      • K extends keyof CascadingRouterEvents

      Parameters

      • event: K

        The event name to emit.

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

    • Get the primary node currently assigned to a room.

      Parameters

      • roomId: string

        Identifier of the room.

      Returns SfuNode | undefined

      The primary node, or undefined if the room is not attached.

    • Get the cascade nodes (beyond the primary) currently serving a room.

      Parameters

      • roomId: string

        Identifier of the room.

      Returns SfuNode[]

      A copy of the room's cascade node list (empty if none).

    • Returns the number of listeners currently registered for event.

      Type Parameters

      • K extends keyof CascadingRouterEvents

      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 CascadingRouterEvents

      Parameters

      • event: K

        The event name the listener was registered for.

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

      Parameters

      • event: K

        The event name to listen for.

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

      Parameters

      • event: K

        The event name to listen for.

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

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

      Returns this

      This emitter, for chaining.