Use WSController to negotiate a new RTCPeerConnection connection with the server using WebSocket custom signaling and keep that connection open for communication.

Example

// Listener channel (no 'stream' parameter), listen to a stream without sending data
const connection = new WSController({endPoint, streamName});
connection.onOpen = stream => videoElement.srcObject = stream;

// Streamer channel (with 'stream' parameter), sends and receives media streams
const connection = new WSController({endPoint, streamName}, {stream: await navigator.mediaDevices.getUserMedia()});
connection.onOpen = stream => {}

Hierarchy

Implements

Constructors

  • Instantiate the WSController, connect to the WebSocket endpoint and call _open() to create the RTCPeerConnection.

    By default, a listener channel is negotiated. To create a streamer channel, pass a stream parameter.

    Parameters

    • connectParams: Params
    • Optional stream: MediaStream

    Returns WSController

Properties

_promise?: ((result) => void)

Type declaration

    • (result): void
    • Parameters

      • result: string | Error

      Returns void

_reportReceivedTimestamp?: number
_reportWatchdogInterval?: Timeout
log: ILog

Start a log

Param

Returns

a Log object with the levels of log to call

Accessors

  • get stream(): undefined | MediaStream
  • Media Stream description delivred from the server if we are player, or build from the local camera if we are the streamer.

    Returns undefined | MediaStream

Methods

  • Main function which creates the RTCPeerConnection, creates the offer, calls the _sip method, then set the answer and calls onOpen

    Parameters

    • Optional iceServer: RTCIceServer

    Returns void

  • Operates Session Initiation Protocol, this method implement the logic to send the SDP offer to the server and get the SDP answer in response.

    Parameters

    • offer: string

      SIP Offer

    Returns Promise<string>

    a Promise with SIP Answer as result

  • Event unsubscription

    Parameters

    • name: "open" | "close" | "playing" | "Close" | "RTPProps" | "MediaReport" | "VideoBitrate" | "Playing" | "Open" | "rtpprops" | "mediareport" | "videobitrate"

      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: "open" | "close" | "playing" | "Close" | "RTPProps" | "MediaReport" | "VideoBitrate" | "Playing" | "Open" | "rtpprops" | "mediareport" | "videobitrate"

      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 subscription only one time, once time fired it's automatically unsubscribe

    Parameters

    • name: "open" | "close" | "playing" | "Close" | "RTPProps" | "MediaReport" | "VideoBitrate" | "Playing" | "Open" | "rtpprops" | "mediareport" | "videobitrate"

      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

  • Send a generic command to control the streaming session

    Parameters

    • type: string

      type of command

    • params: object

      parameters of the command

    Returns void

  • Sets server properties for packet error (nack) and delayed packet loss (drop) for a streamer controller 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

  • Configure the audio and video track to play for a player controller

    Parameters

    • tracks: {
          audio?: number;
          video?: number;
      }
      • Optional audio?: number
      • Optional video?: number

    Returns void

Events

  • Call to distribute video bitrate informations

    Parameters

    • videoBitrate: number

      Current video bitrate

    • videoBitrateConstraint: number

      Video bitrate constraint computed by the server

    Returns void

Generated using TypeDoc