@bitmovin/player-web-integration-cmcd 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.2] - 2026-11-27
11
+ ### Deprecated
12
+ - `CustomKey.keyValuePairToString`. Encoding is done for all keys of a request at once.
13
+
14
+ ### Fixed
15
+ - Encoded bitrate (`br`), object duration (`d`) and top bitrate (`tb`) were not rounded and could be sent as non-integers, e.g. `d=4003.9999999999995`. They are now rounded to integers.
16
+ - Content id (`cid`) and session id (`sid`) longer than 64 characters were sent. They are now omitted (with a console warning, once per value) instead of violating the maximum length of CMCD v1.
17
+ - Buffer starvation (`bs`) could be encoded as `bs=false`. It is now omitted if `false`.
18
+ - `preprocessHttpResponse` threw if the player passed no response (e.g. after a network error), which could prevent the request from being retried. A missing response is now passed on unchanged.
19
+ - `preprocessHttpRequest` could throw for values that cannot be encoded, e.g. a lone surrogate in a content id in query mode. The request is now sent without CMCD data and a console warning is logged.
20
+ - In HTTP header mode, string values and custom key names that are not printable ASCII (e.g. line breaks or `é`) were sent in the CMCD headers. Such keys are now omitted with a console warning.
21
+
22
+ ## [0.6.1] - 2026-11-20
23
+ ### Fixed
24
+ - Measured throughput (`mtp`) was reported in kilobytes per second instead of kilobits per second, making the value 8x too low (and frequently rounding down to 0, so the key was omitted entirely). Throughput is now converted from bytes to bits before scaling to kbps.
25
+ - Next object request (`nor`) contained the absolute URL of the next segment. It is now the path relative to the current request, URL encoded as required by the specification. `nor` is omitted if the next segment is on a different origin.
26
+ - Measured throughput (`mtp`) was sent as `mtp=0` for throughputs below 50 kbps. The key is now omitted in this case.
27
+ - Requested maximum throughput (`rtp`) was never sent. It is now sent for media segment requests outside of startup and buffer starvation, with 5 times the encoded bitrate (`br`), rounded to the nearest 100 kbps.
28
+ - Startup (`su`) was sent on all requests until the first seek or stall. It is now cleared when playback starts.
29
+ - Audio segment requests used the video segments to determine `nor` and object duration (`d`).
30
+ - Object duration (`d`) was sent as `NaN` if the segment duration is unknown.
31
+ - Streaming format (`sf`) was determined by the first request of any type, so e.g. an ads manifest or DRM request made `sf=o` stick for the whole session. It is now derived from the DASH, HLS master or Smooth manifest request (a new main manifest replaces the format of the previous source) and omitted while unknown. HLS variant playlists are recognized as HLS if no format is known yet.
32
+ - Playback rate (`pr`) was sent as the playback speed while paused or before the first play. It is now `0` if the player is not playing, as required by the specification.
33
+ - State of a previous source (streaming format, startup, buffer starvation, encoded bitrate and measured throughput) was reused after loading another source into the same player. It is now reset on `SourceUnloaded`.
34
+ - package.json description referred to the wrong product.
35
+
10
36
  ## [0.6.0] - 2026-07-29
11
37
  ### Changed
12
38
  - The published npm package now only ships `dist/js` plus the top-level docs (`README.md`, `CHANGELOG.md`, `LICENSE`) and required package metadata (e.g. `package.json`). Local development files are no longer part of the tarball.
@@ -43,7 +69,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
43
69
  ### Added
44
70
  - Initial CMCD release (Beta)
45
71
 
