Class: shaka.util.CmcdManager

Thin shaka adapter around `cml.cmcd.CmcdReporter`. The vendored reporter owns CMCD state, encoding, key filtering, sequence numbers, and event-mode dispatch. The adapter translates shaka's player / `

Constructor

new CmcdManager(player, config)

Thin shaka adapter around `cml.cmcd.CmcdReporter`. The vendored reporter owns CMCD state, encoding, key filtering, sequence numbers, and event-mode dispatch. The adapter translates shaka's player / `

Parameters:
Name Type Description
player shaka.Player
config shaka.extern.CmcdConfiguration
Source:

Members

EventType :string

Public re-export of CMCD v2 event types. Literal form per the Closure-tooling constraint above. Values match `cml.cmcd.CmcdEventType` exactly; unit-test asserts identity.
Type:
  • string
Properties:
Name Value Type Description
BITRATE_CHANGE bc string
PLAY_STATE ps string
PLAYBACK_RATE pr string
ERROR e string
TIME_INTERVAL t string
CONTENT_ID c string
BACKGROUNDED_MODE b string
MUTE m string
UNMUTE um string
PLAYER_EXPAND pe string
PLAYER_COLLAPSE pc string
RESPONSE_RECEIVED rr string
AD_START as string
AD_END ae string
AD_BREAK_START abs string
AD_BREAK_END abe string
SKIP sk string
CUSTOM_EVENT ce string
Source:

LEGACY_REQUEST_TOKENS_ :Array<string>

The request types shaka decorated before includeInRequests existed. Used when the application left its list empty, so existing deployments see no change. Steering and callback requests are deliberately absent.
Type:
  • Array<string>
Source:

PlayerState :string

Public re-export of CMCD v2 player states. Literal form per the Closure-tooling constraint above. Values match `cml.cmcd.CmcdPlayerState` exactly; unit-test asserts identity.
Type:
  • string
Properties:
Name Value Type Description
STARTING s string
PLAYING p string
SEEKING k string
REBUFFERING r string
PAUSED a string
WAITING w string
ENDED e string
FATAL_ERROR f string
QUIT q string
PRELOADING d string
Source:

StreamingFormat :string

Public re-export of CMCD streaming-format values. The literal object form is required for Closure tooling: clutz (TypeScript-defs gen) and `generateExterns.js` reject `@export`ed `@enum`s whose RHS is a MemberExpression / alias. The 4 values match `cml.cmcd.CmcdStreamingFormat` exactly; a unit test asserts value identity.
Type:
  • string
Properties:
Name Value Type Description
DASH d string
HLS h string
SMOOTH s string
OTHER o string
Source:

effective_ :shaka.util.CmcdManager.EffectiveConfig

The configuration actually in effect: app config merged with manifest parameters.
Type:
Source:

generatedSessionId_ :string

Session id generated when neither the app nor the manifest supplies one. Kept across reporter rebuilds; cleared by reset() so each playback session gets a fresh id.
Type:
  • string
Source:

lastPlayerState_ :string

Type:
  • string
Source:

manifestParams_ :shaka.extern.ClientDataReporting

CMCD parameters signaled by the manifest, or null.
Type:
Source:

reporter_ :cml.cmcd.CmcdReporter

Type:
  • cml.cmcd.CmcdReporter
Source:

requestTimestampMap_ :Map<!shaka.extern.Request, number>

Per-request `ts` values for TTFB/TTLB derivation in `applyResponseData`. CmcdReporter cannot observe request-send time; the adapter measures it.
Type:
Source:

sf_ :cml.cmcd.CmcdStreamingFormat|undefined

Streaming format set once at manifest-load time. CTA-5004 / CTA-5004-B define `sf` as a stable manifest-type indicator (`'d'`/`'h'`/`'s'`/ `'o'`); the value does not reflect the low-latency state.
Type:
  • cml.cmcd.CmcdStreamingFormat | undefined
Source:

startTimeOfLoad_ :number

Type:
  • number
Source:

video_ :HTMLVideoElement

Type:
  • HTMLVideoElement
Source:

Methods

allKeysForVersion_(version) → {Array<string>}

Parameters:
Name Type Description
version number | undefined
Source:
Returns:
Type
Array<string>

filterSupportedKeys_(keysnon-null, version) → {Array<string>}

Keep only the manifest keys this player can emit for the given version: keys CML knows for that version plus custom keys (hyphenated prefix). Unsupported keys are ignored per Table K.8.
Parameters:
Name Type Description
keys Array<string>
version number
Source:
Returns:
Type
Array<string>

