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

    Class Player

    Use Player to start playing a WebRTS stream.

    You can implement and use a custom Source by passing it as the second argument in the constructor. If not provided, Player.start will attempt to determine the protocol from Connect.Params.endPoint to instantiate the corresponding Source.registerClass or fall back to the default HTTPAdaptiveSource.

    You can initialize tracks selection by playing with onMetadata

    const player = new Player(videoElement);
    // const player = new Player(videoElement, MySource);
    player.onStart = () => {
    console.log('start playing');
    }
    player.onStop = _ => {
    console.log('stop playing');
    }

    // optional : set initial video track to the best track (by default take the middle rendition)
    player.onMetadata = (metadata) => ({ video: metadata.videoTracks[0].id });
    // optional : fix video track to the best track and disable MBR
    player.onMetadata = (metadata) => player.videoTrack = metadata.videoTracks[0].id;

    // start playback
    player.start({
    endPoint: <endPoint>
    });
    ...
    // stop playback
    player.stop();

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    • Constructs a new Player instance to render on the HTMLVideoElement passed in first argument, with an optionally Source to custom how getting the stream.

      This doesn't start the playback, you must call Player.start method

      Parameters

      • video: HTMLVideoElement

        HTMLVideoElement object to render the video

      • OptionalSourceClass: new (playing: IPlaying, params: Params) => Source

        Optional Source logic to use, by default it uses HTTPAdaptiveSource unless Connect.Params.endPoint begin with ws:// see Player.start

      Returns Player

      // Default build
      const player = new Player(video);

      // Build with custom source implementation
      const player = new Player(MySource);

    Properties

    log: ILog

    Start a log

    a Log object with the levels of log to call

    Accessors

    • get audioByteRate(): number

      Gets the audio byte rate in bytes per second, include only the audio payload data.

      Returns number

    • get audioPerSecond(): number

      Get the number of audio sample per second currently decoding

      Returns number

    • get audioTrack(): number | undefined

      Index of the audio track, can be undefined if player is not playing

      Returns number | undefined

    • set audioTrack(idx: number | undefined): void

      Sets the current audio track to the index provided, must be set after starting. It disables MBR, set it to undefined to reactivate MBR.

      Parameters

      • idx: number | undefined

      Returns void

    • get bufferAmount(): number

      Gets the current playback buffer duration in milliseconds

      Returns number

    • get bufferLimitHigh(): number

      Gets the high-buffer threshold for BufferState.HIGH in milliseconds

      Returns number

    • set bufferLimitHigh(value: number): void

      Set the high-buffer threshold for BufferState.HIGH in milliseconds

      Parameters

      • value: number

      Returns void

    • get bufferLimitLow(): number

      Gets the low-buffer threshold for BufferState.LOW in milliseconds

      Returns number

    • set bufferLimitLow(value: number): void

      Set the low‐buffer threshold for BufferState.LOW in milliseconds

      Parameters

      • value: number

      Returns void

    • get bufferLimitMiddle(): number

      Gets the target (middle) buffer size in milliseconds. Latency control mechanisms will try to drive the buffer toward this value.

      Returns number

    • get cmcdSid(): string

      The CMCD session ID

      Returns string

    • set cmcdSid(value: string | undefined): void

      Set the CMCD session ID, if undefined reset to empty string

      Parameters

      • value: string | undefined

      Returns void

    • get currentTime(): number

      Gets the current playback time in seconds

      Returns number

    • get dataByteRate(): number

      Gets the data byte rate in bytes per second, include messages and other non-media payload data like container overhead.

      Returns number

    • get dataTrack(): Set<number> | undefined

      Index of the data track being received, can be undefined if the player is not playing

      Returns Set<number> | undefined

    • set dataTrack(idx: number | Set<number> | number[] | undefined): void

      Select a or multiple data track to the index provided, must be set after starting. When set to undefined it selects all data tracks available.

      Parameters

      • idx: number | Set<number> | number[] | undefined

      Returns void

    • get endTime(): number

      Gets the playback end time in seconds

      Returns number

    • get latency(): number | undefined

      Gets an estimation of playback latency in milliseconds, Computed as the difference between the estimated live time and the current playback time.

      Returns number | undefined

    • get passthroughCMAF(): boolean | undefined

      Source is CMAF and passthrough it to MSE, it's a debugging mode activable when you set Connect.Params.mediaExt to 'cmaf'

      Returns boolean | undefined

    • get paused(): boolean

      Returns true if player is paused

      Returns boolean

    • set paused(value: boolean): void

      Enable or disable player's pause

      Parameters

      • value: boolean

      Returns void

    • get playbackRate(): number

      Gets the current playback rate. A value of 1.0 represents real-time playback.

      Returns number

    • get playbackSpeed(): number

      Gets the effective playback speed. A value of 1.0 represents real-time playback.

      Returns number

    • get recvByteRate(): number

      Gets the current receive byte rate including audio, video and data channels

      Returns number

    • get reliable(): boolean

      Gets whether playback is reliable By default is false while playback is in an unreliable mode with frame skipping enabled, otherwise can returns true when configured to not tolerate any frame loss

      Returns boolean

    • set reliable(value: boolean): void

      Sets whether playback should be treated as reliable. When false, playback operates in an unreliable mode with frame skipping enabled; when true, frame skipping is not tolerated and reliable mode is enforced.

      Parameters

      • value: boolean

      Returns void

    • get signal(): AbortSignal

      Gets an AbortSignal useful for subscribing to playback stop events.

      Returns AbortSignal

    • get startTime(): number

      Gets the playback start time in seconds

      Returns number

    • get tracksCombinable(): boolean | undefined

      Indicates whether tracks can be combined in the same request, by default tracks are combinable to optimize the number of requests

      Returns boolean | undefined

    • set tracksCombinable(value: boolean): void

      Set whether tracks can be combined in the same request, by default tracks are combinable to optimize the number of requests

      Parameters

      • value: boolean

      Returns void

    • get trackSelectable(): boolean | undefined

      Returns true if manual track selection is supported by the source implementation, can also returns undefined if player is not running

      Returns boolean | undefined

    • get videoByteRate(): number

      Gets the video byte rate in bytes per second, include only the video payload data.

      Returns number

    • get videoPerSecond(): number

      Get the number of video frame per second currently decoding

      Returns number

    • get videoTrack(): number | undefined

      Index of the video track, can be undefined if player is not playing

      Returns number | undefined

    • set videoTrack(idx: number | undefined): void

      Sets the current video track to the index provided, must be set after starting. It disables MBR, set it to undefined to reactivate MBR.

      Parameters

      • idx: number | undefined

      Returns void

    Methods

    • Moves the playback head as close as possible to the live point, while respecting the configured bufferLimitLow and bufferLimitHigh buffer thresholds.

      Parameters

      • Optionalreason: string

        add a log reason to display to explain this goLive call

      Returns void

    • Event unsubscription

      Parameters

      • name:
            | "data"
            | "Data"
            | "metadata"
            | "stop"
            | "Metadata"
            | "TrackChange"
            | "FinalizeRequest"
            | "trackchange"
            | "finalizerequest"
            | "BufferState"
            | "BufferChange"
            | "Stall"
            | "AudioSkipping"
            | "VideoSkipping"
            | "bufferstate"
            | "bufferchange"
            | "stall"
            | "audioskipping"
            | "videoskipping"
            | "start"
            | "Start"
            | "Stop"
            | "AudioAppended"
            | "VideoAppended"
            | "MediaKeys"
            | "audioappended"
            | "videoappended"
            | "mediakeys"

        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:
            | "data"
            | "Data"
            | "metadata"
            | "stop"
            | "Metadata"
            | "TrackChange"
            | "FinalizeRequest"
            | "trackchange"
            | "finalizerequest"
            | "BufferState"
            | "BufferChange"
            | "Stall"
            | "AudioSkipping"
            | "VideoSkipping"
            | "bufferstate"
            | "bufferchange"
            | "stall"
            | "audioskipping"
            | "videoskipping"
            | "start"
            | "Start"
            | "Stop"
            | "AudioAppended"
            | "VideoAppended"
            | "MediaKeys"
            | "audioappended"
            | "videoappended"
            | "mediakeys"

        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:
            | "data"
            | "Data"
            | "metadata"
            | "stop"
            | "Metadata"
            | "TrackChange"
            | "FinalizeRequest"
            | "trackchange"
            | "finalizerequest"
            | "BufferState"
            | "BufferChange"
            | "Stall"
            | "AudioSkipping"
            | "VideoSkipping"
            | "bufferstate"
            | "bufferchange"
            | "stall"
            | "audioskipping"
            | "videoskipping"
            | "start"
            | "Start"
            | "Stop"
            | "AudioAppended"
            | "VideoAppended"
            | "MediaKeys"
            | "audioappended"
            | "videoappended"
            | "mediakeys"

        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

    • Starts playing the stream

      If a MediaKeys engine is already running, it means that the previous playback has not been properly released, so the player stops and reports a PlayerError error to avoid unexpected behavior.

      Parameters

      • params: Params

        Connection parameters Connect.Params

      • OptionalidleTimeout: number

        idle timeout, default value is around 14s. It sets the timeout error in the absence of connection activity or data fetching, you can tune it to implement your reliable and consistent fallback mechanism.

      Returns void

      player.start({
      endPoint: <endPoint>
      });
    • Stops playback. If an error is provided, it is treated as an improper stop and propagated to onStop.

      Parameters

      • Optionalerror: PlayerError

        optional error describing why playback stopped improperly

      Returns void

    Events

    • Event fire when audio data are appended to media source, basically here to debug MSE ingestion

      Parameters

      • data: Uint8Array

      Returns void

    • Event fired when data is received in the stream

      Parameters

      • track: number
      • time: number
      • duration: number
      • data: Uint8Array

      Returns void

    • Fired when the URL and headers can be finalized before sending the request to the server.

      Parameters

      • url: URL

        the request URL to finalize or modify if needed

      • headers: Headers

        the request headers to adjust if needed

      Returns void

    • Event fired when MediaKeys state changes if contentProtection is found in the metadata

      MediaKeys support can be disabled by setting no contentProtection in the player parameters

      Parameters

      • OptionalmediaKeysEngine: MediaKeysEngine

        The MediaKeys engine instance when ready, undefined when released

      Returns void

    • Event fired when metadata is available in the stream.

      On the first occurrence, the optional return value allows specifying which track to use when starting the stream. By default, the middle-quality track is selected.

      Note that this differs from using videoTrack or audioTrack, where a specific track is fixed, which disables any Adaptive Bitrate algorithm.

      Parameters

      • metadata: Metadata

        The metadata received from the stream.

      Returns void | Tracks

      Optional tracks to use for initializing the stream.

    • Event fired when streaming starts

      Returns void

    • Fire on a track change

      Parameters

      • audioTrack: number
      • videoTrack: number
      • dataTrack: Set<number>

      Returns void

    • Event fire when video data are appended to media source, basically here to debug MSE ingestion

      Parameters

      • data: Uint8Array

      Returns void