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.

Example

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

Constructors

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

    Parameters

    • Optional Connector: (new (connectParams, stream) => IConnector)

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

        • new (connectParams, stream): IConnector
        • Parameters

          • connectParams: Params
          • stream: MediaStream

          Returns IConnector

    Returns Streamer

Properties

Connector?: (new (connectParams, stream) => IConnector)

Type declaration

    • new (connectParams, stream): IConnector
    • Connector class to use for signaling, can be determined automatically from URL in the start() method

      Parameters

      • connectParams: Params
      • stream: MediaStream

      Returns IConnector

_connector?: IConnector
_controller?: IController
_mediaReport?: MediaReport
_rtpProps?: RTPProps
_videoBitrate?: number
_videoBitrateConstraint?: number
_videoBitrateFixed: boolean
log: ILog

Start a log

Param

Returns

a Log object with the levels of log to call

Accessors

  • get controller(): undefined | IController
  • 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 undefined | IController

  • get streamName(): string
  • Stream name, for example as+bc3f535f-37f3-458b-8171-b4c5e77a6137

    Returns string

  • get videoBitrate(): undefined | number
  • Video bitrate configured by the server, can be undefined on start or when there is no controllable connector

    Returns undefined | number

    Note

    Use connectionInfos to get the current precise audio or video bitrate

  • set videoBitrate(value): 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: undefined | number

    Returns void

  • get videoBitrateConstraint(): undefined | number
  • Video bitrate constraint configured by the server, can be undefined on start or when there is no controllable connector

    Returns undefined | number

    Note

    Use connectionInfos to get the current precise audio or video bitrate

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: "stop" | "start" | "RTPProps" | "MediaReport" | "VideoBitrate" | "rtpprops" | "mediareport" | "videobitrate" | "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: "stop" | "start" | "RTPProps" | "MediaReport" | "VideoBitrate" | "rtpprops" | "mediareport" | "videobitrate" | "Start" | "Stop"

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

    • event: Function

      Subscriber Function

    • Optional options: {
          signal?: AbortSignal;
      }
      • Optional signal?: AbortSignal

        Optional AbortSignal to stop this or multiple subscriptions in same time

    Returns void

  • Event fired to report media statistics

    Parameters

    Returns void

  • Event fired when an RTP setting change occurs

    Parameters

    Returns void

  • Event fired when a video bitrate change occurs

    Parameters

    • videoBitrate: number
    • videoBitrateConstraint: number

    Returns void

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

    Parameters

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

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

    • event: Function

      Subscriber Function

    • Optional options: {
          signal?: AbortSignal;
      }
      • Optional signal?: AbortSignal

    Returns void

  • 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

    • Optional nack: number

      Waiting period before declaring a packet error

    • Optional drop: number

      Waiting period before considering delayed packets as lost

    Returns void

  • 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: undefined | ABRParams | ABRAbstract = {}

      Adaptive bitrate implementation or ABRParams to configure the default implementation

    Returns void

  • Stop streaming the stream

    Parameters

    • Optional error: StreamerError

      error description on an improper stop

    Returns void

Events

  • Event fired when the stream has started

    Parameters

    • stream: MediaStream

    Returns void

  • Event fired when the stream has stopped

    Parameters

    • Optional error: StreamerError

      error description on an improper stop

    Returns void

Generated using TypeDoc