TheDocumentation 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.
Player class is the main entry point for WebRTS live stream playback. It wraps an HTMLVideoElement and orchestrates three key subsystems: a Source transport layer that fetches and demuxes the media, a MediaPlayback engine that feeds data into the browser’s Media Source Extensions (MSE) pipeline, and an optional MediaKeysEngine for DRM-protected streams. Player extends EventEmitter and implements both IPlaying (exposing buffer and rate metrics to the Source) and ICMCD (Common Media Client Data telemetry). Override the on* event methods to hook into lifecycle events without needing to add manual listeners.
Constructor
Player instance. This does not start playback — call start() to begin streaming.
The video element on which the stream will be rendered.
Optional custom
Source implementation to use for transport. When omitted, Player.start() resolves the class from the endpoint protocol via Source.getClass(), or falls back to HTTPAdaptiveSource. If the endpoint starts with ws:// or wss://, WSSource is used automatically when it is registered.Methods
start()
params. Internally creates a MediaSource, attaches it to the video element, then instantiates the resolved Source and MediaPlayback. If a MediaKeysEngine from a previous session is still cleaning up, the call is automatically deferred until the teardown completes.
Connection parameters including
endPoint, optional streamName, mediaExt, contentProtection, and query overrides. The protocol prefix of endPoint (e.g., https, wss) determines which registered Source class is instantiated.Idle timeout in milliseconds. Defaults to approximately 14 000 ms (chosen to be safely above the maximum GOP duration of ~10 s). The timer resets on connection and data events; if it fires, playback stops with a
'Start timeout', 'Connection timeout', or 'Data timeout' PlayerError.stop()
Source, MediaPlayback, and MSE pipeline, and resets all internal state. Calls onStop when complete.
When provided, the stop is treated as an improper termination and the error is forwarded to
onStop. Omit for a graceful, user-initiated stop.goLive()
video.currentTime to endTime - bufferLimitMiddle / 1000, clamped to be no earlier than startTime.
Optional human-readable label appended to the internal log entry, useful for distinguishing automatic (
'restoring', 'repairing') from manual seeks.adjustPlaybackRate()
video.playbackRate linearly based on the current bufferState to keep the buffer within the configured thresholds. Call this from onBufferChange (the default implementation already does so).
Minimum playback rate as a percentage. Defaults to 84 (0.84×). Values above 92 are clamped to 92 to ensure the decrease is meaningful.
Maximum playback rate as a percentage. Defaults to 116 (1.16×). Values below 108 are clamped to 108 to ensure the increase is meaningful. Set to 100 or less to disable speed-up entirely.
computeStats()
PlayerStats object (from @ceeblue/web-utils). Includes protocol, buffer amount, latency, playback rate, per-track byte rates, frames per second, stall count, and more.
Events (Overridable Methods)
Override any of these methods on aPlayer instance to react to lifecycle and media events. Each method has a default implementation that logs to the internal logger.
onStart()
MediaSource opens and the Source and MediaPlayback are fully initialized. After this event started returns true and track properties become assignable.
onStop()
error is populated for improper stops (timeout, decode failure, network error, etc.); it is undefined for clean stops triggered by calling stop() without an argument.
onMetadata()
Media.Tracks object to specify the initial audio and video tracks to use; returning nothing (or undefined) selects the middle-quality rendition by default. Setting player.videoTrack or player.audioTrack inside this handler disables MBR for that track.
onTrackChange()
Active audio track ID, or
-1 if disabled.Active video track ID, or
-1 if disabled.Set of active data track IDs.
onBufferState()
bufferState transitions between NONE, LOW, OK, and HIGH. oldState is the previous value; read this.bufferState for the new one.
onBufferChange()
bufferAmount changes by at least 50 ms (the BUFFER_CHANGE_STEP constant). The default implementation calls adjustPlaybackRate(). Override to implement custom rate adaptation logic.
onStall()
waiting and the buffer is below bufferLimitLow).
onAudioSkipping()
Duration of the skipped audio hole in milliseconds.
onVideoSkipping()
Duration of the skipped video region in milliseconds.
onFinalizeRequest()
A mutable clone of the request URL.
The mutable request headers object.
onData()
onAudioAppended()
SourceBuffer. Useful for low-level debugging of the MSE ingestion pipeline.
onVideoAppended()
SourceBuffer.
onMediaKeys()
MediaKeysEngine state changes. Receives the engine instance when it becomes ready, or undefined when it is released (after stop()).
Properties
Playback State
Read-only.
true between a call to start() and stop(). Guards track assignment and pause operations.Read-only.
true after onStart fires (i.e., after the Source is fully initialized). Track properties are only valid when started is true.Read/write. Pauses or resumes the underlying
video element. Throws if running is false.Read/write. Controls frame-skipping mode.
false (default) enables frame skipping for low-latency live streaming. true disables skipping and enforces reliable delivery. Throws on write if the player has not started (i.e., _source is not yet initialised).Track Selection
Read/write. Index of the active audio track. Setting a value disables MBR for audio; set to
undefined to re-enable automatic selection. Throws on write if not started.Read/write. Index of the active video track. Setting a value disables MBR for video; set to
undefined to re-enable automatic selection. Throws on write if not started.Read/write. Set of active data track IDs. Accepts a single
number, an Array<number>, a Set<number>, or undefined (which selects all available data tracks). Throws on write if not started.Read-only.
true if the active Source implementation supports manual track selection. Returns undefined when the player is not running.Read-only. The most recently received stream
Metadata object, containing track lists, content-protection details, and live-time information.Buffer Metrics
Read-only. Current buffer depth in milliseconds, computed as
(endTime - currentTime) * 1000.Read/write. Low-buffer threshold in milliseconds. Default 150 ms. When
bufferAmount falls below this value, bufferState transitions to LOW.Read/write. High-buffer threshold in milliseconds. Default 550 ms. When
bufferAmount exceeds this value, bufferState transitions to HIGH.Read-only. Computed midpoint between
bufferLimitLow and bufferLimitHigh, used as the target buffer depth for live-edge seeks (goLive) and post-stall recovery.Read-only. Current
BufferState value: NONE, LOW, OK, or HIGH.Read-only.
true while the player is accumulating data before playback can resume (initial start, or recovering from a stall). Becomes false when bufferAmount reaches bufferLimitMiddle.Timing
Read-only. Playback start time in seconds (the oldest buffered position in the MSE timeline).
Read-only. Playback end time in seconds (the most recently appended media position).
Read-only. Current playback position in seconds (mirrors
video.currentTime).Read-only. Estimated live latency in milliseconds, calculated as
metadata.liveTime - currentTime * 1000. Returns undefined when the player has not yet started or currentTime is zero.Playback Rate
Read-only. Current
video.playbackRate. Controlled by adjustPlaybackRate().Read-only. Effective playback speed measured from elapsed
currentTime changes. 1.0 represents real-time.Byte Rates
Read-only. Total incoming byte rate (audio + video + data overhead) in bytes per second.
Read-only. Audio payload byte rate in bytes per second.
Read-only. Video payload byte rate in bytes per second.
Read-only. Data/metadata payload byte rate in bytes per second.
Read-only. Audio frames decoded per second.
Read-only. Video frames decoded per second.
Resolution & Tracks Combinability
Read/write. Upper-bound resolution for the MBR algorithm. Defaults to
Media.screenResolution() (updated on window.resize). Set to undefined for no cap.Read/write. When
true (default), audio and video tracks are fetched in a single combined request to reduce connection overhead. Set to false to force separate requests. Returns undefined when not running. Throws on write if not started.Debug & DRM
Read-only. Debug flag.
true when params.mediaExt was set to 'cmaf', which bypasses the internal demuxer and passes CMAF segments directly to MSE.Read-only. An
AbortSignal that fires when stop() is called. Sources and other async operations tied to this signal are automatically cancelled on stop.CMCD Properties
Read/write. Common Media Client Data payload mode (
CMCD.NONE, CMCD.SHORT, or CMCD.FULL). Proxied to the active Source. Throws on write if not started.Read/write. Delivery mode for CMCD data:
CMCDMode.HEADER (default) or CMCDMode.QUERY. Throws on write if not started.Read/write. CMCD session identifier string. Throws on write if not
started.PlayerError Type
PlayerError is a discriminated union. Match on error.type and then error.name to handle each case:
PlayerError also covers errors forwarded from sub-systems:
SourceError— transport / parsing errors. SeeSource.MediaPlaybackError— MSESourceBuffererrors (e.g.,'Exceeds buffer size').MediaKeysEngineError— DRM initialisation / key-request errors.