Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CeeblueTV/wrts-client/llms.txt
Use this file to discover all available pages before exploring further.
Source is the abstract base class that all WebRTS transport implementations extend. It provides the wiring between the network layer (HTTP adaptive, WebSocket, etc.) and the Player’s MSE pipeline: protocol registration, sample ingestion helpers, timestamp continuity correction, byte-rate accounting, CMCD telemetry, and track management. Concrete subclasses — HTTPAdaptiveSource, WSSource, and HTTPSource — override three abstract methods (play, setReliability, setTracks) to implement their transport strategy. Source implements ICMCD and extends EventEmitter from @ceeblue/web-utils.
Static Methods
Source.registerClass()
Source subclass for one or more protocol names. When Player resolves a source class from an endPoint URL, it calls Source.getClass(protocol) to retrieve the registered implementation.
The return type is a TypeScript 5–compatible decorator function (not the legacy
ClassDecorator type). No experimentalDecorators compiler option is needed — just apply @Source.registerClass('myproto') directly on the class.One or more protocol strings (e.g.,
'https', 'http', 'wss', 'ws'). At least one is required. Strings are normalised to lowercase.Source.getClass()
Source subclass registered for the given protocol, or undefined if none is registered.
Protocol name to look up (case-insensitive).
Constructor
The constructor is called byPlayer (or directly when building a custom source). It must be invoked from the subclass constructor via super.
The
IPlaying instance provided by the Player. Used to read buffer metrics, fire skip events, and receive the abort signal.Protocol string used to build the connection URL via
Connect.buildURL (e.g., 'https', 'wss').Connection parameters passed from
Player.start().Optional connection type. Defaults to
Connect.Type.WRTS.The
Source constructor schedules play() asynchronously via Promise.resolve().then(...), so the subclass constructor returns synchronously and the network connection is initiated in the next microtask.Abstract Methods
Subclasses must implement all three of these methods.play()
Promise) or fire-and-forget. The method is called automatically by the base class on the next microtask after construction.
Built endpoint URL (protocol + host + path + query).
Initial track selection computed from
onMetadata or auto-selection.The same
IPlaying instance passed to the constructor.setReliability()
reliable flag is toggled on the Player. Implementations should reconfigure their transport to enforce or relax frame-skipping behaviour.
setTracks()
player.videoTrack = id). Implementations should request the new rendition from the server or reconfigure their demux pipeline.
Public Method
close()
onClose with the optional error. Certain request errors (e.g., HTTP 404 or 'stream open failed') are automatically morphed into a 'Resource unavailable' error before calling onClose.
Optional error describing why the source closed improperly. Omit for clean closure.
Protected Helper Methods
These methods are available to subclass implementations.Events (Overridable Methods)
ThePlayer overrides these when it attaches to a Source instance. Custom Source subclasses can also call them.
onClose()
error is set for abnormal closures. The Player hooks this to call player.stop(error).
onTrackChange()
Player hooks this to enable/disable the corresponding SourceBuffer in MediaPlayback.
onMetadata()
Media.Tracks object to specify initial track selection; the Player forwards this to player.onMetadata.
onAudio() / onVideo() / onData()
Player hooks these to append data to the MSE SourceBuffer via MediaPlayback.
onFinalizeRequest()
Properties
Identity & State
Read-only. Derived source name, e.g.,
'https-mp4' for an HTTP adaptive source fetching MP4 segments, or the Connect.Type string for non-WRTS connections.Read-only.
true after close() has been called.Read-only. Stream name extracted from
Connect.Params.streamName, e.g., 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'.Read-only. The fully-built endpoint URL string.
Read-only. The most recently received
Metadata object, or undefined before metadata is received.Timeline
Read-only. Current end-of-buffer time for audio in milliseconds (source domain).
Read-only. Current end-of-buffer time for video in milliseconds (source domain).
Read-only. Current end-of-buffer time for data in milliseconds (source domain).
Read-only. Maximum of
audioTime, videoTime, and dataTime — the furthest point any track has reached.Track Selection
Read/write. Effective audio track ID currently being received, or
undefined before initialisation. -1 means disabled. Setting triggers setTracks().Read/write. Effective video track ID. Setting triggers
setTracks() and disables MBR.Read/write. Set of effective data track IDs. Accepts
number, number[], Set<number>, or undefined (all tracks).Read-only. The manually-selected audio track index (
undefined = automatic / MBR).Read-only. The manually-selected video track index (
undefined = automatic / MBR).Read-only. The manually-selected data tracks (
undefined = all tracks).Read-only.
true if the subclass overrides setTracks (indicating it supports manual track selection).Byte Rates
Read-only. Audio payload byte rate in bytes per second, averaged over the last GOP.
Read-only. Video payload byte rate in bytes per second, averaged over the last GOP.
Read-only. Estimated data/overhead byte rate:
max(0, recvByteRate - audioByteRate - videoByteRate).Read-only. The raw
ByteRate accumulator for all received bytes (audio + video + overhead). Access .value() for the current bytes-per-second figure.Frame Rates
Read-only. Audio frames decoded per second.
Read-only. Video frames decoded per second.
Skip Counters
Read-only. Cumulative duration of audio skipped in milliseconds since the source opened.
Read-only. Cumulative duration of video skipped in milliseconds since the source opened.
Reliability & Format
Read/write. Whether the source is in reliable (no-skip) mode. Calls
setReliable() on write.Read-only. Media extension string extracted from
Connect.Params.mediaExt (e.g., 'mp4', 'rts'). Determines which Reader is created by newReader().Tracks Combinability
Read/write. When
true (default), requests for audio and video tracks are combined into a single HTTP request. Automatically set to false when passthroughCMAF is active.ICMCD Properties
Read/write. CMCD payload level. Base implementation always returns
CMCD.NONE and rejects non-null writes (override in subclasses that support CMCD, like HTTPAdaptiveSource).Read/write. CMCD delivery mode (
CMCDMode.HEADER or CMCDMode.QUERY). Defaults to CMCDMode.HEADER.Read/write. CMCD session identifier.
SourceError Type
SourceError is a discriminated union on { type: 'SourceError', name: string }. Match error.name after confirming error.type === 'SourceError':
SourceError also wraps errors from lower layers:
ReaderError— parsing errors fromCMAFReaderorRTSReader.WebSocketReliableError— WebSocket-level transport errors (when usingWSSource).