isMaterialChange_(anon-null, bnon-null) → {boolean}

Whether two effective configurations differ in a field the reporter itself consumes, which is the only reason to tear it down and build a new one. `includeInRequests`, `serviceLocations` and `adaptationSets` are evaluated by this adapter on each request, so they are not compared: rebuilding for them would clear the request timestamps and reset CML's counters for nothing. `eventTargets` is compared by reference, as before.
Parameters:
Name Type Description
a shaka.util.CmcdManager.EffectiveConfig
b shaka.util.CmcdManager.EffectiveConfig
Source:
Returns:
Type
boolean

requestTypeToken_(typenon-null, contextnon-null) → {string}

Map a shaka request to its ISO/IEC 23009-1:2026 Table I.4 request type token. License, key, certificate and timing requests have no DASH token; they get the internal tokens 'license' and 'timing', which only the legacy default set and '*' match.
Parameters:
Name Type Description
type shaka.net.NetworkingEngine.RequestType
context shaka.extern.RequestContext
Source:
Returns:
null when shaka never decorates this request type.
Type
string

resolveEffectiveConfig(confignon-null, manifestParamsnullable, generatedSessionIdnullable) → {shaka.util.CmcdManager.EffectiveConfig}

Merge the application configuration with manifest-signaled CMCD parameters (ISO/IEC 23009-1:2026 Annex K). Manifest values win for the fields the manifest can express (version, mode, keys, includeInRequests, contentID, sessionID) and the presence of parameters enables reporting. Attributes the manifest omitted already carry the spec defaults, except keys / ids, which fall back to the application values. Everything else comes from the application. Does not mutate its arguments or any manager state.
Parameters:
Name Type Attributes Description
config shaka.extern.CmcdConfiguration
manifestParams shaka.extern.ClientDataReporting <nullable>
generatedSessionId string <nullable>
Source:
Returns:
Type
shaka.util.CmcdManager.EffectiveConfig

resolveServiceLocation_(uri, baseUrisnon-null) → {string}

Resolve the service location of a URI by longest-prefix match over the manifest's BaseURL / Location declarations.
Parameters:
Name Type Description
uri string
baseUris Array<shaka.extern.ServiceLocationBaseUri>
Source:
Returns:
Type
string

appendSrcData(uri, mimeType) → {string}