46
- [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.0...HEAD
72
+ [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.2...HEAD
73
+ [0.6.2]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.1...v0.6.2
74
+ [0.6.1]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.0...v0.6.1
47
75
  [0.6.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.5.0...v0.6.0
48
76
  [0.5.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...v0.5.0
49
77
  [0.4.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.3.0...v0.4.0
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Bitmovin Player CMCD Integration
2
2
 
3
- This project adds support for the Common Media Client Data (CMCD) plugin. Please find more information about the Consumer Technology Association (CTA) Specification in https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf
3
+ This project adds support for Common Media Client Data (CMCD) to the Bitmovin Player.
4
+ It implements CMCD v1 as defined in the Consumer Technology Association (CTA) specification CTA-5004, available from CTA at https://www.cta.tech/standards/wave-common-media-client-data/.
4
5
 
5
6
  ## Install
6
7
  Install with npm:
package/dist/js/Cmcd.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * Enums, keys, classes for CMCD v1.0 support according to
3
- * https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf
2
+ * CMCD data model and encoding, CMCD v1 according to CTA-5004.
4
3
  *
5
4
  * Limitation:
6
5
  * - JSON is not supported, only HTTP Headers and Query Args.
@@ -36,8 +35,7 @@ export declare enum CmcdVersionNumbers {
36
35
  v1 = 1
37
36
  }
38
37
  /**
39
- * Enum containing all CMCD keys as defined in
40
- * https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf
38
+ * Enum containing all CMCD keys as defined in CTA-5004
41
39
  */
42
40
  export declare enum CmcdKeysToken {
43
41
  EncodedBitrate = "br",
@@ -65,292 +63,75 @@ export declare enum CmcdHeaderType {
65
63
  Status = "CMCD-Status",
66
64
  Session = "CMCD-Session"
67
65
  }
68
- type IntegerKbps = number;
69
- type IntegerMilliSecs = number;
70
- export declare function cmcdDataToHeader(data: CmcdBase[]): CmcdHeaders;
71
- export declare function cmcdDataToUrlParameter(data: CmcdBase[]): string;
72
- export declare function cmcdDataToJson(data: CmcdBase[]): string;
73
- export declare abstract class CmcdBase {
74
- readonly value: unknown;
75
- abstract readonly key: CmcdKeysToken | string;
76
- abstract readonly type: CmcdHeaderType;
77
- constructor(value: unknown);
78
- /**
79
- * 2. The key and value MUST be separated by an equals sign Unicode 0x3D.
80
- *
81
- * @returns
82
- */
83
- keyValuePairToString(): string;
84
- }
85
- /**
86
- * The encoded bitrate of the audio or video object
87
- * being requested. This may not be known precisely
88
- * by the player; however, it MAY be estimated based
89
- * upon playlist/manifest declarations. If the playlist
90
- * declares both peak and average bitrate values, the
91
- * peak value should be transmitted.
92
- */
93
- export declare class CmcdEncodedBitrate extends CmcdBase {
94
- readonly key = CmcdKeysToken.EncodedBitrate;
95
- readonly type = CmcdHeaderType.Object;
96
- constructor(value: IntegerKbps);
97
- }
98
- /**
99
- * The buffer length associated with the media object
100
- * being requested. This value MUST be rounded to
101
- * the nearest 100 ms. This key SHOULD only be sent
102
- * with an object type of ‘a’, ‘v’ or ‘av’.
103
- */
104
- export declare class CmcdBufferLength extends CmcdBase {
105
- readonly key = CmcdKeysToken.BufferLength;
106
- readonly type = CmcdHeaderType.Request;
107
- constructor(value: IntegerMilliSecs);
108
- }
109
- /**
110
- * Key is included without a value if the buffer was
111
- * starved at some point between the prior request
112
- * and this object request, resulting in the player
113
- * being in a rebuffering state and the video or audio
114
- * playback being stalled. This key MUST NOT be sent
115
- * if the buffer was not starved since the prior
116
- * request.
117
- * If the object type ‘ot’ key is sent along with this
118
- * key, then the ‘bs’ key refers to the buffer
119
- * associated with the particular object type. If no
120
- * object type is communicated, then the buffer state
121
- * applies to the current session.
122
- */
123
- export declare class CmcdBufferStarvation extends CmcdBase {
124
- readonly key = CmcdKeysToken.BufferStarvation;
125
- readonly type = CmcdHeaderType.Status;
126
- constructor(value: boolean);
127
- }
128
- /**
129
- * A unique string identifying the current content.
130
- * Maximum length is 64 characters. This value is
131
- * consistent across multiple different sessions and
132
- * devices and is defined and updated at the
133
- * discretion of the service provider.
134
- */
135
- export declare class CmcdContentId extends CmcdBase {
136
- readonly key = CmcdKeysToken.ContentId;
137
- readonly type = CmcdHeaderType.Session;
138
- constructor(value: string);
139
- }
140
- /**
141
- * The playback duration in milliseconds of the object
142
- * being requested. If a partial segment is being
143
- * requested, then this value MUST indicate the
144
- * playback duration of that part and not that of its
145
- * parent segment. This value can be an
146
- * approximation of the estimated duration if the
147
- * explicit value is not known.
148
- */
149
- export declare class CmcdObjectDuration extends CmcdBase {
150
- readonly key = CmcdKeysToken.ObjectDuration;
151
- readonly type = CmcdHeaderType.Object;
152
- constructor(value: IntegerMilliSecs);
153
- }
154
- /**
155
- * Deadline from the request time until the first
156
- * sample of this Segment/Object needs to be
157
- * available in order to not create a buffer underrun
158
- * or any other playback problems. This value MUST
159
- * be rounded to the nearest 100ms. For a playback
160
- * rate of 1, this may be equivalent to the player’s
161
- * remaining buffer length.
162
- */
163
- export declare class CmcdDeadline extends CmcdBase {
164
- readonly key = CmcdKeysToken.Deadline;
165
- readonly type = CmcdHeaderType.Request;
166
- constructor(value: IntegerMilliSecs);
167
- }
168
- /**
169
- * The throughput between client and server, as
170
- * measured by the client and MUST be rounded to
171
- * the nearest 100 kbps. This value, however derived,
172
- * SHOULD be the value that the client is using to
173
- * make its next Adaptive Bitrate switching decision.
174
- * If the client is connected to multiple servers
175
- * concurrently, it must take care to report only the
176
- * throughput measured against the receiving server.
177
- * If the client has multiple concurrent connections to
178
- * the server, then the intent is that this value
179
- * communicates the aggregate throughput the client
180
- * sees across all those connections.
181
- */
182
- export declare class CmcdMeasuredThroughput extends CmcdBase {
183
- readonly key = CmcdKeysToken.MeasuredThroughput;
184
- readonly type = CmcdHeaderType.Request;
185
- constructor(value: IntegerKbps);
186
- }
187
- /**
188
- * Relative path of the next object to be requested.
189
- * This can be used to trigger pre-fetching by the
190
- * CDN. This MUST be a path relative to the current
191
- * request. This string MUST be URLEncoded [5]. The
192
- * client SHOULD NOT depend upon any pre-fetch
193
- * action being taken - it is merely a request for such
194
- * a pre-fetch to take place.
195
- */
196
- export declare class CmcdNextObjectRequest extends CmcdBase {
197
- readonly key = CmcdKeysToken.NextObjectRequest;
198
- readonly type = CmcdHeaderType.Request;
199
- constructor(value: string);
200
- }
201
- /**
202
- * If the next request will be a partial object request,
203
- * then this string denotes the byte range to be
204
- * requested. If the ‘nor’ field is not set, then the
205
- * object is assumed to match the object currently
206
- * being requested. The client SHOULD NOT depend
207
- * upon any pre-fetch action being taken – it is
208
- * merely a request for such a pre-fetch to take place.
209
- * Formatting is similar to the HTTP Range header,
210
- * except that the unit MUST be ‘byte’, the ‘Range:’
211
- * prefix is NOT required and specifying multiple
212
- * ranges is NOT allowed. Valid combinations are:
213
- * - "<range-start>-"
214
- * - "<range-start>-<range-end>"
215
- * - "-<suffix-length>"
216
- */
217
- export declare class CmcdNextRangeRequest extends CmcdBase {
218
- readonly key = CmcdKeysToken.NextRangeRequest;
219
- readonly type = CmcdHeaderType.Request;
220
- constructor(value: string);
221
- }
222
- /**
223
- * The media type of the current object being
224
- * requested:
225
- * - m = text file, such as a manifest or playlist
226
- * - a = audio only
227
- * - v = video only
228
- * - av = muxed audio and video
229
- * - i = init segment
230
- * - c = caption or subtitle
231
- * - tt = ISOBMFF timed text track
232
- * - k = cryptographic key, license or certificate.
233
- * - o = other
234
- *
235
- * If the object type being requested is unknown,
236
- * then this key MUST NOT be used.
237
- */
238
- export declare class CmcdObjectType extends CmcdBase {
239
- readonly key = CmcdKeysToken.ObjectType;
240
- readonly type = CmcdHeaderType.Object;
241
- constructor(value: CmcdObjectTypeToken);
242
- keyValuePairToString(): string;
243
- }
244
- /**
245
- * 1 if real-time, 2 if double speed, 0 if not playing.
246
- * SHOULD only be sent if not equal to 1.
247
- */
248
- export declare class CmcdPlaybackRate extends CmcdBase {
249
- readonly key = CmcdKeysToken.PlaybackRate;
250
- readonly type = CmcdHeaderType.Session;
251
- constructor(value: number);
252
- keyValuePairToString(): string;
253
- }
254
- /**
255
- * The requested maximum throughput that the
256
- * client considers sufficient for delivery of the asset.
257
- * Values MUST be rounded to the nearest 100kbps.
258
- * For example, a client would indicate that the
259
- * current segment, encoded at 2Mbps, is to be
260
- * delivered at no more than 10Mbps, by using
261
- * rtp=10000.
262
- * Note: This can benefit clients by preventing buffer
263
- * saturation through over-delivery and can also
264
- * deliver a community benefit through fair-share
265
- * delivery. The concept is that each client receives
266
- * the throughput necessary for great performance,
267
- * but no more. The CDN may not support the rtp
268
- * feature.
269
- */
270
- export declare class CmcdRequestedMaximumThroughput extends CmcdBase {
271
- readonly key = CmcdKeysToken.RequestedMaximumThroughput;
272
- readonly type = CmcdHeaderType.Status;
273
- constructor(value: number);
274
- }
275
- /**
276
- * The streaming format that defines the current
277
- * request.
278
- * - d = MPEG DASH
279
- * - h = HTTP Live Streaming (HLS)
280
- * - s = Smooth Streaming
281
- * - o = other
282
- *
283
- * If the streaming format being requested is
284
- * unknown, then this key MUST NOT be used.
285
- */
286
- export declare class CmcdStreamingFormat extends CmcdBase {
287
- readonly key = CmcdKeysToken.StreamingFormat;
288
- readonly type = CmcdHeaderType.Session;
289
- constructor(value: CmcdStreamingFormatToken);
290
- keyValuePairToString(): string;
291
- }
292
- /**
293
- * A GUID identifying the current playback session. A
294
- * playback session typically ties together segments
295
- * belonging to a single media asset. Maximum length
296
- * is 64 characters. It is RECOMMENDED to conform
297
- * to the UUID specification [7].
298
- */
299
- export declare class CmcdSessionId extends CmcdBase {
300
- readonly key = CmcdKeysToken.SessionId;
301
- readonly type = CmcdHeaderType.Session;
302
- constructor(value: string);
303
- }
304
66
  /**
305
- * - v = all segments are available – e.g., VOD
306
- * - l = segments become available over time – e.g.,
307
- * LIVE
308
- */
309
- export declare class CmcdStreamType extends CmcdBase {
310
- readonly key = CmcdKeysToken.StreamType;
311
- readonly type = CmcdHeaderType.Session;
312
- constructor(value: CmcdStreamTypeToken);
313
- keyValuePairToString(): string;
314
- }
315
- /**
316
- * Key is included without a value if the object is
317
- * needed urgently due to startup, seeking or
318
- * recovery after a buffer-empty event. The media
319
- * SHOULD not be rendering when this request is
320
- * made. This key MUST not be sent if it is FALSE.
321
- */
322
- export declare class CmcdStartup extends CmcdBase {
323
- readonly key = CmcdKeysToken.Startup;
324
- readonly type = CmcdHeaderType.Request;
325
- constructor(value: boolean);
326
- keyValuePairToString(): string;
327
- }
328
- /**
329
- * The highest bitrate rendition in the manifest or
330
- * playlist that the client is allowed to play, given
331
- * current codec, licensing and sizing constraints.
332
- */
333
- export declare class CmcdTopBitrate extends CmcdBase {
334
- readonly key = CmcdKeysToken.TopBitrate;
335
- readonly type = CmcdHeaderType.Object;
336
- constructor(value: IntegerKbps);
337
- }
338
- /**
339
- * The version of this specification used for
340
- * interpreting the defined key names and values. If
341
- * this key is omitted, the client and server MUST
342
- * interpret the values as being defined by version 1.
343
- * Client SHOULD omit this field if the version is 1.
344
- */
345
- export declare class CmcdVersion extends CmcdBase {
346
- readonly key = CmcdKeysToken.CmcdVersion;
347
- readonly type = CmcdHeaderType.Session;
348
- constructor(value: CmcdVersionNumbers);
349
- keyValuePairToString(): string;
350
- }
351
- export declare class CmcdCustomKey extends CmcdBase {
67
+ * CMCD data of one request. Values are unrounded and unencoded; the encoder applies the rules of the
68
+ * key table. `undefined` keys are not sent.
69
+ */
70
+ export interface CmcdData {
71
+ /** Encoded bitrate in kbps */
72
+ br?: number;
73
+ /** Buffer length in ms */
74
+ bl?: number;
75
+ /** Buffer starvation since the prior request */
76
+ bs?: boolean;
77
+ /** Content id, max. 64 characters */
78
+ cid?: string;
79
+ /** Object duration in ms */
80
+ d?: number;
81
+ /** Deadline in ms */
82
+ dl?: number;
83
+ /** Measured throughput in kbps */
84
+ mtp?: number;
85
+ /** Next object request, path relative to the current request */
86
+ nor?: string;
87
+ /** Next range request, e.g. `12323-48763` */
88
+ nrr?: string;
89
+ /** Object type */
90
+ ot?: CmcdObjectTypeToken;
91
+ /** Playback rate, 0 if not playing */
92
+ pr?: number;
93
+ /** Requested maximum throughput in kbps */
94
+ rtp?: number;
95
+ /** Streaming format */
96
+ sf?: CmcdStreamingFormatToken;
97
+ /** Session id, max. 64 characters */
98
+ sid?: string;
99
+ /** Stream type */
100
+ st?: CmcdStreamTypeToken;
101
+ /** Startup, seek or recovery after a buffer-empty event */
102
+ su?: boolean;
103
+ /** Top bitrate in kbps */
104
+ tb?: number;
105
+ /** CMCD version */
106
+ v?: CmcdVersionNumbers;
107
+ }
108
+ type CmcdValueType = 'integer' | 'decimal' | 'string' | 'token' | 'boolean';
109
+ export interface CmcdKeyInfo {
110
+ header: CmcdHeaderType;
111
+ type: CmcdValueType;
112
+ /** Rounds to a multiple of this value */
113
+ round?: number;
114
+ /** Value (after rounding) that is not sent */
115
+ omit?: number | boolean;
116
+ /** Value is URL encoded before serialization */
117
+ urlEncode?: boolean;
118
+ }
119
+ /** Keys of a CMCD version. Keys without an entry are not sent. */
120
+ export type CmcdKeyTable = {
121
+ [K in keyof CmcdData]?: CmcdKeyInfo;
122
+ };
123
+ export declare const CMCD_V1_KEYS: CmcdKeyTable;
124
+ export declare function cmcdDataToHeader(data: CmcdData, customKeys?: CmcdCustomKey[]): CmcdHeaders;
125
+ export declare function cmcdDataToUrlParameter(data: CmcdData, customKeys?: CmcdCustomKey[]): string;
126
+ export declare class CmcdCustomKey {
352
127
  readonly key: string;
128
+ readonly value: string | number;
353
129
  readonly type: CmcdHeaderType;
354
130
  constructor(key: string, value: string | number, headerType?: CmcdHeaderType);
131
+ /**
132
+ * @deprecated Will be removed. Encoding is done for all keys of a request at once.
133
+ * @returns The CMCD v1 key-value pair, or an empty string if the key is not sent.
134
+ */
135
+ keyValuePairToString(): string;
355
136
  }
356
137
  export {};
@@ -39,8 +39,11 @@ export declare class CmcdIntegration {
39
39
  private lastMeasuredThroughputAudio;
40
40
  private lastMeasuredThroughputVideo;
41
41
  private manifestType;
42
+ private warnOnce;
42
43
  constructor(config: CmcdConfig);
43
44
  setPlayer(player: PlayerAPI): void;
45
+ /** Clears all state that belongs to the previously loaded source. */
46
+ private resetSourceState;
44
47
  onVideoAdaptation: (data: VideoAdaptationData) => string;
45
48
  onAudioAdaptation: (data: AudioAdaptationData) => string;
46
49
  preprocessHttpRequest: (type: HttpRequestType, request: HttpRequest) => Promise<HttpRequest>;
@@ -48,10 +51,15 @@ export declare class CmcdIntegration {
48
51
  setSessionId(id: string): void;
49
52
  setContentId(id: string): void;
50
53
  private gatherCmcdData;
51
- private getRequestedMaximumThroughput;
54
+ /** `cid` and `sid` are limited to 64 characters. Longer values are omitted, as truncating could cause collisions. */
55
+ private isValidId;
56
+ /**
57
+ * Main manifest requests set the format, so loading another source before the previous one
58
+ * was unloaded is handled. An HLS variant request only sets it if still unknown (media playlist as source).
59
+ * Returns `null` while unknown, as `sf` MUST NOT be sent then.
60
+ */
52
61
  private getStreamingType;
53
62
  private getObjectType;
54
- private getAudioSegmentRequestSpecificData;
55
- private getVideoSegmentRequestSpecificData;
56
- private getNextObjectAndObjectDurationCmcdData;
63
+ private addSegmentRequestSpecificData;
64
+ private addNextObjectAndObjectDuration;
57
65
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns a function that logs each distinct message only once, to avoid a warning per request.
3
+ * Each returned function has its own memory, so callers can choose the scope.
4
+ */
5
+ export declare function createWarnOnce(): (message: string) => void;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Serializer for the subset of Structured Field Values (RFC 8941) that CMCD uses.
3
+ *
4
+ * The `serialize*` functions throw a `TypeError` or `RangeError` for values that RFC 8941 cannot represent.
5
+ */
6
+ /** Marks a string as Token, so it is serialized without quotes. */
7
+ export declare class SfToken {
8
+ readonly value: string;
9
+ constructor(value: string);
10
+ }
11
+ export type SfBareItem = number | string | boolean | SfToken;
12
+ export interface SfParameters {
13
+ [key: string]: SfBareItem;
14
+ }
15
+ export interface SfItem {
16
+ value: SfBareItem;
17
+ params?: SfParameters;
18
+ }
19
+ export type SfInnerList = SfItem[];
20
+ export declare function isInteger(value: number): boolean;
21
+ export declare function serializeInteger(value: number): string;
22
+ /** Rounds to 3 fractional digits, ties to even. */
23
+ export declare function serializeDecimal(value: number): string;
24
+ /** Escapes `\` and `"` and adds quotes, without checking the characters. */
25
+ export declare function quoteString(value: string): string;
26
+ export declare function serializeString(value: string): string;
27
+ export declare function serializeToken(value: string): string;
28
+ export declare function serializeBoolean(value: boolean): string;
29
+ export declare function serializeKey(key: string): string;
30
+ /** Numbers are serialized as Integer if integral, otherwise as Decimal. */
31
+ export declare function serializeBareItem(value: SfBareItem): string;
32
+ export declare function serializeParameters(params?: SfParameters): string;
33
+ export declare function serializeItem(item: SfItem): string;
34
+ export declare function serializeInnerList(items: SfInnerList): string;
35
+ /** A Dictionary member. Boolean true is serialized as the bare key (plus parameters). */
36
+ export declare function serializeDictionaryMember(key: string, value: SfItem | SfInnerList): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the path of `targetUrl` relative to `baseUrl` (e.g. `../300kbps/segment35.m4v`),
3
+ * including the query of `targetUrl`.
4
+ * Returns `null` if no relative path is possible, i.e. both URLs have a different origin.
5
+ */
6
+ export declare function toRelativeUrl(baseUrl: string, targetUrl: string): string | null;
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BitmovinPlayerIntegrationCmcd=e():(t.bitmovin=t.bitmovin||{},t.bitmovin.player=t.bitmovin.player||{},t.bitmovin.player.integration=t.bitmovin.player.integration||{},t.bitmovin.player.integration.Cmcd=e())}(self,function(){return function(){"use strict";var t={145:function(t,e,r){r.d(e,{$y:function(){return o},CT:function(){return T},II:function(){return u},JP:function(){return a},KQ:function(){return s},Nv:function(){return y},P$:function(){return m},Qf:function(){return j},S5:function(){return h},ST:function(){return i},T:function(){return D},W1:function(){return P},Wf:function(){return R},X5:function(){return v},XO:function(){return c},Xk:function(){return g},YM:function(){return E},Yj:function(){return S},e$:function(){return b},fB:function(){return k},hU:function(){return A},nd:function(){return M},o5:function(){return O},p$:function(){return x},w6:function(){return q},xq:function(){return I}});var n,i,u,o,s,a,c,l=(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)});function p(t){return t.sort(function(t,e){return t.key.localeCompare(e.key)}).filter(function(t){return t.keyValuePairToString()})}function h(t){var e=p(t),r=e.filter(function(t){return t.type===c.Request}).map(function(t){return t.keyValuePairToString()}).join(","),n=e.filter(function(t){return t.type===c.Object}).map(function(t){return t.keyValuePairToString()}).join(","),i=e.filter(function(t){return t.type===c.Status}).map(function(t){return t.keyValuePairToString()}).join(","),u=e.filter(function(t){return t.type===c.Session}).map(function(t){return t.keyValuePairToString()}).join(","),o={};return r&&(o[c.Request]=r),n&&(o[c.Object]=n),i&&(o[c.Status]=i),u&&(o[c.Session]=u),o}function y(t){var e=p(t).map(function(t){return t.keyValuePairToString()}).join(",");return"CMCD=".concat(encodeURIComponent(e))}!function(t){t.AudioOnly="a",t.VideoOnly="v",t.MuxedVideoAudio="av",t.ManifestOrPlaylistTextFile="m",t.InitSegment="i",t.CaptionOrSubtitle="c",t.TimedTextTrack="tt",t.CryptographicKeyOrLicenseOrCertificate="k",t.Other="o"}(i||(i={})),function(t){t.MpegDash="d",t.Hls="h",t.Smooth="s",t.Other="o"}(u||(u={})),function(t){t.Vod="v",t.Live="l"}(o||(o={})),function(t){t[t.v1=1]="v1"}(s||(s={})),function(t){t.EncodedBitrate="br",t.BufferLength="bl",t.BufferStarvation="bs",t.ContentId="cid",t.ObjectDuration="d",t.Deadline="dl",t.MeasuredThroughput="mtp",t.NextObjectRequest="nor",t.NextRangeRequest="nrr",t.ObjectType="ot",t.PlaybackRate="pr",t.RequestedMaximumThroughput="rtp",t.StreamingFormat="sf",t.SessionId="sid",t.StreamType="st",t.Startup="su",t.TopBitrate="tb",t.CmcdVersion="v"}(a||(a={})),function(t){t.Object="CMCD-Object",t.Request="CMCD-Request",t.Status="CMCD-Status",t.Session="CMCD-Session"}(c||(c={}));var f,d=function(){function t(t){this.value=t}return t.prototype.keyValuePairToString=function(){return"string"==typeof this.value?this.value?"".concat(this.key,"=").concat((t=this.value,e=/"/g,r=/\\/g,'"'.concat(t.replace(r,"\\\\").replace(e,'\\"'),'"'))):"":"boolean"==typeof this.value&&!0===this.value?"".concat(this.key):"".concat(this.key,"=").concat(this.value);var t,e,r},t}(),v=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.EncodedBitrate,r.type=c.Object,r}return l(e,t),e}(d),S=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.BufferLength,r.type=c.Request,r}return l(e,t),e}(d),g=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.BufferStarvation,r.type=c.Status,r}return l(e,t),e}(d),T=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ContentId,r.type=c.Session,r}return l(e,t),e}(d),m=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ObjectDuration,r.type=c.Object,r}return l(e,t),e}(d),b=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.Deadline,r.type=c.Request,r}return l(e,t),e}(d),O=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.MeasuredThroughput,r.type=c.Request,r}return l(e,t),e}(d),k=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.NextObjectRequest,r.type=c.Request,r}return l(e,t),e}(d),A=(l(function(t){var e=f.call(this,t)||this;return e.key=a.NextRangeRequest,e.type=c.Request,e},f=d),function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ObjectType,r.type=c.Object,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d)),M=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.PlaybackRate,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return 1===this.value?"":"".concat(this.key,"=").concat(this.value)},e}(d),R=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.RequestedMaximumThroughput,r.type=c.Status,r}return l(e,t),e}(d),I=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamingFormat,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),x=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.SessionId,r.type=c.Session,r}return l(e,t),e}(d),E=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamType,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),D=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.Startup,r.type=c.Request,r}return l(e,t),e.prototype.keyValuePairToString=function(){return!0===this.value?"".concat(this.key):""},e}(d),P=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.TopBitrate,r.type=c.Object,r}return l(e,t),e}(d),q=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.CmcdVersion,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return this.value===s.v1?"":"".concat(this.key,"=").concat(this.value)},e}(d),j=function(t){function e(e,r,n){var i=t.call(this,r)||this,u=e.match(/^(.*-)(.*)$/);if(!u||!u[2])throw new Error("Custom key names MUST carry a hyphenated prefix (and SHOULD use a reverse-DNS syntax)");return i.key=e,i.type=Object.values(c).includes(n)?n:null,i}return l(e,t),e}(d)},779:function(t,e,r){r.r(e),r.d(e,{CmcdIntegration:function(){return o},CustomKey:function(){return n.Qf},HeaderType:function(){return n.XO}});var n=r(145),i=function(){return i=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)},u=function(t,e,r){if(r||2===arguments.length)for(var n,i=0,u=e.length;i<u;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))},o=function(){function t(t){var e=this;if(this.onVideoAdaptation=function(t){return e.currentVideoQuality=t.representations.filter(function(e){return e.id===t.suggested})[0],t.suggested},this.onAudioAdaptation=function(t){return e.currentAudioQuality=t.representations.filter(function(e){return e.id===t.suggested})[0],t.suggested},this.preprocessHttpRequest=function(t,r){var o=e.gatherCmcdData(t,r);if(e.useQueryArgs)r.url=function(t,e){var r=t.indexOf("?"),n=t.indexOf("#"),i=-1===n?"":t.slice(n),o=-1===n?t:t.slice(0,n);if(-1===r||-1!==n&&r>n)return"".concat(o,"?").concat(e).concat(i);var s=o.slice(0,r),a=o.slice(r+1).split("&").filter(function(t){return""!==t&&"CMCD"!==t&&!t.startsWith("CMCD=")}),c=u(u([],a,!0),[e],!1).join("&");return"".concat(s,"?").concat(c).concat(i)}(r.url,(0,n.Nv)(o));else{var s=(0,n.S5)(o);r.headers=i(i({},r.headers),s)}return Promise.resolve(r)},this.preprocessHttpResponse=function(t,r){var n,i,u=r.elapsedTime,o=r.length;if(!u||!o)return Promise.resolve(r);var s=o/u/1e3;return t===((null===(n=e.player)||void 0===n?void 0:n.exports.HttpRequestType.MEDIA_AUDIO)||"media/audio")&&(e.lastMeasuredThroughputAudio=Math.round(100*s)/100),t===((null===(i=e.player)||void 0===i?void 0:i.exports.HttpRequestType.MEDIA_VIDEO)||"media/video")&&(e.lastMeasuredThroughputVideo=Math.round(100*s)/100),Promise.resolve(r)},this.useQueryArgs=t.useQueryArgs||!1,this.sessionId=t.sessionId||"",this.contentId=t.contentId||"",this.customKeys=t.customKeys||[],this.stalledSinceLastRequest=!1,this.currentVideoQuality=null,this.currentAudioQuality=null,this.isSeekingOrTimeshiftingOrStartup=!0,this.lastMeasuredThroughputAudio=0,this.lastMeasuredThroughputVideo=0,this.manifestType=null,!1===this.useQueryArgs&&this.customKeys.length>0){var r=this.customKeys.filter(function(t){return null===t.type}).map(function(t){return t.key});if(r.length>0)throw new Error("All custom keys must have an HTTP header type configured if HTTP header mode is used (`CmcdConfig.useQueryArgs = false`), but is missing for "+r.join(", "))}}return t.prototype.setPlayer=function(t){var e=this;this.player=t,this.player.on(t.exports.PlayerEvent.StallStarted,function(){e.stalledSinceLastRequest=!0,e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.StallEnded,function(){return e.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(t.exports.PlayerEvent.Seek,function(){return e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.Seeked,function(){return e.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(t.exports.PlayerEvent.TimeShift,function(){return e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.TimeShifted,function(){return e.isSeekingOrTimeshiftingOrStartup=!1})},t.prototype.setSessionId=function(t){this.sessionId=t},t.prototype.setContentId=function(t){this.contentId=t},t.prototype.gatherCmcdData=function(t,e){var r,i;if(!this.player)throw new Error("Bitmovin Player not provided!");var u=[];u.push(new n.w6(n.KQ.v1)),u.push(new n.YM(this.player.isLive()?n.$y.Live:n.$y.Vod)),u.push(new n.nd(this.player.getPlaybackSpeed())),u.push(this.getObjectType(t)),u.push(this.getStreamingType(t)),this.contentId&&u.push(new n.CT(this.contentId)),this.sessionId&&u.push(new n.p$(this.sessionId)),this.isSeekingOrTimeshiftingOrStartup&&u.push(new n.T(!0)),(this.stalledSinceLastRequest||this.player.isStalled())&&(u.push(new n.Xk(!0)),this.stalledSinceLastRequest=!1),t===(null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_AUDIO)?u=u.concat(this.getAudioSegmentRequestSpecificData(e)):t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MEDIA_VIDEO)&&(u=u.concat(this.getVideoSegmentRequestSpecificData(e))),u.concat(this.getRequestedMaximumThroughput(u));for(var o=0,s=this.customKeys;o<s.length;o++){var a=s[o];u.push(a)}return u},t.prototype.getRequestedMaximumThroughput=function(t){var e=t.find(function(t){return t.key===n.JP.EncodedBitrate}),r=t.find(function(t){return t.key===n.JP.ObjectDuration}),i=Boolean(t.find(function(t){return t.key===n.JP.ObjectDuration})),u=t.find(function(t){return t.key===n.JP.Startup}),o=u&&!u.value;if(e&&r&&!i&&!o){var s=1e3*Number(r.value),a=Number(e.value)*(s/2);return[new n.Wf(a)]}return[]},t.prototype.getStreamingType=function(t){var e,r,i;return this.manifestType||(t===(null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MANIFEST_DASH)?this.manifestType=n.II.MpegDash:t===(null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MANIFEST_HLS_MASTER)?this.manifestType=n.II.Hls:t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MANIFEST_SMOOTH)?this.manifestType=n.II.Smooth:this.manifestType=n.II.Other),new n.xq(this.manifestType)},t.prototype.getObjectType=function(t){var e,r,i,u,o,s,a,c,l,p,h,y,f,d,v,S;switch(t){case null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MEDIA_AUDIO:S=new n.hU(n.ST.AudioOnly);break;case null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_VIDEO:S=new n.hU(n.ST.VideoOnly);break;case null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.DRM_CERTIFICATE_FAIRPLAY:case null===(u=this.player)||void 0===u?void 0:u.exports.HttpRequestType.DRM_LICENSE_CLEARKEY:case null===(o=this.player)||void 0===o?void 0:o.exports.HttpRequestType.DRM_LICENSE_FAIRPLAY:case null===(s=this.player)||void 0===s?void 0:s.exports.HttpRequestType.DRM_LICENSE_PLAYREADY:case null===(a=this.player)||void 0===a?void 0:a.exports.HttpRequestType.DRM_LICENSE_WIDEVINE:case null===(c=this.player)||void 0===c?void 0:c.exports.HttpRequestType.KEY_HLS_AES:S=new n.hU(n.ST.CryptographicKeyOrLicenseOrCertificate);break;case null===(l=this.player)||void 0===l?void 0:l.exports.HttpRequestType.MANIFEST_ADS:case null===(p=this.player)||void 0===p?void 0:p.exports.HttpRequestType.MANIFEST_DASH:case null===(h=this.player)||void 0===h?void 0:h.exports.HttpRequestType.MANIFEST_HLS_MASTER:case null===(y=this.player)||void 0===y?void 0:y.exports.HttpRequestType.MANIFEST_HLS_VARIANT:case null===(f=this.player)||void 0===f?void 0:f.exports.HttpRequestType.MANIFEST_SMOOTH:S=new n.hU(n.ST.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:S=new n.hU(n.ST.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:S=new n.hU(n.ST.CaptionOrSubtitle);break;default:S=new n.hU(n.ST.Other)}return S},t.prototype.getAudioSegmentRequestSpecificData=function(t){var e,r=[];if(this.currentAudioQuality&&this.currentAudioQuality.bandwidth&&r.push(new n.X5(Math.round(this.currentAudioQuality.bandwidth/1e3))),this.lastMeasuredThroughputAudio&&r.push(new n.o5(this.lastMeasuredThroughputAudio)),!this.player)return r;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Audio);if(i.targetLevel>0){r.push(new n.Yj(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.e$(1e3*u))}var o=this.player.getAvailableAudioQualities().reduce(function(t,e){return Math.max(t,e.bitrate)},0)/1e3;if(o>0&&r.push(new n.W1(o)),this.currentVideoQuality)try{var s=this.player.getAvailableSegments();for(var a in s)if(a.startsWith("video/")){var c=s[a][this.currentVideoQuality.id];r=r.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing audio segments:",t)}return r},t.prototype.getVideoSegmentRequestSpecificData=function(t){var e,r=[];if(this.currentVideoQuality&&this.currentVideoQuality.bandwidth&&r.push(new n.X5(Math.round(this.currentVideoQuality.bandwidth/1e3))),this.lastMeasuredThroughputVideo&&r.push(new n.o5(this.lastMeasuredThroughputVideo)),!this.player)return r;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Video);if(i.targetLevel>0){r.push(new n.Yj(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.e$(1e3*u))}var o=this.player.getAvailableVideoQualities().reduce(function(t,e){return Math.max(t,e.bitrate)},0)/1e3;if(o>0&&r.push(new n.W1(o)),this.currentVideoQuality)try{var s=this.player.getAvailableSegments();for(var a in s)if(a.startsWith("video/")){var c=s[a][this.currentVideoQuality.id];r=r.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing video segments:",t)}return r},t.prototype.getNextObjectAndObjectDurationCmcdData=function(t,e){var r=[],i=t.findIndex(function(t){return t.url===e});if(i>-1){var u=t[i];if(Number.isNaN(u.duration)||r.push(new n.P$(1e3*Number(u.duration))),i+1<t.length){var o=t[i+1];o.url&&r.push(new n.fB(o.url))}}return r},t}()}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var u=e[n]={exports:{}};return t[n](u,u.exports,r),u.exports}return r.d=function(t,e){if(Array.isArray(e))for(var n=0;n<e.length;){var i=e[n++],u=e[n++];r.o(t,i)?0===u&&n++:0===u?Object.defineProperty(t,i,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,i,{enumerable:!0,get:u})}else for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(145),r(779)}()});
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.BitmovinPlayerIntegrationCmcd=t():(e.bitmovin=e.bitmovin||{},e.bitmovin.player=e.bitmovin.player||{},e.bitmovin.player.integration=e.bitmovin.player.integration||{},e.bitmovin.player.integration.Cmcd=t())}(self,function(){return function(){"use strict";var e={967:function(e,t,r){r.d(t,{Qf:function(){return O},XO:function(){return p},JP:function(){return c},ST:function(){return s},$y:function(){return u},II:function(){return a},KQ:function(){return l},S5:function(){return m},Nv:function(){return T}});var n=/^[a-zA-Z*][!#$%&'*+\-.^_`|~0-9a-zA-Z:/]*$/,i=/^[\x20-\x7e]*$/;function o(e){return'"'.concat(e.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),'"')}var s,a,u,l,c,p,d=r(602);!function(e){e.AudioOnly="a",e.VideoOnly="v",e.MuxedVideoAudio="av",e.ManifestOrPlaylistTextFile="m",e.InitSegment="i",e.CaptionOrSubtitle="c",e.TimedTextTrack="tt",e.CryptographicKeyOrLicenseOrCertificate="k",e.Other="o"}(s||(s={})),function(e){e.MpegDash="d",e.Hls="h",e.Smooth="s",e.Other="o"}(a||(a={})),function(e){e.Vod="v",e.Live="l"}(u||(u={})),function(e){e[e.v1=1]="v1"}(l||(l={})),function(e){e.EncodedBitrate="br",e.BufferLength="bl",e.BufferStarvation="bs",e.ContentId="cid",e.ObjectDuration="d",e.Deadline="dl",e.MeasuredThroughput="mtp",e.NextObjectRequest="nor",e.NextRangeRequest="nrr",e.ObjectType="ot",e.PlaybackRate="pr",e.RequestedMaximumThroughput="rtp",e.StreamingFormat="sf",e.SessionId="sid",e.StreamType="st",e.Startup="su",e.TopBitrate="tb",e.CmcdVersion="v"}(c||(c={})),function(e){e.Object="CMCD-Object",e.Request="CMCD-Request",e.Status="CMCD-Status",e.Session="CMCD-Session"}(p||(p={}));var y={br:{header:p.Object,type:"integer",round:1},bl:{header:p.Request,type:"integer",round:100},bs:{header:p.Status,type:"boolean",omit:!1},cid:{header:p.Session,type:"string"},d:{header:p.Object,type:"integer",round:1},dl:{header:p.Request,type:"integer",round:100},mtp:{header:p.Request,type:"integer",round:100,omit:0},nor:{header:p.Request,type:"string",urlEncode:!0},nrr:{header:p.Request,type:"string"},ot:{header:p.Object,type:"token"},pr:{header:p.Session,type:"decimal",omit:1},rtp:{header:p.Status,type:"integer",round:100,omit:0},sf:{header:p.Session,type:"token"},sid:{header:p.Session,type:"string"},st:{header:p.Session,type:"token"},su:{header:p.Request,type:"boolean",omit:!1},tb:{header:p.Object,type:"integer",round:1},v:{header:p.Session,type:"integer",omit:1}},h=/^[\x20-\x7e]*$/;function f(e,t,r,s){if(void 0===s&&(s=!1),s&&!h.test(e))throw new TypeError("Not a printable ASCII key: ".concat(e));if(r){if(r.round&&(t=Math.round(t/r.round)*r.round),r.urlEncode&&(t=encodeURIComponent(t)),t===r.omit)return null;if("token"===r.type)return"".concat(e,"=").concat(function(e){if("string"!=typeof e||!n.test(e))throw new TypeError("Not a token: ".concat(e));return e}(t))}return""===t?null:!0===t?e:"string"==typeof t?"".concat(e,"=").concat(s?function(e){if("string"!=typeof e||!i.test(e))throw new TypeError("Not a printable ASCII string: ".concat(e));return o(e)}(t):o(t)):"".concat(e,"=").concat(t)}var v=(0,d.C)();function g(e,t,r){for(var n=[],i=function(e,t,i,o){var s=null;try{s=f(e,t,o,r)}catch(t){v("CMCD: '".concat(e,"' is not sent: ").concat(t.message))}null!==s&&n.push({key:e,header:i,member:s})},o=0,s=Object.keys(e);o<s.length;o++){var a=s[o],u=y[a],l=e[a];u&&null!=l&&i(a,l,u.header,u)}for(var c=0,p=t;c<p.length;c++){var d=p[c];i(d.key,d.value,d.type)}return n.sort(function(e,t){return e.key.localeCompare(t.key)})}function S(e){return e.map(function(e){return e.member}).join(",")}function m(e,t){void 0===t&&(t=[]);for(var r=g(e,t,!0),n={},i=function(e){var t=S(r.filter(function(t){return t.header===e}));t&&(n[e]=t)},o=0,s=[p.Request,p.Object,p.Status,p.Session];o<s.length;o++)i(s[o]);return n}function T(e,t){return void 0===t&&(t=[]),"CMCD=".concat(encodeURIComponent(S(g(e,t,!1))))}var O=function(){function e(e,t,r){var n=e.match(/^(.*-)(.*)$/);if(!n||!n[2])throw new Error("Custom key names MUST carry a hyphenated prefix (and SHOULD use a reverse-DNS syntax)");this.key=e,this.value=t,this.type=Object.values(p).includes(r)?r:null}return e.prototype.keyValuePairToString=function(){return f(this.key,this.value)||""},e}()},46:function(e,t,r){r.r(t),r.d(t,{CmcdIntegration:function(){return u},CustomKey:function(){return n.Qf},HeaderType:function(){return n.XO}});var n=r(967),i=function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))},o=r(602),s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},s.apply(this,arguments)},a=function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))},u=function(){function e(e){var t=this;if(this.warnOnce=(0,o.C)(),this.onVideoAdaptation=function(e){return t.currentVideoQuality=e.representations.filter(function(t){return t.id===e.suggested})[0],e.suggested},this.onAudioAdaptation=function(e){return t.currentAudioQuality=e.representations.filter(function(t){return t.id===e.suggested})[0],e.suggested},this.preprocessHttpRequest=function(e,r){var i=t.gatherCmcdData(e,r);try{if(t.useQueryArgs)r.url=function(e,t){var r=e.indexOf("?"),n=e.indexOf("#"),i=-1===n?"":e.slice(n),o=-1===n?e:e.slice(0,n);if(-1===r||-1!==n&&r>n)return"".concat(o,"?").concat(t).concat(i);var s=o.slice(0,r),u=o.slice(r+1).split("&").filter(function(e){return""!==e&&"CMCD"!==e&&!e.startsWith("CMCD=")}),l=a(a([],u,!0),[t],!1).join("&");return"".concat(s,"?").concat(l).concat(i)}(r.url,(0,n.Nv)(i,t.customKeys));else{var o=(0,n.S5)(i,t.customKeys);r.headers=s(s({},r.headers),o)}}catch(e){t.warnOnce("CMCD: data is not sent: ".concat(e))}return Promise.resolve(r)},this.preprocessHttpResponse=function(e,r){var n,i;if(!r)return Promise.resolve(r);var o=r.elapsedTime,s=r.length;if(!o||!s)return Promise.resolve(r);var a=8*s/o/1e3;return e===((null===(n=t.player)||void 0===n?void 0:n.exports.HttpRequestType.MEDIA_AUDIO)||"media/audio")&&(t.lastMeasuredThroughputAudio=Math.round(100*a)/100),e===((null===(i=t.player)||void 0===i?void 0:i.exports.HttpRequestType.MEDIA_VIDEO)||"media/video")&&(t.lastMeasuredThroughputVideo=Math.round(100*a)/100),Promise.resolve(r)},this.useQueryArgs=e.useQueryArgs||!1,this.sessionId=e.sessionId||"",this.contentId=e.contentId||"",this.customKeys=e.customKeys||[],this.resetSourceState(),!1===this.useQueryArgs&&this.customKeys.length>0){var r=this.customKeys.filter(function(e){return null===e.type}).map(function(e){return e.key});if(r.length>0)throw new Error("All custom keys must have an HTTP header type configured if HTTP header mode is used (`CmcdConfig.useQueryArgs = false`), but is missing for "+r.join(", "))}}return e.prototype.setPlayer=function(e){var t=this;this.player=e,this.player.on(e.exports.PlayerEvent.SourceUnloaded,function(){return t.resetSourceState()}),this.player.on(e.exports.PlayerEvent.StallStarted,function(){t.stalledSinceLastRequest=!0,t.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(e.exports.PlayerEvent.StallEnded,function(){return t.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(e.exports.PlayerEvent.Playing,function(){return t.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(e.exports.PlayerEvent.Seek,function(){return t.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(e.exports.PlayerEvent.Seeked,function(){return t.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(e.exports.PlayerEvent.TimeShift,function(){return t.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(e.exports.PlayerEvent.TimeShifted,function(){return t.isSeekingOrTimeshiftingOrStartup=!1})},e.prototype.resetSourceState=function(){this.stalledSinceLastRequest=!1,this.currentVideoQuality=null,this.currentAudioQuality=null,this.isSeekingOrTimeshiftingOrStartup=!0,this.lastMeasuredThroughputAudio=0,this.lastMeasuredThroughputVideo=0,this.manifestType=null},e.prototype.setSessionId=function(e){this.sessionId=e},e.prototype.setContentId=function(e){this.contentId=e},e.prototype.gatherCmcdData=function(e,t){if(!this.player)throw new Error("Bitmovin Player not provided!");var r={v:n.KQ.v1,st:this.player.isLive()?n.$y.Live:n.$y.Vod,pr:this.player.isPlaying()?this.player.getPlaybackSpeed():0,ot:this.getObjectType(e)},i=this.getStreamingType(e);i&&(r.sf=i),this.isValidId(n.JP.ContentId,this.contentId)&&(r.cid=this.contentId),this.isValidId(n.JP.SessionId,this.sessionId)&&(r.sid=this.sessionId);var o=this.isSeekingOrTimeshiftingOrStartup;o&&(r.su=!0);var s=this.stalledSinceLastRequest||this.player.isStalled();return s&&(r.bs=!0,this.stalledSinceLastRequest=!1),e===this.player.exports.HttpRequestType.MEDIA_AUDIO?this.addSegmentRequestSpecificData(r,t,"audio"):e===this.player.exports.HttpRequestType.MEDIA_VIDEO&&this.addSegmentRequestSpecificData(r,t,"video"),o||s||void 0===r.br||(r.rtp=5*r.br),r},e.prototype.isValidId=function(e,t){return!!t&&(t.length<=64||(this.warnOnce("CMCD: '".concat(e,"' value '").concat(t,"' exceeds ").concat(64," characters and is not sent.")),!1))},e.prototype.getStreamingType=function(e){var t,r=null===(t=this.player)||void 0===t?void 0:t.exports.HttpRequestType;return e===(null==r?void 0:r.MANIFEST_DASH)?this.manifestType=n.II.MpegDash:e===(null==r?void 0:r.MANIFEST_HLS_MASTER)?this.manifestType=n.II.Hls:e===(null==r?void 0:r.MANIFEST_SMOOTH)?this.manifestType=n.II.Smooth:e!==(null==r?void 0:r.MANIFEST_HLS_VARIANT)||this.manifestType||(this.manifestType=n.II.Hls),this.manifestType},e.prototype.getObjectType=function(e){var t,r,i,o,s,a,u,l,c,p,d,y,h,f,v;switch(e){case null===(t=this.player)||void 0===t?void 0:t.exports.HttpRequestType.MEDIA_AUDIO:return n.ST.AudioOnly;case null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_VIDEO:return n.ST.VideoOnly;case null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.DRM_CERTIFICATE_FAIRPLAY:case null===(o=this.player)||void 0===o?void 0:o.exports.HttpRequestType.DRM_LICENSE_CLEARKEY:case null===(s=this.player)||void 0===s?void 0:s.exports.HttpRequestType.DRM_LICENSE_FAIRPLAY:case null===(a=this.player)||void 0===a?void 0:a.exports.HttpRequestType.DRM_LICENSE_PLAYREADY:case null===(u=this.player)||void 0===u?void 0:u.exports.HttpRequestType.DRM_LICENSE_WIDEVINE:case null===(l=this.player)||void 0===l?void 0:l.exports.HttpRequestType.KEY_HLS_AES:return n.ST.CryptographicKeyOrLicenseOrCertificate;case null===(c=this.player)||void 0===c?void 0:c.exports.HttpRequestType.MANIFEST_ADS:case null===(p=this.player)||void 0===p?void 0:p.exports.HttpRequestType.MANIFEST_DASH:case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MANIFEST_HLS_MASTER:case null===(y=this.player)||void 0===y?void 0:y.exports.HttpRequestType.MANIFEST_HLS_VARIANT:case null===(h=this.player)||void 0===h?void 0:h.exports.HttpRequestType.MANIFEST_SMOOTH:return n.ST.ManifestOrPlaylistTextFile;case null===(f=this.player)||void 0===f?void 0:f.exports.HttpRequestType.MEDIA_SEGMENTINDEX:return n.ST.InitSegment;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:return n.ST.CaptionOrSubtitle;default:return n.ST.Other}},e.prototype.addSegmentRequestSpecificData=function(e,t,r){if(this.player){var n="audio"===r,i=n?this.currentAudioQuality:this.currentVideoQuality,o=n?this.lastMeasuredThroughputAudio:this.lastMeasuredThroughputVideo;i&&i.bandwidth&&(e.br=Math.round(i.bandwidth/1e3)),o&&(e.mtp=o);var s=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,n?this.player.exports.MediaType.Audio:this.player.exports.MediaType.Video);s.targetLevel>0&&(e.bl=1e3*s.level,e.dl=s.level/this.player.getPlaybackSpeed()*1e3);var a=(n?this.player.getAvailableAudioQualities():this.player.getAvailableVideoQualities()).reduce(function(e,t){return Math.max(e,t.bitrate)},0)/1e3;if(a>0&&(e.tb=a),i)try{var u=this.player.getAvailableSegments();for(var l in u){var c=u[l][i.id];l.startsWith("".concat(r,"/"))&&c&&this.addNextObjectAndObjectDuration(e,c,t.url)}}catch(e){console.error("Error processing ".concat(r," segments:"),e)}}},e.prototype.addNextObjectAndObjectDuration=function(e,t,r){var n=t.findIndex(function(e){return e.url===r});if(n>-1){var o=t[n];if(Number.isFinite(o.duration)&&(e.d=1e3*Number(o.duration)),n+1<t.length){var s=t[n+1],a=s.url?function(e,t){var r,n;try{r=new URL(e),n=new URL(t,r)}catch(e){return null}if(r.origin!==n.origin)return null;for(var o=r.pathname.split("/").slice(0,-1),s=n.pathname.split("/"),a=0;a<o.length&&a<s.length-1&&o[a]===s[a];)a++;var u=new Array(o.length-a).fill(".."),l=i(i([],u,!0),s.slice(a),!0).join("/");return 0===u.length&&l.split("/")[0].includes(":")&&(l="./".concat(l)),"".concat(l).concat(n.search)}(r,s.url):null;a&&(e.nor=a)}}},e}()},602:function(e,t,r){function n(){var e=new Set;return function(t){e.has(t)||(e.add(t),console.warn(t))}}r.d(t,{C:function(){return n}})}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}return r.d=function(e,t){if(Array.isArray(t))for(var n=0;n<t.length;){var i=t[n++],o=t[n++];r.o(e,i)?0===o&&n++:0===o?Object.defineProperty(e,i,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,i,{enumerable:!0,get:o})}else for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(967),r(46)}()});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitmovin/player-web-integration-cmcd",
3
- "version": "0.6.0",
4
- "description": "Conviva analytics integration for the Bitmovin Player",
3
+ "version": "0.6.2",
4
+ "description": "CMCD (CTA-5004) integration for the Bitmovin Player",
5
5
  "types": "dist/js/CmcdIntegration.d.ts",
6
6
  "browser": "dist/js/bitmovin-player-integration-cmcd.js",
7
7
  "main": "dist/js/bitmovin-player-integration-cmcd.js",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "ssh://git@github.com/bitmovin/bitmovin-player-web-integration-cmcd.git"
16
+ "url": "git+https://github.com/bitmovin/bitmovin-player-web-integration-cmcd.git"
17
17
  },
18
18
  "scripts": {
19
19
  "format": "prettier --write src/ test/",