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

    Interface IController

    IController is a controller interface extending a stream connector with the capability of sending and receiving commands with the server.

    This interface can serve the both roles: player or streamer.

    interface IController {
        closed: boolean;
        codecs: Set<string>;
        log: ILog;
        opened: boolean;
        stream?: MediaStream;
        streamName: string;
        close(error?: ConnectorError): void;
        connectionInfos(cacheDuration?: number): Promise<ConnectionInfos>;
        off(
            name:
                | "close"
                | "Close"
                | "RTPProps"
                | "MediaReport"
                | "VideoBitrate"
                | "Playing"
                | "Open"
                | "rtpprops"
                | "mediareport"
                | "videobitrate"
                | "playing"
                | "open",
            event: Function,
        ): boolean;
        on(
            name:
                | "close"
                | "Close"
                | "RTPProps"
                | "MediaReport"
                | "VideoBitrate"
                | "Playing"
                | "Open"
                | "rtpprops"
                | "mediareport"
                | "videobitrate"
                | "playing"
                | "open",
            event: Function,
            options?: { signal?: AbortSignal },
        ): void;
        once(
            name:
                | "close"
                | "Close"
                | "RTPProps"
                | "MediaReport"
                | "VideoBitrate"
                | "Playing"
                | "Open"
                | "rtpprops"
                | "mediareport"
                | "videobitrate"
                | "playing"
                | "open",
            event: Function,
            options?: { signal?: AbortSignal },
        ): void;
        onClose(error?: ConnectorError): void;
        onMediaReport(mediaReport: MediaReport): void;
        onOpen(stream: MediaStream): void;
        onPlaying(playingInfos: PlayingInfos): void;
        onRTPProps(rtpProps: RTPProps): void;
        onVideoBitrate(videoBitrate: number, videoBitrateConstraint: number): void;
        replaceTrack(
            kind: "audio" | "video",
            track: MediaStreamTrack | null,
        ): Promise<void>;
        send(type: string, params: object): void;
        setRTPProps(nack?: number, drop?: number): void;
        setTracks(tracks: { audio?: number; video?: number }): void;
        setVideoBitrate(value: number): void;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    closed: boolean

    True when connector is closed, in other words when onClose event is fired

    codecs: Set<string>

    Indicate codecs supported, should be set before than onOpen happen

    log: ILog

    Start a log

    a Log object with the levels of log to call

    opened: boolean

    True when connector is opened, in other words when onOpen event is fired

    stream?: MediaStream

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

    streamName: string

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

    Methods

    • 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

    • Parameters

      • kind: "audio" | "video"

        'video' or 'audio' to replace the track of the given kind

      • track: MediaStreamTrack | null

      Returns Promise<void>

      Promise that resolves when the track is replaced

      Error if the kind is not supported or if the operation fails

      This method allows to replace the current track of the given kind with a new one. If the track is null, it will remove the current track of that kind.

    • Send a generic command to control the streaming session

      Parameters

      • type: string

        type of command

      • params: object

        parameters of the command

      Returns void

      controller.send('video_bitrate', {video_bitrate: 0});
      
    • 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 }
        • Optionalaudio?: number

          Audio track

        • Optionalvideo?: number

          Video track

      Returns void

    • Configure the video bitrate on the server side for a streamer controller

      Parameters

      • value: number

        video bitrate in bps

      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