The WebRTS Client exports a set of lower-level media primitives for advanced use cases: codec detection and string encoding, CMAF/fMP4 container demuxing and writing, RTS binary format parsing, MSE buffer management, and screen-resolution helpers. Most application developers only needDocumentation 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, Source, and Metadata — but these types become essential when building custom renderers, testing pipeline components in isolation, or integrating the library into non-standard playback architectures.
Media and AVC are re-exported as named namespace exports from the package root via export * as Media and export * as AVC. Import them by name: import { Media, AVC } from '@ceeblue/wrts-client'. You then access members as Media.Type.VIDEO, Media.Codec.H264, AVC.readCodecString, etc.Media Module
TheMedia module (from src/media/Media.ts) defines the core enums and types shared across the entire library.
Media.Type
Identifies the kind of data carried by a track or sample.| Value | Number | Description |
|---|---|---|
Media.Type.DATA | 0 | Data or subtitle track (ID3 tags, JSON metadata, WebVTT, etc.) |
Media.Type.AUDIO | 1 | Audio elementary stream |
Media.Type.VIDEO | 2 | Video elementary stream |
Media.Codec
Identifies a specific codec. Used to filter tracks inMetadata.filterAudios/filterVideos/filterDatas and to drive MSE codec strings.
| Value | String | Description |
|---|---|---|
Media.Codec.UNKNOWN | '' | Codec not yet identified |
Media.Codec.H264 | 'H264' | H.264 / AVC video |
Media.Codec.HEVC | 'HEVC' | H.265 / HEVC video |
Media.Codec.VP8 | 'VP8' | VP8 video |
Media.Codec.MP3 | 'MP3' | MPEG-1/2 Audio Layer III |
Media.Codec.AAC | 'AAC' | Advanced Audio Coding |
Media.Codec.OPUS | 'OPUS' | Opus audio |
Media.Codec.ID3 | 'ID3' | ID3 timed metadata (data track) |
Media.Codec.JSON | 'JSON' | JSON metadata (data track) |
Media.Codec.SUBTITLE | 'SUBTITLE' | Subtitle / closed-caption data |
Media.Sample
Represents a single decoded media sample produced by aReader and consumed by a MediaBuffer.
Media.Resolution
A simple width/height pair used for video track resolution and screen size comparisons.Media.Tracks
Selects which tracks are active. Passed toonInitTracks and used internally for ABR switching.
Media Utility Functions
Converts a
Media.Type enum value to a lowercase string.Returns the physical screen resolution in pixels, accounting for
window.devicePixelRatio. Automatically swaps width/height on portrait (smartphone) screens so the larger dimension is always width. Returns undefined in non-browser environments.Returns
true if resolution exceeds both the width and height of screen. Useful for filtering out video tracks that the display cannot render at full quality.Maximum Group of Pictures duration constant, set to
10000 ms (10 seconds). Used internally to bound buffer window calculations.Reader Abstract Class
Reader is the abstract base class for all container-format demuxers. Concrete implementations (CMAFReader, RTSReader) extend it and implement the parse() method. Feed binary data incrementally via read(); the reader buffers incomplete frames automatically.
Constructor
Methods
Feeds a chunk of binary data into the reader. Internally accumulates incomplete frames between calls.
Clears any internally buffered incomplete data. Call this when seeking or after a track change.
Events
Fired for each decoded media sample.
Fired when a metadata packet is found embedded in the stream (e.g. an RTS metadata frame or a CMAF
emsg box carrying a JSON manifest).Fired once after the container initialization segment is parsed and track IDs are known.
Fired on parse errors. The default implementation logs the error.
ReaderError Type
Invalid payload
Invalid payload
The binary data does not conform to the expected format at a specific point in the parse.
Unknown format
Unknown format
An unrecognized box type or packet type was encountered.
Unsupported format
Unsupported format
A recognized but unimplemented format variant was encountered (e.g. an unsupported
senc version).Unfound track
Unfound track
A fragment header (
tfhd) referenced a track ID that was never declared in the moov box.CMAFReader
CMAFReader extends Reader and parses CMAF/fMP4 (Fragmented MP4) container segments. It handles moov, moof, mdat, DRM boxes (tenc, senc, sinf/schi), and emsg event message boxes. It is used internally by HTTPAdaptiveSource and WSSource when receiving CMAF-segmented streams.
Constructor
When
true, the raw CMAF bytes are collected and passed as sample.data for each sample rather than the unwrapped elementary stream payload. Defaults to false.Additional Event
Fired when an
emsg (Event Message Box) is found in the stream, such as an ID3 timed metadata event.Static Method
Parses a raw
sinf/schi payload (as received in a FairPlay encrypted event) and returns the track encryption descriptor, including KID and IV configuration.RTSReader
RTSReader extends Reader and parses the RTS binary container format used by WebRTS WebSocket streams. The RTS format uses 7-bit variable-length integers for compact framing and carries audio, video, data, metadata, and init-tracks commands in a single multiplexed stream.
Constructor
When
true, each packet in the stream is preceded by a 7-bit variable-length size field. When false (default), the reader assumes a frame-oriented transport such as WebSocket where each message is already a complete packet.CMAFWriter
CMAFWriter writes CMAF/fMP4 output optimized for live streaming. It is used internally by MediaBuffer to wrap elementary stream samples in proper moov/moof/mdat boxes before they are appended to an MSE SourceBuffer. It currently supports H.264 video and AAC/MP3 audio, with optional CENC/CBCS content protection.
Constructor
Methods
Writes the
ftyp + moov initialization segment for the given track. Returns a CMAFWriterError if the codec or track type is unsupported, undefined on success.Wraps a single
Media.Sample in moof + mdat boxes and fires onWrite.Event
Fired with each encoded CMAF packet ready to be appended to a
SourceBuffer.CMAFWriterError Type
AVC Module
TheAVC module (src/media/AVC.ts) provides H.264/AVC-centric codec string parsing, SPS decoding, and audio config serialization utilities. These are used internally by CMAFReader and Metadata to populate MediaTrack fields from binary codec configuration data.
Parses an RFC 6381 codec descriptor string and writes the detected Recognized prefixes include
codec and type into out. Returns true on a successful match.avc1/avc2/avc3/avc4/h264/x264/264, mp4a.40 (AAC), mp4a.40.34 (MP3), opus, vp8, id3, json, subtitle.Builds an RFC 6381 codec descriptor string from a
Media.Codec enum and optional binary config data (e.g. avcC bytes for H.264 profile/level encoding).Parses an
avcC or hvcC binary blob and returns a VideoConfig object containing the raw sps and optional pps byte arrays.Serializes a
VideoConfig (SPS + PPS) into an avcC binary blob using the provided BinaryWriter.Decodes an H.264 Sequence Parameter Set to extract resolution and frame rate, writing them into
out only if not already populated.Encodes MPEG-4 Audio Specific Config (ASC) bytes for an AAC stream.
Decodes MPEG-4 ASC bytes and returns
{ rate, channels }.Extracts the 5-bit NAL unit type from a NAL header byte.
MediaBuffer
MediaBuffer wraps a single MSE SourceBuffer (audio or video) and manages the full lifecycle of appending, codec-type changes, buffer trimming, and quota-exceeded recovery. It uses CMAFWriter internally to convert Media.Sample objects into fMP4 data before appending.
Constructor
Key Properties
true if the MIME type starts with 'video'.The playback start boundary in seconds. Setting this triggers a
flush() that removes buffered data before the new start time.The end of the currently buffered range in seconds (read-only).
Key Methods
Appends a single decoded sample to the buffer. Automatically initializes the
SourceBuffer codec on first call or on track ID change.Drains the internal packet queue into the
SourceBuffer. Pass fixHole = true to force removal of timeline discontinuities.Cancels all pending operations and releases the
SourceBuffer.Events
Fired after each successful buffer update cycle.
Fired with each raw
Uint8Array appended to the SourceBuffer. Useful for debugging MSE ingestion.Fired on any buffer error (see
MediaBufferError).MediaBufferError Type
MediaPlayback
MediaPlayback coordinates one audio MediaBuffer and one video MediaBuffer over a shared MediaSource. It exposes a unified startTime/endTime that spans both tracks, handles MSE endOfStream, and fires onProgress as the buffers advance.
Constructor
Key Properties
true when both the audio and video buffers have been released.The earliest common buffered time across both tracks (in seconds). Setting this trims both buffers.
The latest common sync point across both tracks (in seconds).
Enables the audio track (creates a new
audio/mp4 MediaBuffer). Disabling audio is not supported; attempting to set false closes the playback with an error.Enables the video track (creates a new
video/mp4 MediaBuffer). Disabling video is not supported; attempting to set false closes the playback with an error.Key Methods
Appends an audio sample to the audio buffer.
Appends a video sample to the video buffer.
Flushes both audio and video buffers.
Ends the
MediaSource stream, aborts both buffers, and fires onClose.Events
Fired when the playback is closed, with an optional error if the closure was abnormal.
Fired when a buffer quota is exceeded. Call
player.play() or advance startTime to recover.Fired each time the combined buffer end time advances.
Raw audio bytes appended to MSE (for debugging).
Raw video bytes appended to MSE (for debugging).
MediaPlaybackError Type
MediaTrack
MediaTrack is a plain data class representing a single track descriptor. Its properties are documented in full on the Metadata reference page under MediaTrack Properties, since MediaTrack instances are always obtained from Metadata.tracks, Metadata.audioTracks, Metadata.videoTracks, or Metadata.dataTracks.
The class also provides a convenience toString() method that builds a human-readable label:
Reader, CMAFReader, RTSReader, CMAFWriter, MediaBuffer, and MediaPlayback are all designed for advanced or internal use. Most application developers building a standard live stream viewer only need Player, Source/HTTPAdaptiveSource/WSSource, and Metadata.