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

    Class WSController

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

    // 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 (View Summary)

    Implements

    Index

    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
      • Optionalstream: MediaStream

      Returns WSController

    Properties

    log: ILog

    Start a log

    a Log object with the levels of log to call

    Accessors

    • get stream(): MediaStream | undefined

      Media Stream description delivred from the server if we are player, or build from the local camera if we are the streamer.

      Returns MediaStream | undefined

    Methods

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

      Parameters

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

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

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

        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

    • Hot-swap a track on the existing RTCPeerConnection without renegotiation.

      Parameters

      • kind: "audio" | "video"

        'audio' | 'video'

      • track: MediaStreamTrack | null

        A MediaStreamTrack to send, or null to stop sending that kind.

      Returns Promise<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

      • Optionalnack: number

        Waiting period before declaring a packet error

      • Optionaldrop: 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 }

      Returns void

    Events

    • Call when connector is open

      Parameters

      • stream: MediaStream

        MediaStream description provided from the server if we are the player, or build from the local camera if we are the streamer.

      Returns void

    • Call to distribute video bitrate informations

      Parameters

      • videoBitrate: number

        Current video bitrate

      • videoBitrateConstraint: number

        Video bitrate constraint computed by the server

      Returns void