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

    Function planCascadeTree

    • Compute a balanced cascade fan-out tree that distributes a room's media to a large viewer population across many SFU nodes.

      Starting from the origin, nodes are drawn from availableNodeIds and attached tier by tier, each parent taking up to fanout children, until the current tier can seat viewerCount viewers (at viewersPerNode each) or the node pool is exhausted. Leaf nodes are then filled with viewer slots up to their per-node capacity. This shallow, wide tree keeps forwarding hops low while scaling to very large audiences (for example a live stream to 1M viewers).

      Parameters

      • params: {
            availableNodeIds: string[];
            capacityOf?: (nodeId: string) => number;
            fanout: number;
            originId: string;
            viewerCount: number;
            viewersPerNode: number;
        }

        Planning inputs.

        • availableNodeIds: string[]

          Candidate node ids to draw from (the origin is excluded automatically).

        • OptionalcapacityOf?: (nodeId: string) => number

          Optional per-node capacity lookup overriding viewersPerNode for leaf seating.

        • fanout: number

          Maximum children per node; must be >= 1.

        • originId: string

          Identifier of the origin node (tree root).

        • viewerCount: number

          Total number of viewers to seat.

        • viewersPerNode: number

          Default viewer capacity per node (and the origin's assumed capacity); must be >= 1.

      Returns CascadePlan

      The computed CascadePlan, including any unmetViewers shortfall.

      InvalidArgumentError when fanout < 1 or viewersPerNode < 1.

      const plan = planCascadeTree({
      originId: 'origin',
      viewerCount: 1_000_000,
      fanout: 8,
      viewersPerNode: 1000,
      availableNodeIds: relayIds,
      })
      console.log(plan.tiers, plan.servedViewers, plan.unmetViewers)