@bitmovin/player-web-integration-cmcd 0.6.1 → 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,18 @@ 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
+
10
22
  ## [0.6.1] - 2026-11-20
11
23
  ### Fixed
12
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.
@@ -57,7 +69,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
57
69
  ### Added
58
70
  - Initial CMCD release (Beta)
59
71
 
60
- [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.1...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
61
74
  [0.6.1]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.0...v0.6.1
62
75
  [0.6.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.5.0...v0.6.0
63
76
  [0.5.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...v0.5.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,298 +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
- keyValuePairToString(): string;
187
- }
188
- /**
189
- * Relative path of the next object to be requested.
190
- * This can be used to trigger pre-fetching by the
191
- * CDN. This MUST be a path relative to the current
192
- * request. This string MUST be URLEncoded [5]. The
193
- * client SHOULD NOT depend upon any pre-fetch
194
- * action being taken - it is merely a request for such
195
- * a pre-fetch to take place.
196
- */
197
- export declare class CmcdNextObjectRequest extends CmcdBase {
198
- readonly key = CmcdKeysToken.NextObjectRequest;
199
- readonly type = CmcdHeaderType.Request;
200
- /**
201
- * @param relativePath Unencoded path relative to the current request, e.g. `../300kbps/segment35.m4v`.
202
- * It is URL encoded here, independent of the query argument encoding of the whole payload.
203
- */
204
- constructor(relativePath: string);
205
- }
206
- /**
207
- * If the next request will be a partial object request,
208
- * then this string denotes the byte range to be
209
- * requested. If the ‘nor’ field is not set, then the
210
- * object is assumed to match the object currently
211
- * being requested. The client SHOULD NOT depend
212
- * upon any pre-fetch action being taken – it is
213
- * merely a request for such a pre-fetch to take place.
214
- * Formatting is similar to the HTTP Range header,
215
- * except that the unit MUST be ‘byte’, the ‘Range:’
216
- * prefix is NOT required and specifying multiple
217
- * ranges is NOT allowed. Valid combinations are:
218
- * - "<range-start>-"
219
- * - "<range-start>-<range-end>"
220
- * - "-<suffix-length>"
221
- */
222
- export declare class CmcdNextRangeRequest extends CmcdBase {
223
- readonly key = CmcdKeysToken.NextRangeRequest;
224
- readonly type = CmcdHeaderType.Request;
225
- constructor(value: string);
226
- }
227
- /**
228
- * The media type of the current object being
229
- * requested:
230
- * - m = text file, such as a manifest or playlist
231
- * - a = audio only
232
- * - v = video only
233
- * - av = muxed audio and video
234
- * - i = init segment
235
- * - c = caption or subtitle
236
- * - tt = ISOBMFF timed text track
237
- * - k = cryptographic key, license or certificate.
238
- * - o = other
239
- *
240
- * If the object type being requested is unknown,
241
- * then this key MUST NOT be used.
242
- */
243
- export declare class CmcdObjectType extends CmcdBase {
244
- readonly key = CmcdKeysToken.ObjectType;
245
- readonly type = CmcdHeaderType.Object;
246
- constructor(value: CmcdObjectTypeToken);
247
- keyValuePairToString(): string;
248
- }
249
- /**
250
- * 1 if real-time, 2 if double speed, 0 if not playing.
251
- * SHOULD only be sent if not equal to 1.
252
- */
253
- export declare class CmcdPlaybackRate extends CmcdBase {
254
- readonly key = CmcdKeysToken.PlaybackRate;
255
- readonly type = CmcdHeaderType.Session;
256
- constructor(value: number);
257
- keyValuePairToString(): string;
258
- }
259
- /**
260
- * The requested maximum throughput that the
261
- * client considers sufficient for delivery of the asset.
262
- * Values MUST be rounded to the nearest 100kbps.
263
- * For example, a client would indicate that the
264
- * current segment, encoded at 2Mbps, is to be
265
- * delivered at no more than 10Mbps, by using
266
- * rtp=10000.
267
- * Note: This can benefit clients by preventing buffer
268
- * saturation through over-delivery and can also
269
- * deliver a community benefit through fair-share
270
- * delivery. The concept is that each client receives
271
- * the throughput necessary for great performance,
272
- * but no more. The CDN may not support the rtp
273
- * feature.
274
- */
275
- export declare class CmcdRequestedMaximumThroughput extends CmcdBase {
276
- readonly key = CmcdKeysToken.RequestedMaximumThroughput;
277
- readonly type = CmcdHeaderType.Status;
278
- constructor(value: IntegerKbps);
279
- keyValuePairToString(): string;
280
- }
281
- /**
282
- * The streaming format that defines the current
283
- * request.
284
- * - d = MPEG DASH
285
- * - h = HTTP Live Streaming (HLS)
286
- * - s = Smooth Streaming
287
- * - o = other
288
- *
289
- * If the streaming format being requested is
290
- * unknown, then this key MUST NOT be used.
291
- */
292
- export declare class CmcdStreamingFormat extends CmcdBase {
293
- readonly key = CmcdKeysToken.StreamingFormat;
294
- readonly type = CmcdHeaderType.Session;
295
- constructor(value: CmcdStreamingFormatToken);
296
- keyValuePairToString(): string;
297
- }
298
- /**
299
- * A GUID identifying the current playback session. A
300
- * playback session typically ties together segments
301
- * belonging to a single media asset. Maximum length
302
- * is 64 characters. It is RECOMMENDED to conform
303
- * to the UUID specification [7].
304
- */
305
- export declare class CmcdSessionId extends CmcdBase {
306
- readonly key = CmcdKeysToken.SessionId;
307
- readonly type = CmcdHeaderType.Session;
308
- constructor(value: string);
309
- }
310
- /**
311
- * - v = all segments are available – e.g., VOD
312
- * - l = segments become available over time – e.g.,
313
- * LIVE
314
- */
315
- export declare class CmcdStreamType extends CmcdBase {
316
- readonly key = CmcdKeysToken.StreamType;
317
- readonly type = CmcdHeaderType.Session;
318
- constructor(value: CmcdStreamTypeToken);
319
- keyValuePairToString(): string;
320
- }
321
- /**
322
- * Key is included without a value if the object is
323
- * needed urgently due to startup, seeking or
324
- * recovery after a buffer-empty event. The media
325
- * SHOULD not be rendering when this request is
326
- * made. This key MUST not be sent if it is FALSE.
327
- */
328
- export declare class CmcdStartup extends CmcdBase {
329
- readonly key = CmcdKeysToken.Startup;
330
- readonly type = CmcdHeaderType.Request;
331
- constructor(value: boolean);
332
- keyValuePairToString(): string;
333
- }
334
66
  /**
335
- * The highest bitrate rendition in the manifest or
336
- * playlist that the client is allowed to play, given
337
- * current codec, licensing and sizing constraints.
338
- */
339
- export declare class CmcdTopBitrate extends CmcdBase {
340
- readonly key = CmcdKeysToken.TopBitrate;
341
- readonly type = CmcdHeaderType.Object;
342
- constructor(value: IntegerKbps);
343
- }
344
- /**
345
- * The version of this specification used for
346
- * interpreting the defined key names and values. If
347
- * this key is omitted, the client and server MUST
348
- * interpret the values as being defined by version 1.
349
- * Client SHOULD omit this field if the version is 1.
350
- */
351
- export declare class CmcdVersion extends CmcdBase {
352
- readonly key = CmcdKeysToken.CmcdVersion;
353
- readonly type = CmcdHeaderType.Session;
354
- constructor(value: CmcdVersionNumbers);
355
- keyValuePairToString(): string;
356
- }
357
- 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 {
358
127
  readonly key: string;
128
+ readonly value: string | number;
359
129
  readonly type: CmcdHeaderType;
360
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;
361
136
  }
362
137
  export {};
@@ -39,6 +39,7 @@ 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;
44
45
  /** Clears all state that belongs to the previously loaded source. */
@@ -50,7 +51,8 @@ export declare class CmcdIntegration {
50
51
  setSessionId(id: string): void;
51
52
  setContentId(id: string): void;
52
53
  private gatherCmcdData;
53
- private getRequestedMaximumThroughput;
54
+ /** `cid` and `sid` are limited to 64 characters. Longer values are omitted, as truncating could cause collisions. */
55
+ private isValidId;
54
56
  /**
55
57
  * Main manifest requests set the format, so loading another source before the previous one
56
58
  * was unloaded is handled. An HLS variant request only sets it if still unknown (media playlist as source).
@@ -58,6 +60,6 @@ export declare class CmcdIntegration {
58
60
  */
59
61
  private getStreamingType;
60
62
  private getObjectType;
61
- private getSegmentRequestSpecificData;
62
- private getNextObjectAndObjectDurationCmcdData;
63
+ private addSegmentRequestSpecificData;
64
+ private addNextObjectAndObjectDuration;
63
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;
@@ -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,n){n.d(e,{$y:function(){return u},CT:function(){return T},II:function(){return o},JP:function(){return a},KQ:function(){return s},Nv:function(){return y},P$:function(){return m},Qf:function(){return q},S5:function(){return h},ST:function(){return i},T:function(){return P},W1:function(){return D},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 O},fB:function(){return k},hU:function(){return A},nd:function(){return I},o5:function(){return b},p$:function(){return x},w6:function(){return C},xq:function(){return M}});var r,i,o,u,s,a,c,l=(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(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 n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});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),n=e.filter(function(t){return t.type===c.Request}).map(function(t){return t.keyValuePairToString()}).join(","),r=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(","),o=e.filter(function(t){return t.type===c.Session}).map(function(t){return t.keyValuePairToString()}).join(","),u={};return n&&(u[c.Request]=n),r&&(u[c.Object]=r),i&&(u[c.Status]=i),o&&(u[c.Session]=o),u}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"}(o||(o={})),function(t){t.Vod="v",t.Live="l"}(u||(u={})),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,n=/\\/g,'"'.concat(t.replace(n,"\\\\").replace(e,'\\"'),'"'))):"":"boolean"==typeof this.value&&!0===this.value?"".concat(this.key):"".concat(this.key,"=").concat(this.value);var t,e,n},t}(),v=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.EncodedBitrate,n.type=c.Object,n}return l(e,t),e}(d),S=function(t){function e(e){var n=t.call(this,100*Math.round(e/100))||this;return n.key=a.BufferLength,n.type=c.Request,n}return l(e,t),e}(d),g=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.BufferStarvation,n.type=c.Status,n}return l(e,t),e}(d),T=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.ContentId,n.type=c.Session,n}return l(e,t),e}(d),m=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.ObjectDuration,n.type=c.Object,n}return l(e,t),e}(d),O=function(t){function e(e){var n=t.call(this,100*Math.round(e/100))||this;return n.key=a.Deadline,n.type=c.Request,n}return l(e,t),e}(d),b=function(t){function e(e){var n=t.call(this,100*Math.round(e/100))||this;return n.key=a.MeasuredThroughput,n.type=c.Request,n}return l(e,t),e.prototype.keyValuePairToString=function(){return 0===this.value?"":t.prototype.keyValuePairToString.call(this)},e}(d),k=function(t){function e(e){var n=t.call(this,encodeURIComponent(e))||this;return n.key=a.NextObjectRequest,n.type=c.Request,n}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 n=t.call(this,e)||this;return n.key=a.ObjectType,n.type=c.Object,n}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d)),I=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.PlaybackRate,n.type=c.Session,n}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 n=t.call(this,100*Math.round(e/100))||this;return n.key=a.RequestedMaximumThroughput,n.type=c.Status,n}return l(e,t),e.prototype.keyValuePairToString=function(){return 0===this.value?"":t.prototype.keyValuePairToString.call(this)},e}(d),M=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.StreamingFormat,n.type=c.Session,n}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),x=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.SessionId,n.type=c.Session,n}return l(e,t),e}(d),E=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.StreamType,n.type=c.Session,n}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),P=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.Startup,n.type=c.Request,n}return l(e,t),e.prototype.keyValuePairToString=function(){return!0===this.value?"".concat(this.key):""},e}(d),D=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.TopBitrate,n.type=c.Object,n}return l(e,t),e}(d),C=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.CmcdVersion,n.type=c.Session,n}return l(e,t),e.prototype.keyValuePairToString=function(){return this.value===s.v1?"":"".concat(this.key,"=").concat(this.value)},e}(d),q=function(t){function e(e,n,r){var i=t.call(this,n)||this,o=e.match(/^(.*-)(.*)$/);if(!o||!o[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(r)?r:null,i}return l(e,t),e}(d)},46:function(t,e,n){n.r(e),n.d(e,{CmcdIntegration:function(){return s},CustomKey:function(){return r.Qf},HeaderType:function(){return r.XO}});var r=n(145),i=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))},o=function(){return o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},o.apply(this,arguments)},u=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))},s=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,n){var i=e.gatherCmcdData(t,n);if(e.useQueryArgs)n.url=function(t,e){var n=t.indexOf("?"),r=t.indexOf("#"),i=-1===r?"":t.slice(r),o=-1===r?t:t.slice(0,r);if(-1===n||-1!==r&&n>r)return"".concat(o,"?").concat(e).concat(i);var s=o.slice(0,n),a=o.slice(n+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)}(n.url,(0,r.Nv)(i));else{var s=(0,r.S5)(i);n.headers=o(o({},n.headers),s)}return Promise.resolve(n)},this.preprocessHttpResponse=function(t,n){var r,i,o=n.elapsedTime,u=n.length;if(!o||!u)return Promise.resolve(n);var s=8*u/o/1e3;return t===((null===(r=e.player)||void 0===r?void 0:r.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(n)},this.useQueryArgs=t.useQueryArgs||!1,this.sessionId=t.sessionId||"",this.contentId=t.contentId||"",this.customKeys=t.customKeys||[],this.resetSourceState(),!1===this.useQueryArgs&&this.customKeys.length>0){var n=this.customKeys.filter(function(t){return null===t.type}).map(function(t){return t.key});if(n.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 "+n.join(", "))}}return t.prototype.setPlayer=function(t){var e=this;this.player=t,this.player.on(t.exports.PlayerEvent.SourceUnloaded,function(){return e.resetSourceState()}),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.Playing,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.resetSourceState=function(){this.stalledSinceLastRequest=!1,this.currentVideoQuality=null,this.currentAudioQuality=null,this.isSeekingOrTimeshiftingOrStartup=!0,this.lastMeasuredThroughputAudio=0,this.lastMeasuredThroughputVideo=0,this.manifestType=null},t.prototype.setSessionId=function(t){this.sessionId=t},t.prototype.setContentId=function(t){this.contentId=t},t.prototype.gatherCmcdData=function(t,e){if(!this.player)throw new Error("Bitmovin Player not provided!");var n=[];n.push(new r.w6(r.KQ.v1)),n.push(new r.YM(this.player.isLive()?r.$y.Live:r.$y.Vod)),n.push(new r.nd(this.player.isPlaying()?this.player.getPlaybackSpeed():0)),n.push(this.getObjectType(t));var i=this.getStreamingType(t);i&&n.push(i),this.contentId&&n.push(new r.CT(this.contentId)),this.sessionId&&n.push(new r.p$(this.sessionId));var o=this.isSeekingOrTimeshiftingOrStartup;o&&n.push(new r.T(!0));var u=this.stalledSinceLastRequest||this.player.isStalled();u&&(n.push(new r.Xk(!0)),this.stalledSinceLastRequest=!1),t===this.player.exports.HttpRequestType.MEDIA_AUDIO?n=n.concat(this.getSegmentRequestSpecificData(e,"audio")):t===this.player.exports.HttpRequestType.MEDIA_VIDEO&&(n=n.concat(this.getSegmentRequestSpecificData(e,"video"))),o||u||(n=n.concat(this.getRequestedMaximumThroughput(n)));for(var s=0,a=this.customKeys;s<a.length;s++){var c=a[s];n.push(c)}return n},t.prototype.getRequestedMaximumThroughput=function(t){var e=t.find(function(t){return t.key===r.JP.EncodedBitrate});return e?[new r.Wf(5*Number(e.value))]:[]},t.prototype.getStreamingType=function(t){var e,n=null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType;return t===(null==n?void 0:n.MANIFEST_DASH)?this.manifestType=r.II.MpegDash:t===(null==n?void 0:n.MANIFEST_HLS_MASTER)?this.manifestType=r.II.Hls:t===(null==n?void 0:n.MANIFEST_SMOOTH)?this.manifestType=r.II.Smooth:t!==(null==n?void 0:n.MANIFEST_HLS_VARIANT)||this.manifestType||(this.manifestType=r.II.Hls),this.manifestType?new r.xq(this.manifestType):null},t.prototype.getObjectType=function(t){var e,n,i,o,u,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 r.hU(r.ST.AudioOnly);break;case null===(n=this.player)||void 0===n?void 0:n.exports.HttpRequestType.MEDIA_VIDEO:S=new r.hU(r.ST.VideoOnly);break;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===(u=this.player)||void 0===u?void 0:u.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 r.hU(r.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 r.hU(r.ST.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:S=new r.hU(r.ST.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:S=new r.hU(r.ST.CaptionOrSubtitle);break;default:S=new r.hU(r.ST.Other)}return S},t.prototype.getSegmentRequestSpecificData=function(t,e){var n=[];if(!this.player)return n;var i="audio"===e,o=i?this.currentAudioQuality:this.currentVideoQuality,u=i?this.lastMeasuredThroughputAudio:this.lastMeasuredThroughputVideo;o&&o.bandwidth&&n.push(new r.X5(Math.round(o.bandwidth/1e3))),u&&n.push(new r.o5(u));var s=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,i?this.player.exports.MediaType.Audio:this.player.exports.MediaType.Video);if(s.targetLevel>0){n.push(new r.Yj(1e3*s.level));var a=s.level/this.player.getPlaybackSpeed();n.push(new r.e$(1e3*a))}var c=(i?this.player.getAvailableAudioQualities():this.player.getAvailableVideoQualities()).reduce(function(t,e){return Math.max(t,e.bitrate)},0)/1e3;if(c>0&&n.push(new r.W1(c)),o)try{var l=this.player.getAvailableSegments();for(var p in l){var h=l[p][o.id];p.startsWith("".concat(e,"/"))&&h&&(n=n.concat(this.getNextObjectAndObjectDurationCmcdData(h,t.url)))}}catch(t){console.error("Error processing ".concat(e," segments:"),t)}return n},t.prototype.getNextObjectAndObjectDurationCmcdData=function(t,e){var n=[],o=t.findIndex(function(t){return t.url===e});if(o>-1){var u=t[o];if(Number.isFinite(u.duration)&&n.push(new r.P$(1e3*Number(u.duration))),o+1<t.length){var s=t[o+1],a=s.url?function(t,e){var n,r;try{n=new URL(t),r=new URL(e,n)}catch(t){return null}if(n.origin!==r.origin)return null;for(var o=n.pathname.split("/").slice(0,-1),u=r.pathname.split("/"),s=0;s<o.length&&s<u.length-1&&o[s]===u[s];)s++;var a=new Array(o.length-s).fill(".."),c=i(i([],a,!0),u.slice(s),!0).join("/");return 0===a.length&&c.split("/")[0].includes(":")&&(c="./".concat(c)),"".concat(c).concat(r.search)}(e,s.url):null;a&&n.push(new r.fB(a))}}return n},t}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.exports}return n.d=function(t,e){if(Array.isArray(e))for(var r=0;r<e.length;){var i=e[r++],o=e[r++];n.o(t,i)?0===o&&r++:0===o?Object.defineProperty(t,i,{enumerable:!0,value:e[r++]}):Object.defineProperty(t,i,{enumerable:!0,get:o})}else for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(145),n(46)}()});
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitmovin/player-web-integration-cmcd",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
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",