WebSocket Streaming

Hierarchy (view full)

Constructors

Properties

_rtt: number
log: ILog

Start a log

Param: args

Returns

a Log object with the levels of log to call

Accessors

  • get audioPerSecond(): number
  • Get the number of audio frame per second currently decoding

    Returns number

  • get audioSelected(): undefined | number
  • Index of the manual audio selection, undefined indicates automatic mode and -1 disable manually the track

    Returns undefined | number

  • get audioTrack(): undefined | number
  • Index of the effective audio track, can be undefined on start and -1 means track disabled

    Returns undefined | number

  • set audioTrack(idx): void
  • Select a audio track to the index provided, or indicates automatic with undefined

    Parameters

    • idx: undefined | number

    Returns void

  • get closed(): boolean
  • True when source is closed

    Returns boolean

  • get cmcdSid(): string
  • The CMCD session ID

    Returns string

  • set cmcdSid(value): void
  • Set the CMCD session ID, if undefined reset to empty string

    Parameters

    • value: undefined | string

    Returns void

  • get passthroughCMAF(): boolean
  • Source is CMAF and passthrough it to MSE, it's a debugging mode activable when you set Connect.Params.mediaExt to 'cmaf'

    Returns boolean

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

    Returns string

  • get trackSelectable(): boolean
  • Returns true if manual track selection is supported by the source implementation

    Returns boolean

  • get videoPerSecond(): number
  • Get the number of video sample per second currently decoding

    Returns number

  • get videoSelected(): undefined | number
  • Index of the manual video selection, undefined indicates automatic mode and -1 disable manually the track

    Returns undefined | number

  • get videoTrack(): undefined | number
  • Index of the effective video track, can be undefined on start and -1 means track disabled

    Returns undefined | number

  • set videoTrack(idx): void
  • Selects a video track based on the provided index, or enables automatic selection if set to undefined.

    Parameters

    • idx: undefined | number

    Returns void

    Remarks

    Manually setting a track disables any Adaptive Bitrate algorithm.

Methods

  • Create a Reader usable to feed the Source and matching mediaExt Can throw an exception if no demuxer is found for the related media extension

    Parameters

    • params: {
          isStream: boolean;
      } = ...
      • isStream: boolean

    Returns Reader

  • Fetches a resource in a compliant way by invoking finalizeRequest during preparation.

    Parameters

    • url: URL

      the URL to fetch

    • Optional init: RequestInit

      optional fetch configuration

    Returns Promise<Response & {
        error?: string;
    }>

    the fetched response

  • Fetch a media object with CMCD if enabled

    Parameters

    • url: URL

      full URL of the media object

    • type: Media.Type
    • options: RequestInit = {}

    Returns Promise<Response & {
        error?: string;
    }>

  • Fetches a resource and measures the RTT (round-trip time) in a compliant way by invoking finalizeRequest during preparation.

    Parameters

    • url: URL

      the URL to fetch

    • Optional init: RequestInit

      optional fetch configuration

    Returns Promise<Response & {
        error?: string;
        rtt: number;
    }>

    the fetched response (including RTT metadata)

  • Prepares a request, exposing the user-interception onFinalizeRequest to modify it if needed.

    Parameters

    • url: URL

      URL to adjust if need

    • headers: Headers

      HTTP headers to tweak as desired

    Returns URL

    the finalized URL

  • Parameters

    • type: Media.Type
    • trackId: number
    • currentTime: number
    • sample: {
          duration?: number;
          time: number;
      }
      • Optional duration?: number
      • time: number

    Returns number

  • Event unsubscription

    Parameters

    • name: "data" | "sample" | "metadata" | "close" | "Data" | "Metadata" | "Close" | "TrackChange" | "Sample" | "FinalizeRequest" | "trackchange" | "finalizerequest"

      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" | "sample" | "metadata" | "close" | "Data" | "Metadata" | "Close" | "TrackChange" | "Sample" | "FinalizeRequest" | "trackchange" | "finalizerequest"

      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: "data" | "sample" | "metadata" | "close" | "Data" | "Metadata" | "Close" | "TrackChange" | "Sample" | "FinalizeRequest" | "trackchange" | "finalizerequest"

      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

  • Ingest audio sample for trackId, if sample is undefined it only changes the tracks

    Parameters

    • trackId: number
    • Optional sample: Sample

    Returns void

  • Ingest timed data sample for trackId

    Parameters

    • trackId: number
    • time: number
    • data: any

    Returns void

  • Ingest video sample for trackId, if sample is undefined it only changes the tracks If sample.duration is negative, it will extend the sample until the currentTime to repair synchronization

    Parameters

    • trackId: number
    • Optional sample: Sample

    Returns void

  • Retrieves the Source class registered for the specified protocol.

    Parameters

    • protocol: string

      The name of the protocol (e.g., 'wss', 'https', 'http').

    Returns undefined | SourceType

    The registered Source class implementation for the protocol, or undefined if not found.

  • Registers a Source class for one or multiple protocols, see getClass to retrieve the registered Source class.

    Parameters

    • Rest ...protocols: [string, ...string[]]

      One or more protocol names (e.g., 'wss', 'https', 'http'), at least one protocol is required.

    Returns (<Class>(SourceClass, context?) => Class)

    A decorator that registers the given Source class under the specified protocols.

      • <Class>(SourceClass, context?): Class
      • Type Parameters

        • Class extends SourceType

        Parameters

        • SourceClass: Class
        • Optional context: unknown

        Returns Class

    Example

    *@Source.registerClass('wss', 'ws')*
    export class MySource extends Source {
    constructor(playing: IPlaying, params: Connect.Params) {
    super(playing, 'wss', params);
    }
    }

Events

  • Fire when data is received in the stream.

    Parameters

    • trackId: number
    • time: number
    • data: any

    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 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.

    Example

    // Set the initial video track to the highest quality; MBR will adjust it later based on network conditions.
    player.onMetadata = (metadata) => ({ video: metadata.videoTracks[0].id });

    // Alternatively, disable MBR and lock the video track to the highest available quality.
    player.onMetadata = (metadata) => player.videoTrack = metadata.videoTracks[0].id;