Skip to main content

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.

The Metadata class is the primary descriptor for a WebRTS stream. It is received via the onMetadata callback on Player or Source, and carries everything needed to configure playback: the protocol version negotiated with the server, the current live time, the full set of available tracks (audio, video, and data), and any DRM/content-protection configuration. Use the track arrays and filter methods to select the right quality level and codec before playback begins.
import { Metadata } from '@ceeblue/wrts-client';

Constructor

obj
any
A parsed JSON manifest object from the WRTS endpoint. The constructor reads the following fields:
  • version — protocol version string (e.g. "1.2.3") or number
  • currentTime / liveTime — current live time in milliseconds (or seconds if a decimal is present; automatically converted)
  • tracks[] — array of track descriptor objects
  • contentProtection[] — array of DRM descriptors keyed by KID

Static Methods

Metadata.connect
static async method
Fetches the stream manifest from a WRTS endpoint and returns a populated Metadata instance. The live time is adjusted by half the round-trip time (RTT) of the fetch to compensate for network latency.
static async connect(
  params: Connect.Params,
  controller: AbortController
): Promise<Metadata>
Returns Promise<Metadata> — resolves to the parsed metadata object.
const controller = new AbortController();
const metadata = await Metadata.connect({ endPoint: 'https://example.com/stream' }, controller);
console.log('Protocol:', metadata.protocolVersion);

Properties

protocolVersion
{ major: number; minor: number; patch: number }
The WebRTS protocol version negotiated by the server, parsed from the version field of the manifest.
// Example: { major: 1, minor: 2, patch: 0 }
console.log(metadata.protocolVersion.major);
date
Date
The Date at which this Metadata instance was constructed. Useful for calculating the age of cached metadata.
liveTime
number
The current live time of the stream, in milliseconds. This value continuously advances using the wall clock — it stores the timestamp from the manifest and extrapolates forward based on elapsed time since the object was created. The setter records both the new value and the current wall-clock time so future reads extrapolate correctly.
console.log('Current live time:', metadata.liveTime, 'ms');
tracks
Map<number, MediaTrack>
All tracks indexed by their numeric track ID, sorted by descending bandwidth. Includes audio, video, and data tracks.
audioTracks
Array<MediaTrack>
Audio-only tracks, sorted in descending order of bandwidth. The first element is the highest-quality audio track.
videoTracks
Array<MediaTrack>
Video-only tracks, sorted in descending order of bandwidth. The first element is the highest-quality video track.
dataTracks
Array<MediaTrack>
Data and subtitle tracks. Not sorted by bandwidth.
contentProtection
Map<string, ContentProtection>
DRM settings keyed by KID (Key ID). Each key is a 32-character lowercase hex string. Values are ContentProtection objects describing the encryption scheme, IV, and PSSH boxes for each DRM system.

Methods

fix()
method
Deduplicates and re-sorts all tracks by descending bandwidth, then rebuilds the up/down linked-list pointers on each MediaTrack. Call this after manually inserting tracks into Metadata outside of the constructor.
metadata.fix();
filterAudios(codecs?)
method
Removes all audio tracks whose codec is not in the provided set. Repairs up/down pointers afterward.
filterAudios(codecs?: Array<Media.Codec>): this
Returns this — chainable.
filterVideos(codecs?)
method
Removes all video tracks whose codec is not in the provided set. Repairs up/down pointers afterward.
filterVideos(codecs?: Array<Media.Codec>): this
Returns this — chainable.
filterDatas(codecs?)
method
Removes all data/subtitle tracks whose codec is not in the provided set.
filterDatas(codecs?: Array<Media.Codec>): this
Returns this — chainable.

MediaTrack Properties

Each entry in tracks, audioTracks, videoTracks, and dataTracks is a MediaTrack instance. See the Media Types page for the full class reference. Key properties are:
id
number
Numeric track identifier. Matches the key used in Metadata.tracks.
type
Media.Type
Track type: Media.Type.AUDIO, Media.Type.VIDEO, or Media.Type.DATA.
codec
Media.Codec
Detected codec enum value, e.g. Media.Codec.H264, Media.Codec.AAC, Media.Codec.OPUS.
codecString
string
RFC 6381 codec descriptor string (e.g. "avc1.640028", "mp4a.40.2").
bandwidth
number
Maximum bandwidth in bytes per second (Bps). Used for sorting and ABR decisions.
rate
number
Sample rate in Hz for audio tracks (e.g. 48000), or frames per second for video tracks (e.g. 25).
resolution
Media.Resolution | undefined
{ width: number, height: number } — only meaningful for video tracks. Defaults to { width: 0, height: 0 }.
channels
number
Number of audio channels. Only meaningful for audio tracks.
language
string | undefined
ISO 639-2 language code (e.g. "eng", "fra"). Present on audio and subtitle/data tracks when provided by the server.
config
Uint8Array | undefined
Codec-specific initialization data (e.g. avcC, esds, dOps box contents). Required for initializing MSE SourceBuffer codec strings.
contentProtection
string | undefined
The KID string linking this track to a ContentProtection entry in Metadata.contentProtection.
up
MediaTrack | undefined
The next-higher-quality track of the same type in the sorted linked list. undefined if this is the highest-quality track.
down
MediaTrack | undefined
The next-lower-quality track of the same type in the sorted linked list. undefined if this is the lowest-quality track.

ContentProtection Type

ContentProtection objects are stored in Metadata.contentProtection, keyed by KID.
scheme
ProtectionScheme
The CENC protection scheme applied to encrypted samples.
ValueHexDescription
ProtectionScheme.CENC0x63656e63AES-CTR full-sample encryption
ProtectionScheme.CBC10x63626331AES-CBC full-sample encryption
ProtectionScheme.CENS0x63656e73AES-CTR with sub-sample pattern
ProtectionScheme.CBCS0x63626373AES-CBC with sub-sample pattern (default)
kid
string
The Key ID as a 32-character lowercase hex string (UUID without dashes).
iv
string | undefined
The initialization vector as a hex string. undefined when ivMode is 'sample' (each sample carries its own IV).
ivMode
'constant' | 'sample'
How the IV is delivered:
  • 'constant' — a single IV is reused for every sample, carried in the metadata
  • 'sample' — each sample’s Media.Sample.iv field carries a per-sample IV
pssh
Map<string, string>
Maps DRM system UUID (e.g. "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" for Widevine) to the base64-encoded PSSH box for that system.

Usage Example

player.onMetadata = (metadata) => {
  console.log('Protocol version:', metadata.protocolVersion);
  console.log(
    'Video tracks:',
    metadata.videoTracks.map(t => `${t.id}: ${t.bandwidth}bps`)
  );

  // Select the highest-quality video track and first audio track:
  return {
    video: metadata.videoTracks[0]?.id,
    audio: metadata.audioTracks[0]?.id
  };
};
Use filterVideos and filterAudios before returning the track selection to ensure only browser-supported codecs are passed to the player. For example:
metadata.filterVideos([Media.Codec.H264]).filterAudios([Media.Codec.AAC, Media.Codec.OPUS]);

Build docs developers (and LLMs) love