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

    Browser P2P mesh call over a signaling Room. Manages one PeerConnection per remote peer, wiring perfect negotiation, ICE, and track publishing so that adding a track fans it out to every peer.

    It reacts to room membership: joining peers get a new connection, leaving peers are torn down, and a RoomEvent.Refreshed triggers a full Call.restart. All observable activity is surfaced as MediaEvents.

    Intended for small mesh calls where each participant connects directly to every other participant. For many-participant rooms, use the SFU (MediaService) instead.

    const stream = await getUserMedia({ audio: true, video: true })
    const call = new Call(room, { stream, iceServers })

    call.on(MediaEvent.RemoteStream, (peerId, remoteStream) => {
    attachToVideoElement(peerId, remoteStream)
    })
    call.on(MediaEvent.RemoteStreamRemoved, (peerId) => detach(peerId))

    call.start()
    // later
    call.close()

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Publishes a local track to every peer connection and registers it so it is also added to peers that join later. Emits MediaEvent.TrackPublished.

      Parameters

      • track: MediaStreamTrack

        The local media track to send.

      • stream: MediaStream

        The stream the track belongs to.

      • Optionalopts: { contentHint?: string; maxBitrate?: number }

        Optional per-track overrides.

        • OptionalcontentHint?: string

          Encoder content hint set on the track (e.g. "motion", "detail").

        • OptionalmaxBitrate?: number

          Maximum send bitrate in bits per second; falls back to CallOptions.maxBitrate.

      Returns void

    • Permanently closes the call: stops active-speaker detection, clears local tracks, detaches room listeners, and closes every peer connection. Idempotent; a closed call cannot be restarted with Call.start.

      Returns void

    • Opens a data channel to a specific peer.

      Parameters

      • peerId: string

        The target peer's id.

      • label: string

        Data channel label.

      • Optionalopts: RTCDataChannelInit

        Optional data channel configuration.

      Returns RTCDataChannel | undefined

      The created data channel, or undefined if no connection to that peer exists.

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

      Type Parameters

      • K extends keyof CallEvents

      Parameters

      • event: K

        The event name to emit.

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

    • Collects WebRTC statistics for one or all peer connections.

      Parameters

      • OptionalpeerId: string

        If given, returns stats for just that peer; otherwise for all connected peers.

      Returns Promise<Map<string, RTCStatsReport>>

      A map of peer id to its RTCStatsReport.

    • Returns boolean

      Whether the local audio tracks are currently muted.

    • Returns boolean

      Whether the local video tracks are currently muted.

    • Returns the number of listeners currently registered for event.

      Type Parameters

      • K extends keyof CallEvents

      Parameters

      • event: K

        The event name to count listeners for.

      Returns number

      The count of registered listeners (0 if none).

    • Disables all local audio tracks (mutes the microphone) without renegotiating.

      Returns void

    • Disables all local video tracks (stops sending camera frames) without renegotiating.

      Returns void

    • Removes a previously registered listener for event.

      Type Parameters

      • K extends keyof CallEvents

      Parameters

      • event: K

        The event name the listener was registered for.

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

      Parameters

      • event: K

        The event name to listen for.

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

      Parameters

      • event: K

        The event name to listen for.

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

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

      Returns this

      This emitter, for chaining.

    • Replaces a published track with a new one on every peer connection without renegotiation (e.g. switching cameras). Updates the local track registry.

      Parameters

      Returns Promise<void>

    • Tears down all connections and room listeners, then starts fresh. Local published tracks are preserved and re-added to the new connections. Invoked automatically when the room signals RoomEvent.Refreshed.

      Returns void

    • Starts the call: creates connections to all current peers and subscribes to room membership and signaling events. Idempotent, and a no-op once the call has been closed.

      Returns void

    • Starts polling remote audio levels and emitting MediaEvent.ActiveSpeaker when the dominant speaker changes. Idempotent.

      Parameters

      • intervalMs: number = 1000

        Poll interval in milliseconds.

      Returns void

      1000
      
    • Stops active-speaker detection and releases its resources. Idempotent.

      Returns void