Apply CMCD data to streams loaded via `
Parameters:
Name Type Description
uri string
mimeType string
Source:
Returns:
Type
string

appendTextTrackData(uri) → {string}

Apply CMCD data to a sidecar text track URI.
Parameters:
Name Type Description
uri string
Source:
Returns:
Type
string

applyEffectiveConfig_()

Recompute the effective configuration and rebuild the reporter when a material field changed.
Source:

applyRequestData(typenon-null, requestnon-null, contextopt)

Apply CMCD data to a request via the reporter.
Parameters:
Name Type Attributes Description
type shaka.net.NetworkingEngine.RequestType
request shaka.extern.Request
context shaka.extern.RequestContext <optional>
Source:

applyResponseData(typenon-null, responsenon-null, contextopt)

Apply CMCD data to a response.
Parameters:
Name Type Attributes Description
type shaka.net.NetworkingEngine.RequestType
response shaka.extern.Response
context shaka.extern.RequestContext <optional>
Source:

applyTextData(requestnon-null)

Apply CMCD data to a sidecar text request.
Parameters:
Name Type Description
request shaka.extern.Request
Source:

applyToRequest_(requestnon-null, datanon-null)

Push a CMCD-applied request through `createRequestReport`. Mutates `request` in place to preserve shaka's existing applyRequestData contract.
Parameters:
Name Type Description
request shaka.extern.Request
data cml.cmcd.Cmcd
Source:

buildExternalUriData_() → {cml.cmcd.Cmcd}

Persistent CMCD baseline used by `appendSrcData` / `appendTextTrackData`. These bypass the reporter (browsers can't observe headers for direct media loads, so we always force query mode regardless of configured `useHeaders`); `sn` is omitted since the reporter's per-target counters don't apply.
Source:
Returns:
Type
cml.cmcd.Cmcd

calculateRtp_(stream, segment) → {number}

Computed `rtp` (requested maximum throughput) for a segment.
Parameters:
Name Type Description
stream shaka.extern.Stream
segment shaka.media.SegmentReference
Source:
Returns:
Type
number

configure(config)

Update the application configuration. If the effective configuration changes materially, the reporter is torn down and recreated.
Parameters:
Name Type Description
config shaka.extern.CmcdConfiguration
Source:

encodeOptionsForUri_(uri) → {cml.cmcd.CmcdEncodeOptions}

Encode options for direct `cml.cmcd.appendCmcdQuery` calls (`appendSrcData`, `appendTextTrackData`). `baseUrl` lets CML relativize `nor` URLs root-relative; `version` filters keys per spec; `reportingMode = REQUEST` pins the request-mode key filter.
Parameters:
Name Type Description
uri string
Source:
Returns:
Type
cml.cmcd.CmcdEncodeOptions

getBufferLength_(type) → {number}

Buffer length in milliseconds for a media type.
Parameters:
Name Type Description
type string
Source:
Returns:
Type
number

getCurrentTime_() → {number}

Source:
Returns:
Type
number

getDataForSegment_(context, requestUrinullable) → {Object<string, *>}

Build the per-segment CMCD payload from shaka's request context.
Parameters:
Name Type Attributes Description
context shaka.extern.RequestContext
requestUri string <nullable>
Source:
Returns:
Type
Object<string, *>

getObjectType_(context) → {cml.cmcd.CmcdObjectType|undefined}

Map a shaka request context to a CMCD object type.
Parameters:
Name Type Description
context shaka.extern.RequestContext
Source:
Returns:
Type
cml.cmcd.CmcdObjectType | undefined

getObjectTypeFromMimeType_(mimeType) → {cml.cmcd.CmcdObjectType|undefined}

Map a mimeType to a CMCD object type. Used by `appendSrcData`.
Parameters:
Name Type Description
mimeType string
Source:
Returns:
Type
cml.cmcd.CmcdObjectType | undefined

getRemainingBufferLength_(type) → {number}

Remaining buffer length in milliseconds.
Parameters:
Name Type Description
type string
Source:
Returns:
Type
number

getStreamFormat_(type) → {cml.cmcd.CmcdStreamingFormat|undefined}

Resolve `sf` from the manifest-parser advanced-request type.
Parameters:
Name Type Description
type shaka.net.NetworkingEngine.AdvancedRequestType
Source:
Returns:
Type
cml.cmcd.CmcdStreamingFormat | undefined

getStreamType_() → {cml.cmcd.CmcdStreamType}

Source:
Returns:
Type
cml.cmcd.CmcdStreamType

getTopBandwidth_(type) → {number}

Top-bandwidth value across variants for a given object type.
Parameters:
Name Type Description
type cml.cmcd.CmcdObjectType | undefined
Source:
Returns:
Type
number

isTokenAllowed_(token) → {boolean}

An empty list means different things depending on where it came from. A manifest-supplied list is authoritative even when empty: it named only request types this player never makes, so nothing is decorated. An empty application list is just the unconfigured default, and falls back to the legacy request set.
Parameters:
Name Type Description
token string A Table I.4 request type token, or one of the internal tokens 'license' / 'timing'.
Source:
Returns:
Type
boolean

makeRequester_() → {function(!Object): !Promise<{status: number}>}

Build the `requester` callback CmcdReporter uses for event-mode dispatch. Routes through NetworkingEngine so the request inherits auth / retry / filters.
Source:
Returns:
Type
function(!Object): !Promise<{status: number}>

maybeStartReporter_()

Construct and start the reporter, and wire up its event listeners, if the effective configuration is enabled and a video element is available. No-ops if the reporter is already running or either precondition fails.
Source:

onLoad()

Re-arm the reporter for a new playback session. The Player calls this at the start of every `load()`: each `load()` after the first is preceded by an unload that stops the reporter via `reset()`, and neither `setMediaElement()` (the element stays attached) nor `configure()` runs again on that path, so without this hook CMCD would stay silent for every load after the first (https://github.com/shaka-project/shaka-player/issues/10414). No-ops when a reporter is already running, when CMCD is disabled, or when no media element is attached.
Source:

passesManifestFilters_(typenon-null, requestnon-null, contextnon-null) → {boolean}

Apply the ClientDataReporting serviceLocations and adaptationSets filters (ISO/IEC 23009-1:2026 Table K.7). Both filters intersect. A request whose service location cannot be resolved is excluded on purpose: header-mode CMCD toward a CDN that did not ask for it can trigger CORS preflight failures. Steering requests are not CDN requests and bypass the service location filter (dash.js does the same). The adaptationSets filter applies only to requests that carry a stream.
Parameters:
Name Type Description
type shaka.net.NetworkingEngine.RequestType
request shaka.extern.Request
context shaka.extern.RequestContext
Source:
Returns:
Type
boolean

removeCmcdQueryFromUri_(uri) → {string}

Strip the CMCD query parameter from a URL.
Parameters:
Name Type Description
uri string
Source:
Returns:
Type
string

reset()

Reset the manager at the end of a playback session. Stops the reporter and clears all session-scoped state, including manifest parameters and the generated session id. The video element reference is preserved (shaka keeps it attached across unload()/load(); only detach() releases it), so onLoad() can re-arm the reporter for the next session.
Source:

responseModeEnabled_() → {boolean}

Whether any configured `eventTarget` subscribes to the `'rr'` (response-received) event. Saves recording response-received calls into the reporter when no target consumes them.
Source:
Returns:
Type
boolean

setBuffering(buffering)

Forwarded from Player buffering observer; translates to a REBUFFERING / PLAYING player-state transition.
Parameters:
Name Type Description
buffering boolean
Source:

setLowLatency(lowLatency)

No-op shim retained for Player call-site back-compat. Phase 1 dropped the non-spec `'ld'`/`'lh'` StreamingFormat values; CTA-5004 does not define LL-specific values, so low-latency content emits `sf=d` (DASH) or `sf=h` (HLS).
Parameters:
Name Type Description
lowLatency boolean
Source:

setManifestParameters(paramsnullable)

Apply CMCD parameters signaled by the manifest (DASH ServiceDescription/ClientDataReporting, ISO/IEC 23009-1:2026 Annex K). Pass null when the manifest carries none. Honored only while `applyParametersFromManifest` is enabled in the app configuration.
Parameters:
Name Type Attributes Description
params shaka.extern.ClientDataReporting <nullable>
Source:

setMediaElement(mediaElement)

Set the media element and start the reporter (if enabled).
Parameters:
Name Type Description
mediaElement HTMLMediaElement The video element
Source:

setPlayerState_(statenon-null)

Player-state deduplication: skip the update + recordEvent pair if the new state is identical to the last-emitted one. Without this, `
Parameters:
Name Type Description
state cml.cmcd.CmcdPlayerState
Source:

