@ceeblue/webrtc-client
    Preparing search index...

    Class Streamer

    Use Streamer to broadcast to a WebRTC server.

    You can use a controllable version using a WSController as connector, or change it to use a HTTPConnector (HTTP WHIP). By default it uses a WSController excepting if on Streamer.start you use a Connect.Params.endPoint prefixed with a http:// protocol. With a controllable connector you can change video bitrate during the streaming, what is not possible with a HTTP(WHIP) connector.

    const streamer = new Streamer();
    // const streamer = new Streamer(isWHEP ? HTTPConnector : WSController);
    streamer.onStart = stream => {
    console.log('start streaming');
    }
    streamer.onStop = _ => {
    console.log('stop streaming');
    }
    navigator.mediaDevices
    .getUserMedia({ audio: true, video: true })
    .then(stream => {
    streamer.start(stream, {
    endPoint: address, // if address is prefixed by `http://` it uses a HTTPConnector (HTTP-WHIP) if Streamer is build without contructor argument
    streamName: 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'
    });
    ...
    streamer.stop();
    });

    Hierarchy (View Summary)

    Index

    Constructors

    • Constructs a new Streamer instance, optionally with a custom connector This doesn't start the broadcast, you must call start() method

      Parameters

      • OptionalConnector: new (connectParams: Params, stream: MediaStream) => IConnector

        Connector class to use for signaling, can be determined automatically from URL in the start() method

      Returns Streamer

    Properties

    log: ILog

    Start a log

    a Log object with the levels of log to call

    Accessors

    • get audioTrack(): MediaStreamTrack | null

      The current audio track of the stream, or null if audio track is disabled.

      Returns MediaStreamTrack | null

    • get controller(): IController | undefined

      Returns the IController instance when starting with a connector with controllable ability, or undefined if stream is not starting or stream is not controllable.

      Returns IController | undefined

    • get streamName(): string

      Stream name, for example as+bc3f535f-37f3-458b-8171-b4c5e77a6137

      Returns string

    • get videoBitrate(): number | undefined

      Video bitrate configured by the server, can be undefined on start or when there is no controllable connector

      Returns number | undefined

      Use connectionInfos to get the current precise audio or video bitrate

    • set videoBitrate(value: number | undefined): void

      Configure the video bitrate from the server, possible only if your Streamer instance is built with a controllable connector Set undefined to remove this configuration

      Parameters

      • value: number | undefined

      Returns void

    • get videoBitrateConstraint(): number | undefined

      Video bitrate constraint configured by the server, can be undefined on start or when there is no controllable connector

      Returns number | undefined

      Use connectionInfos to get the current precise audio or video bitrate

    • get videoTrack(): MediaStreamTrack | null

      The current video track of the stream, or null if video track is disabled.

      Returns MediaStreamTrack | null

    Methods

    • Returns connection info, such as round trip time, requests sent and received, bytes sent and received, and bitrates NOTE: This call is resource-intensive for the CPU.

      Returns Promise<ConnectionInfos>

      A promise for a ConnectionInfos

    • Event unsubscription

      Parameters

      • name:
            | "RTPProps"
            | "MediaReport"
            | "VideoBitrate"
            | "rtpprops"
            | "mediareport"
            | "videobitrate"
            | "start"
            | "stop"
            | "Start"
            | "Stop"

        Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)

      • event: Function

        Unsubscriber Function, must be the one passed to on or once subscription methods

      Returns boolean

    • Event subscription

      Parameters

      • name:
            | "RTPProps"
            | "MediaReport"
            | "VideoBitrate"
            | "rtpprops"
            | "mediareport"
            | "videobitrate"
            | "start"
            | "stop"
            | "Start"
            | "Stop"

        Name of event without the on prefix (ex: log to onLog event declared)

      • event: Function

        Subscriber Function

      • Optionaloptions: { signal?: AbortSignal }
        • Optionalsignal?: AbortSignal

          Optional AbortSignal to stop this or multiple subscriptions in same time

      Returns void

    • Event subscription only one time, once time fired it's automatically unsubscribe

      Parameters

      • name:
            | "RTPProps"
            | "MediaReport"
            | "VideoBitrate"
            | "rtpprops"
            | "mediareport"
            | "videobitrate"
            | "start"
            | "stop"
            | "Start"
            | "Stop"

        Name of event without the on prefix (ex: log to onLog event declared)

      • event: Function

        Subscriber Function

      • Optionaloptions: { signal?: AbortSignal }
        • Optionalsignal?: AbortSignal

          Optional AbortSignal to stop this or multiple subscriptions in same time

      Returns void

    • Event fired when a video bitrate change occurs

      Parameters

      • videoBitrate: number
      • videoBitrateConstraint: number

      Returns void

    • Replace the audio track while streaming.

      Parameters

      • track: MediaStreamTrack | null

        MediaStreamTrack to set as audio track, or null to remove the audio track

      Returns Promise<void>

      A promise that resolves when the track is set or removed

    • Sets server properties for packet error (nack) and delayed packet loss (drop) and fires an onRTPProps event if changed successfully. NOTE: Method can also retrieve current server values if called without arguments.

      Parameters

      • Optionalnack: number

        Waiting period before declaring a packet error

      • Optionaldrop: number

        Waiting period before considering delayed packets as lost

      Returns void

    • Replace the video track while streaming.

      Parameters

      • track: MediaStreamTrack | null

        MediaStreamTrack to set as video track, or null to remove the video track

      Returns Promise<void>

      A promise that resolves when the track is set or removed

    • Starts broadcasting the stream The connector is determined automatically from Connect.Params.endPoint if not forced in the constructor.

      The adaptiveBitrate option can take three different types of value:

      • A ABRParams parameters to configure the default ABRLinear implementation
      • undefined to disable ABR management
      • Use a custom ABRAbstract implementation instance

      Parameters

      • stream: MediaStream

        MediaStream instance to stream

      • params: Params

        Connection parameters

      • adaptiveBitrate: ABRParams | ABRAbstract | undefined = {}

        Adaptive bitrate implementation or ABRParams to configure the default implementation

      Returns void

    Events

    • Event fired when the stream has started

      Parameters

      • stream: MediaStream

      Returns void