setStartTimeOfLoad(startTimeOfLoad)

Set start time of load; trigger autoplay-driven start if applicable.
Parameters:
Name Type Description
startTimeOfLoad number
Source:

setupEventListeners_()

Wire `
Source:

shouldApplyToRequest_(typenon-null, requestnon-null, contextnon-null) → {boolean}

Whether CMCD data should be attached to this request, per the effective includeInRequests list (ISO/IEC 23009-1:2026 Table I.4 tokens).
Parameters:
Name Type Description
type shaka.net.NetworkingEngine.RequestType
request shaka.extern.Request
context shaka.extern.RequestContext
Source:
Returns:
Type
boolean

stopReporter_()

Stop the reporter and drop request-scoped state. Session-scoped state that a rebuild must carry over (manifest parameters, the generated session id, the learned `sf`, the last player state and the start time of load) is kept, so that a rebuild triggered mid-load does not lose the pending `msd` measurement.
Source:

toReporterConfig_(cfgnon-null) → {cml.cmcd.CmcdReporterConfig}

Translate the effective configuration into `cml.cmcd.CmcdReporterConfig`. Field renames: - `useHeaders` → `transmissionMode` enum - `version: 1|2` → `CMCD_V1` / `CMCD_V2` constants - per-target `includeKeys` → `enabledKeys` Empty `includeKeys` is expanded to all valid keys for the version, since CML's reporter early-returns when `enabledKeys` is empty.
Parameters:
Name Type Description
cfg shaka.util.CmcdManager.EffectiveConfig
Source:
Returns:
Type
cml.cmcd.CmcdReporterConfig

Type Definitions

EffectiveConfig

The configuration actually in effect after merging the application configuration with manifest-signaled parameters.
Type:
  • {enabled: boolean, version: number, useHeaders: boolean, sessionId: string, contentId: string, rtpSafetyFactor: number, includeKeys: !Array<string>, includeInRequests: !Array<string>, eventTargets: ?Array<shaka.extern.CmcdTarget>, serviceLocations: ?Array<string>, adaptationSets: ?Array<string>, serviceLocationBaseUris: !Array<shaka.extern.ServiceLocationBaseUri>, fromManifest: boolean}
Source: