@bitmovin/player-web-integration-cmcd 0.5.0 → 0.6.1
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 +24 -1
- package/dist/js/Cmcd.d.ts +8 -2
- package/dist/js/CmcdIntegration.d.ts +8 -2
- package/dist/js/Url.d.ts +6 -0
- package/dist/js/bitmovin-player-integration-cmcd.js +1 -1
- package/package.json +10 -3
- package/dist/index.html +0 -90
- package/jest.config.js +0 -5
- package/test/ts/Cmcd.test.ts +0 -391
- package/test/ts/CmcdIntegration.test.ts +0 -185
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.1] - 2026-11-20
|
|
11
|
+
### Fixed
|
|
12
|
+
- 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.
|
|
13
|
+
- 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.
|
|
14
|
+
- Measured throughput (`mtp`) was sent as `mtp=0` for throughputs below 50 kbps. The key is now omitted in this case.
|
|
15
|
+
- 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.
|
|
16
|
+
- Startup (`su`) was sent on all requests until the first seek or stall. It is now cleared when playback starts.
|
|
17
|
+
- Audio segment requests used the video segments to determine `nor` and object duration (`d`).
|
|
18
|
+
- Object duration (`d`) was sent as `NaN` if the segment duration is unknown.
|
|
19
|
+
- 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.
|
|
20
|
+
- 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.
|
|
21
|
+
- 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`.
|
|
22
|
+
- package.json description referred to the wrong product.
|
|
23
|
+
|
|
24
|
+
## [0.6.0] - 2026-07-29
|
|
25
|
+
### Changed
|
|
26
|
+
- 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.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- Query parameters already present on a request URL were re-encoded when `useQueryArgs` is enabled. Only the appended `CMCD` parameter is URL encoded now.
|
|
30
|
+
|
|
10
31
|
## [0.5.0] - 2026-01-14
|
|
11
32
|
### Added
|
|
12
33
|
- Option to set the CMCD header type per `CustomKey` to one of the predefined HTTP headers. This is required now for CustomKey's if `useQueryArgs` is set to `false` (HTTP Header mode is used).
|
|
@@ -36,7 +57,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
36
57
|
### Added
|
|
37
58
|
- Initial CMCD release (Beta)
|
|
38
59
|
|
|
39
|
-
[Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.
|
|
60
|
+
[Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.1...HEAD
|
|
61
|
+
[0.6.1]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.0...v0.6.1
|
|
62
|
+
[0.6.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.5.0...v0.6.0
|
|
40
63
|
[0.5.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...v0.5.0
|
|
41
64
|
[0.4.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.3.0...v0.4.0
|
|
42
65
|
[0.3.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.1...v0.3.0
|
package/dist/js/Cmcd.d.ts
CHANGED
|
@@ -183,6 +183,7 @@ export declare class CmcdMeasuredThroughput extends CmcdBase {
|
|
|
183
183
|
readonly key = CmcdKeysToken.MeasuredThroughput;
|
|
184
184
|
readonly type = CmcdHeaderType.Request;
|
|
185
185
|
constructor(value: IntegerKbps);
|
|
186
|
+
keyValuePairToString(): string;
|
|
186
187
|
}
|
|
187
188
|
/**
|
|
188
189
|
* Relative path of the next object to be requested.
|
|
@@ -196,7 +197,11 @@ export declare class CmcdMeasuredThroughput extends CmcdBase {
|
|
|
196
197
|
export declare class CmcdNextObjectRequest extends CmcdBase {
|
|
197
198
|
readonly key = CmcdKeysToken.NextObjectRequest;
|
|
198
199
|
readonly type = CmcdHeaderType.Request;
|
|
199
|
-
|
|
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);
|
|
200
205
|
}
|
|
201
206
|
/**
|
|
202
207
|
* If the next request will be a partial object request,
|
|
@@ -270,7 +275,8 @@ export declare class CmcdPlaybackRate extends CmcdBase {
|
|
|
270
275
|
export declare class CmcdRequestedMaximumThroughput extends CmcdBase {
|
|
271
276
|
readonly key = CmcdKeysToken.RequestedMaximumThroughput;
|
|
272
277
|
readonly type = CmcdHeaderType.Status;
|
|
273
|
-
constructor(value:
|
|
278
|
+
constructor(value: IntegerKbps);
|
|
279
|
+
keyValuePairToString(): string;
|
|
274
280
|
}
|
|
275
281
|
/**
|
|
276
282
|
* The streaming format that defines the current
|
|
@@ -41,6 +41,8 @@ export declare class CmcdIntegration {
|
|
|
41
41
|
private manifestType;
|
|
42
42
|
constructor(config: CmcdConfig);
|
|
43
43
|
setPlayer(player: PlayerAPI): void;
|
|
44
|
+
/** Clears all state that belongs to the previously loaded source. */
|
|
45
|
+
private resetSourceState;
|
|
44
46
|
onVideoAdaptation: (data: VideoAdaptationData) => string;
|
|
45
47
|
onAudioAdaptation: (data: AudioAdaptationData) => string;
|
|
46
48
|
preprocessHttpRequest: (type: HttpRequestType, request: HttpRequest) => Promise<HttpRequest>;
|
|
@@ -49,9 +51,13 @@ export declare class CmcdIntegration {
|
|
|
49
51
|
setContentId(id: string): void;
|
|
50
52
|
private gatherCmcdData;
|
|
51
53
|
private getRequestedMaximumThroughput;
|
|
54
|
+
/**
|
|
55
|
+
* Main manifest requests set the format, so loading another source before the previous one
|
|
56
|
+
* was unloaded is handled. An HLS variant request only sets it if still unknown (media playlist as source).
|
|
57
|
+
* Returns `null` while unknown, as `sf` MUST NOT be sent then.
|
|
58
|
+
*/
|
|
52
59
|
private getStreamingType;
|
|
53
60
|
private getObjectType;
|
|
54
|
-
private
|
|
55
|
-
private getVideoSegmentRequestSpecificData;
|
|
61
|
+
private getSegmentRequestSpecificData;
|
|
56
62
|
private getNextObjectAndObjectDurationCmcdData;
|
|
57
63
|
}
|
package/dist/js/Url.d.ts
ADDED
|
@@ -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={247:function(t,e,r){r.d(e,{Ao:function(){return E},Dh:function(){return a},I3:function(){return R},J3:function(){return M},M:function(){return h},O5:function(){return b},Ph:function(){return I},QU:function(){return u},RE:function(){return s},RF:function(){return A},RZ:function(){return y},T8:function(){return m},TS:function(){return k},Vf:function(){return x},Vq:function(){return q},ZH:function(){return v},be:function(){return T},dg:function(){return O},gu:function(){return D},hq:function(){return w},hv:function(){return c},mP:function(){return S},mc:function(){return i},nf:function(){return o},oI:function(){return g},x9:function(){return P}});var n,i,u,o,s,a,c,p=(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 l(t){return t.sort((function(t,e){return t.key.localeCompare(e.key)})).filter((function(t){return t.keyValuePairToString()}))}function h(t){var e=l(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=l(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 p(e,t),e}(d),g=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 p(e,t),e}(d),S=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.BufferStarvation,r.type=c.Status,r}return p(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 p(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 p(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 p(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 p(e,t),e}(d),R=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.NextObjectRequest,r.type=c.Request,r}return p(e,t),e}(d),k=(p((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 p(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d)),A=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.PlaybackRate,r.type=c.Session,r}return p(e,t),e.prototype.keyValuePairToString=function(){return 1===this.value?"":"".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.RequestedMaximumThroughput,r.type=c.Status,r}return p(e,t),e}(d),x=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamingFormat,r.type=c.Session,r}return p(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),I=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.SessionId,r.type=c.Session,r}return p(e,t),e}(d),D=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamType,r.type=c.Session,r}return p(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),E=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.Startup,r.type=c.Request,r}return p(e,t),e.prototype.keyValuePairToString=function(){return!0===this.value?"".concat(this.key):""},e}(d),q=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.TopBitrate,r.type=c.Object,r}return p(e,t),e}(d),P=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.CmcdVersion,r.type=c.Session,r}return p(e,t),e.prototype.keyValuePairToString=function(){return this.value===s.v1?"":"".concat(this.key,"=").concat(this.value)},e}(d),w=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 p(e,t),e}(d)},498:function(t,e,r){r.r(e),r.d(e,{CmcdIntegration:function(){return u},CustomKey:function(){return n.hq},HeaderType:function(){return n.hv}});var n=r(247),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(){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 u=e.gatherCmcdData(t,r);if(e.useQueryArgs){var o=new URL(r.url);o.searchParams.delete("CMCD");var s=(0,n.RZ)(u),a=o.toString().includes("?")?"&":"?";r.url="".concat(o.toString()).concat(a).concat(s)}else{var c=(0,n.M)(u);r.headers=i(i({},r.headers),c)}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.x9(n.RE.v1)),u.push(new n.gu(this.player.isLive()?n.nf.Live:n.nf.Vod)),u.push(new n.RF(this.player.getPlaybackSpeed())),u.push(this.getObjectType(t)),u.push(this.getStreamingType(t)),this.contentId&&u.push(new n.be(this.contentId)),this.sessionId&&u.push(new n.Ph(this.sessionId)),this.isSeekingOrTimeshiftingOrStartup&&u.push(new n.Ao(!0)),(this.stalledSinceLastRequest||this.player.isStalled())&&(u.push(new n.mP(!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.Dh.EncodedBitrate})),r=t.find((function(t){return t.key===n.Dh.ObjectDuration})),i=Boolean(t.find((function(t){return t.key===n.Dh.ObjectDuration}))),u=t.find((function(t){return t.key===n.Dh.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.J3(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.QU.MpegDash:t===(null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MANIFEST_HLS_MASTER)?this.manifestType=n.QU.Hls:t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MANIFEST_SMOOTH)?this.manifestType=n.QU.Smooth:this.manifestType=n.QU.Other),new n.Vf(this.manifestType)},t.prototype.getObjectType=function(t){var e,r,i,u,o,s,a,c,p,l,h,y,f,d,v,g;switch(t){case null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MEDIA_AUDIO:g=new n.TS(n.mc.AudioOnly);break;case null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_VIDEO:g=new n.TS(n.mc.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:g=new n.TS(n.mc.CryptographicKeyOrLicenseOrCertificate);break;case null===(p=this.player)||void 0===p?void 0:p.exports.HttpRequestType.MANIFEST_ADS:case null===(l=this.player)||void 0===l?void 0:l.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:g=new n.TS(n.mc.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:g=new n.TS(n.mc.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:g=new n.TS(n.mc.CaptionOrSubtitle);break;default:g=new n.TS(n.mc.Other)}return g},t.prototype.getAudioSegmentRequestSpecificData=function(t){var e,r=[];if(this.currentAudioQuality&&this.currentAudioQuality.bandwidth&&r.push(new n.ZH(Math.round(this.currentAudioQuality.bandwidth/1e3))),this.lastMeasuredThroughputAudio&&r.push(new n.dg(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.oI(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.O5(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.Vq(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.ZH(Math.round(this.currentVideoQuality.bandwidth/1e3))),this.lastMeasuredThroughputVideo&&r.push(new n.dg(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.oI(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.O5(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.Vq(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.T8(1e3*Number(u.duration))),i+1<t.length){var o=t[i+1];o.url&&r.push(new n.I3(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){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},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(247),r(498)}()}));
|
|
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)}()});
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitmovin/player-web-integration-cmcd",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/js",
|
|
10
|
+
"CHANGELOG.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
8
14
|
"repository": {
|
|
9
15
|
"type": "git",
|
|
10
|
-
"url": "
|
|
16
|
+
"url": "git+https://github.com/bitmovin/bitmovin-player-web-integration-cmcd.git"
|
|
11
17
|
},
|
|
12
18
|
"scripts": {
|
|
13
19
|
"format": "prettier --write src/ test/",
|
|
@@ -15,6 +21,7 @@
|
|
|
15
21
|
"start": "webpack serve --open --config tooling/webpack.dev.js",
|
|
16
22
|
"debug": "webpack --config tooling/webpack.dev.js",
|
|
17
23
|
"build": "webpack --config tooling/webpack.prod.js",
|
|
24
|
+
"prepack": "npm run build",
|
|
18
25
|
"clean": "rm -R dist/js",
|
|
19
26
|
"test": "jest",
|
|
20
27
|
"test-watch": "jest --watch"
|
package/dist/index.html
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Bitmovin Player Integration Demo</title>
|
|
5
|
-
<meta charset="UTF-8"/>
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
-
<link href="https://cdn.bitmovin.com/player/web/8/bitmovinplayer-ui.css" rel="stylesheet">
|
|
9
|
-
|
|
10
|
-
<style>
|
|
11
|
-
.container {
|
|
12
|
-
text-align: center;
|
|
13
|
-
}
|
|
14
|
-
.container h1 {
|
|
15
|
-
margin-bottom: 22px;
|
|
16
|
-
line-height: 66px;
|
|
17
|
-
}
|
|
18
|
-
.container h2 {
|
|
19
|
-
font-weight: normal;
|
|
20
|
-
margin-bottom: 36px;
|
|
21
|
-
line-height: 26px;
|
|
22
|
-
}
|
|
23
|
-
.player-wrapper {
|
|
24
|
-
width: 95%;
|
|
25
|
-
margin: 20px auto;
|
|
26
|
-
box-shadow: 0 0 30px rgba(0,0,0,0.7);
|
|
27
|
-
}
|
|
28
|
-
</style>
|
|
29
|
-
</head>
|
|
30
|
-
<body>
|
|
31
|
-
<div class="container">
|
|
32
|
-
<h1>TEST</h1>
|
|
33
|
-
<div class="content">
|
|
34
|
-
<div class="player-wrapper">
|
|
35
|
-
<div id="playerContainer"></div>
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
<script type="text/javascript" src="//cdn.bitmovin.com/player/web/8/bitmovinplayer.js"></script>
|
|
41
|
-
<script type="text/javascript" src="./js/bitmovin-player-integration-cmcd.js"></script>
|
|
42
|
-
<script type="text/javascript">
|
|
43
|
-
const playerConfig = {
|
|
44
|
-
key: '7e9c8483-ea84-423e-b675-19cf31dec43a',
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const cmcdConfig = {
|
|
48
|
-
useQueryArgs: true,
|
|
49
|
-
sessionId: '6e2fb550-c457-11e9-bb97-0800200c9a66',
|
|
50
|
-
contentId: '1111-111111-111111-11111',
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const cmcdIntegration = new window.bitmovin.player.integration.Cmcd.CmcdIntegration(cmcdConfig);
|
|
54
|
-
|
|
55
|
-
playerConfig.network = {
|
|
56
|
-
preprocessHttpRequest: cmcdIntegration.preprocessHttpRequest,
|
|
57
|
-
preprocessHttpResponse: cmcdIntegration.preprocessHttpResponse,
|
|
58
|
-
};
|
|
59
|
-
playerConfig.adaptation = {
|
|
60
|
-
desktop: {
|
|
61
|
-
onVideoAdaptation: cmcdIntegration.onVideoAdaptation,
|
|
62
|
-
onAudioAdaptation: cmcdIntegration.onAudioAdaptation,
|
|
63
|
-
},
|
|
64
|
-
mobile: {
|
|
65
|
-
onVideoAdaptation: cmcdIntegration.onVideoAdaptation,
|
|
66
|
-
onAudioAdaptation: cmcdIntegration.onAudioAdaptation,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
var player = new bitmovin.player.Player(
|
|
71
|
-
document.querySelector('#playerContainer'),
|
|
72
|
-
playerConfig,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
cmcdIntegration.setPlayer(player);
|
|
76
|
-
|
|
77
|
-
const source = {
|
|
78
|
-
dash: 'https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd',
|
|
79
|
-
hls: 'https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8',
|
|
80
|
-
poster: 'https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/poster.jpg',
|
|
81
|
-
thumbnailTrack: {
|
|
82
|
-
url: 'https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/thumbnails/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.vtt'
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
player.load(source);
|
|
87
|
-
|
|
88
|
-
</script>
|
|
89
|
-
</body>
|
|
90
|
-
</html>
|
package/jest.config.js
DELETED
package/test/ts/Cmcd.test.ts
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
import { describe, beforeEach, it, expect } from '@jest/globals';
|
|
2
|
-
import {
|
|
3
|
-
CmcdBufferLength,
|
|
4
|
-
CmcdBufferStarvation,
|
|
5
|
-
CmcdContentId,
|
|
6
|
-
CmcdCustomKey,
|
|
7
|
-
CmcdDeadline,
|
|
8
|
-
CmcdEncodedBitrate,
|
|
9
|
-
CmcdHeaderType,
|
|
10
|
-
CmcdMeasuredThroughput,
|
|
11
|
-
CmcdNextObjectRequest,
|
|
12
|
-
CmcdNextRangeRequest,
|
|
13
|
-
CmcdObjectDuration,
|
|
14
|
-
CmcdObjectType,
|
|
15
|
-
CmcdObjectTypeToken,
|
|
16
|
-
CmcdPlaybackRate,
|
|
17
|
-
CmcdRequestedMaximumThroughput,
|
|
18
|
-
CmcdSessionId,
|
|
19
|
-
CmcdStartup,
|
|
20
|
-
CmcdStreamType,
|
|
21
|
-
CmcdStreamTypeToken,
|
|
22
|
-
CmcdStreamingFormat,
|
|
23
|
-
CmcdStreamingFormatToken,
|
|
24
|
-
CmcdTopBitrate,
|
|
25
|
-
CmcdVersion,
|
|
26
|
-
CmcdVersionNumbers,
|
|
27
|
-
cmcdDataToHeader,
|
|
28
|
-
cmcdDataToUrlParameter,
|
|
29
|
-
} from '../../src/ts/Cmcd';
|
|
30
|
-
|
|
31
|
-
describe('Cmcd', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
// fresh setup before every test case
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should transform CMCD objects to URL parameter', () => {
|
|
37
|
-
const cmcdObjects = [
|
|
38
|
-
new CmcdEncodedBitrate(500),
|
|
39
|
-
new CmcdBufferLength(0),
|
|
40
|
-
new CmcdBufferStarvation(true),
|
|
41
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=bl%3D0%2Cbr%3D500%2Cbs%2Cot%3Dv');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should always sort the URL parameters alphabetically by CMCD key', () => {
|
|
48
|
-
const cmcdObjects1 = [
|
|
49
|
-
new CmcdEncodedBitrate(500),
|
|
50
|
-
new CmcdBufferLength(0),
|
|
51
|
-
new CmcdBufferStarvation(true),
|
|
52
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
53
|
-
];
|
|
54
|
-
const cmcdObjects2 = [
|
|
55
|
-
new CmcdBufferLength(0),
|
|
56
|
-
new CmcdBufferStarvation(true),
|
|
57
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
58
|
-
new CmcdEncodedBitrate(500),
|
|
59
|
-
];
|
|
60
|
-
const cmcdObjects3 = [
|
|
61
|
-
new CmcdBufferStarvation(true),
|
|
62
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
63
|
-
new CmcdBufferLength(0),
|
|
64
|
-
new CmcdEncodedBitrate(500),
|
|
65
|
-
];
|
|
66
|
-
const cmcdObjects4 = [
|
|
67
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
68
|
-
new CmcdBufferLength(0),
|
|
69
|
-
new CmcdBufferStarvation(true),
|
|
70
|
-
new CmcdEncodedBitrate(500),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
const cmcdUrlParams1 = cmcdDataToUrlParameter(cmcdObjects1);
|
|
74
|
-
const cmcdUrlParams2 = cmcdDataToUrlParameter(cmcdObjects2);
|
|
75
|
-
const cmcdUrlParams3 = cmcdDataToUrlParameter(cmcdObjects3);
|
|
76
|
-
const cmcdUrlParams4 = cmcdDataToUrlParameter(cmcdObjects4);
|
|
77
|
-
|
|
78
|
-
expect(cmcdUrlParams1).toEqual(cmcdUrlParams2);
|
|
79
|
-
expect(cmcdUrlParams2).toEqual(cmcdUrlParams3);
|
|
80
|
-
expect(cmcdUrlParams3).toEqual(cmcdUrlParams4);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should sort custom keys alphabetically with standard keys according to full key name', () => {
|
|
84
|
-
const cmcdObjects = [
|
|
85
|
-
new CmcdObjectDuration(4004), // key: 'd'
|
|
86
|
-
new CmcdCustomKey('com.example-myNumericKey', 500), // key: 'com.example-myNumericKey'
|
|
87
|
-
new CmcdCustomKey('com.example-myStringKey', 'myStringValue'), // key: 'com.example-myStringKey'
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
const result = cmcdDataToUrlParameter(cmcdObjects);
|
|
91
|
-
|
|
92
|
-
// Custom keys should come first alphabetically before 'd'
|
|
93
|
-
// Expected order: 'com.example-myNumericKey', 'com.example-myStringKey', 'd'
|
|
94
|
-
expect(result).toEqual(
|
|
95
|
-
'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should maintain strict alphabetical order regardless of input order with mixed custom and standard keys', () => {
|
|
100
|
-
const cmcdObjects1 = [
|
|
101
|
-
new CmcdObjectDuration(4004), // 'd'
|
|
102
|
-
new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
|
|
103
|
-
new CmcdBufferLength(0), // 'bl'
|
|
104
|
-
];
|
|
105
|
-
|
|
106
|
-
const cmcdObjects2 = [
|
|
107
|
-
new CmcdBufferLength(0), // 'bl'
|
|
108
|
-
new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
|
|
109
|
-
new CmcdObjectDuration(4004), // 'd'
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
const result1 = cmcdDataToUrlParameter(cmcdObjects1);
|
|
113
|
-
const result2 = cmcdDataToUrlParameter(cmcdObjects2);
|
|
114
|
-
|
|
115
|
-
expect(result1).toEqual(result2);
|
|
116
|
-
// Should be: bl, com.example-myKey, d
|
|
117
|
-
expect(result1).toEqual('CMCD=bl%3D0%2Ccom.example-myKey%3D500%2Cd%3D4004');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should sort custom keys that come after standard keys alphabetically', () => {
|
|
121
|
-
const cmcdObjects = [
|
|
122
|
-
new CmcdBufferLength(100), // 'bl'
|
|
123
|
-
new CmcdCustomKey('z-custom-key', 'value'), // 'z-custom-key' - should come last
|
|
124
|
-
new CmcdObjectDuration(4004), // 'd'
|
|
125
|
-
new CmcdCustomKey('m-custom-key', 123), // 'm-custom-key' - should come between 'd' and 'z'
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
const result = cmcdDataToUrlParameter(cmcdObjects);
|
|
129
|
-
|
|
130
|
-
// Expected alphabetical order: bl, d, m-custom-key, z-custom-key
|
|
131
|
-
expect(result).toEqual('CMCD=bl%3D100%2Cd%3D4004%2Cm-custom-key%3D123%2Cz-custom-key%3D%22value%22');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('Cmcd classes', () => {
|
|
135
|
-
it('should ignore keys with empty string value', () => {
|
|
136
|
-
expect(new CmcdContentId('').keyValuePairToString()).toEqual('');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should quote strings', () => {
|
|
140
|
-
expect(new CmcdContentId('test-content-id').keyValuePairToString()).toEqual('cid="test-content-id"');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should escape backslashes in strings', () => {
|
|
144
|
-
expect(new CmcdContentId('test-\\content\\-id').keyValuePairToString()).toEqual('cid="test-\\\\content\\\\-id"');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should escape quotes in strings', () => {
|
|
148
|
-
expect(new CmcdContentId('"test"-content-id').keyValuePairToString()).toEqual('cid="\\"test\\"-content-id"');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should escape quotes and backslashes in strings', () => {
|
|
152
|
-
expect(new CmcdContentId('"test"-content\\-id').keyValuePairToString()).toEqual(
|
|
153
|
-
'cid="\\"test\\"-content\\\\-id"'
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should truncate true boolean values to just include the CMCD key', () => {
|
|
158
|
-
expect(new CmcdBufferStarvation(true).keyValuePairToString()).toEqual('bs');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should explicitly list false boolean values', () => {
|
|
162
|
-
expect(new CmcdBufferStarvation(false).keyValuePairToString()).toEqual('bs=false');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should list number values "as is"', () => {
|
|
166
|
-
expect(new CmcdEncodedBitrate(5432).keyValuePairToString()).toEqual('br=5432');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should list token values "as is"', () => {
|
|
170
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.VideoOnly).keyValuePairToString()).toEqual('ot=v');
|
|
171
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.AudioOnly).keyValuePairToString()).toEqual('ot=a');
|
|
172
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.CaptionOrSubtitle).keyValuePairToString()).toEqual('ot=c');
|
|
173
|
-
expect(
|
|
174
|
-
new CmcdObjectType(CmcdObjectTypeToken.CryptographicKeyOrLicenseOrCertificate).keyValuePairToString()
|
|
175
|
-
).toEqual('ot=k');
|
|
176
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.InitSegment).keyValuePairToString()).toEqual('ot=i');
|
|
177
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.ManifestOrPlaylistTextFile).keyValuePairToString()).toEqual('ot=m');
|
|
178
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.MuxedVideoAudio).keyValuePairToString()).toEqual('ot=av');
|
|
179
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.Other).keyValuePairToString()).toEqual('ot=o');
|
|
180
|
-
expect(new CmcdObjectType(CmcdObjectTypeToken.TimedTextTrack).keyValuePairToString()).toEqual('ot=tt');
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should round buffer length, deadline values to nearest 100ms', () => {
|
|
184
|
-
expect(new CmcdBufferLength(5452).keyValuePairToString()).toEqual('bl=5500');
|
|
185
|
-
expect(new CmcdBufferLength(5450).keyValuePairToString()).toEqual('bl=5500');
|
|
186
|
-
expect(new CmcdBufferLength(5432).keyValuePairToString()).toEqual('bl=5400');
|
|
187
|
-
expect(new CmcdDeadline(5452).keyValuePairToString()).toEqual('dl=5500');
|
|
188
|
-
expect(new CmcdDeadline(5450).keyValuePairToString()).toEqual('dl=5500');
|
|
189
|
-
expect(new CmcdDeadline(5432).keyValuePairToString()).toEqual('dl=5400');
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('should round measured throughput values to nearest 100kbps', () => {
|
|
193
|
-
expect(new CmcdMeasuredThroughput(87654).keyValuePairToString()).toEqual('mtp=87700');
|
|
194
|
-
expect(new CmcdMeasuredThroughput(87650).keyValuePairToString()).toEqual('mtp=87700');
|
|
195
|
-
expect(new CmcdMeasuredThroughput(87649).keyValuePairToString()).toEqual('mtp=87600');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should remove playback rate if value is 1', () => {
|
|
199
|
-
expect(new CmcdPlaybackRate(1).keyValuePairToString()).toEqual('');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should add playback rate if value is not 1', () => {
|
|
203
|
-
expect(new CmcdPlaybackRate(1.08).keyValuePairToString()).toEqual('pr=1.08');
|
|
204
|
-
expect(new CmcdPlaybackRate(0).keyValuePairToString()).toEqual('pr=0');
|
|
205
|
-
expect(new CmcdPlaybackRate(2.52).keyValuePairToString()).toEqual('pr=2.52');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('should remove CMCD version if value is 1', () => {
|
|
209
|
-
expect(new CmcdVersion(CmcdVersionNumbers.v1).keyValuePairToString()).toEqual('');
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('CmcdCustomKey', () => {
|
|
214
|
-
describe('with HTTP Header mode', () => {
|
|
215
|
-
it('should set the provided CmcdHeaderType correctly', () => {
|
|
216
|
-
const customKey1 = new CmcdCustomKey('com.example-myNumericKey1', 'value1', CmcdHeaderType.Object);
|
|
217
|
-
const customKey2 = new CmcdCustomKey('com.example-myNumericKey2', 'value2', CmcdHeaderType.Request);
|
|
218
|
-
const customKey3 = new CmcdCustomKey('com.example-myNumericKey3', 'value3', CmcdHeaderType.Session);
|
|
219
|
-
const customKey4 = new CmcdCustomKey('com.example-myNumericKey4', 'value4', CmcdHeaderType.Status);
|
|
220
|
-
|
|
221
|
-
expect(customKey1.type).toEqual(CmcdHeaderType.Object);
|
|
222
|
-
expect(customKey2.type).toEqual(CmcdHeaderType.Request);
|
|
223
|
-
expect(customKey3.type).toEqual(CmcdHeaderType.Session);
|
|
224
|
-
expect(customKey4.type).toEqual(CmcdHeaderType.Status);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should set invalid CmcdHeaderType to null', () => {
|
|
228
|
-
const customKey1 = new CmcdCustomKey('com.example-myNumericKey1', 'value1', 'invalid' as any);
|
|
229
|
-
const customKey2 = new CmcdCustomKey('com.example-myNumericKey2', 'value2', null as any);
|
|
230
|
-
const customKey3 = new CmcdCustomKey('com.example-myNumericKey3', 'value3', undefined as any);
|
|
231
|
-
const customKey4 = new CmcdCustomKey('com.example-myNumericKey4', 'value4', 2 as any);
|
|
232
|
-
|
|
233
|
-
expect(customKey1.type).toEqual(null);
|
|
234
|
-
expect(customKey2.type).toEqual(null);
|
|
235
|
-
expect(customKey3.type).toEqual(null);
|
|
236
|
-
expect(customKey4.type).toEqual(null);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe('CMCD Spec Examples', () => {
|
|
242
|
-
// Examples from CMCD v1 spec Section 6 taken as test cases
|
|
243
|
-
|
|
244
|
-
it('Section 6, Example #1:', () => {
|
|
245
|
-
const cmcdObjects = [new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66')];
|
|
246
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=sid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22');
|
|
247
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
248
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('Section 6, Example #2:', () => {
|
|
253
|
-
const cmcdObjects = [
|
|
254
|
-
new CmcdEncodedBitrate(3200),
|
|
255
|
-
new CmcdBufferStarvation(true),
|
|
256
|
-
new CmcdObjectDuration(4004),
|
|
257
|
-
new CmcdMeasuredThroughput(25432),
|
|
258
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
259
|
-
new CmcdRequestedMaximumThroughput(15000),
|
|
260
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
261
|
-
new CmcdTopBitrate(6000),
|
|
262
|
-
];
|
|
263
|
-
|
|
264
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
265
|
-
'CMCD=br%3D3200%2Cbs%2Cd%3D4004%2Cmtp%3D25400%2Cot%3Dv%2Crtp%3D15000%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22%2Ctb%3D6000'
|
|
266
|
-
);
|
|
267
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
268
|
-
'CMCD-Request': 'mtp=25400',
|
|
269
|
-
'CMCD-Object': 'br=3200,d=4004,ot=v,tb=6000',
|
|
270
|
-
'CMCD-Status': 'bs,rtp=15000',
|
|
271
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('Section 6, Example #3:', () => {
|
|
276
|
-
const cmcdObjects = [
|
|
277
|
-
new CmcdBufferStarvation(true),
|
|
278
|
-
new CmcdRequestedMaximumThroughput(15000),
|
|
279
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
280
|
-
];
|
|
281
|
-
// Small mistake in the CMCD spec where 'bs' was truncated to 'b' in this query arg example
|
|
282
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
283
|
-
'CMCD=bs%2Crtp%3D15000%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
|
|
284
|
-
);
|
|
285
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
286
|
-
'CMCD-Status': 'bs,rtp=15000',
|
|
287
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('Section 6, Example #4:', () => {
|
|
292
|
-
const cmcdObjects = [new CmcdBufferStarvation(true), new CmcdStartup(true)];
|
|
293
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=bs%2Csu');
|
|
294
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
295
|
-
'CMCD-Status': 'bs',
|
|
296
|
-
'CMCD-Request': 'su',
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('Section 6, Example #5:', () => {
|
|
301
|
-
const cmcdObjects = [
|
|
302
|
-
new CmcdObjectDuration(4004),
|
|
303
|
-
new CmcdCustomKey('com.example-myNumericKey', 500, CmcdHeaderType.Session),
|
|
304
|
-
new CmcdCustomKey('com.example-myStringKey', 'myStringValue', CmcdHeaderType.Session),
|
|
305
|
-
];
|
|
306
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
307
|
-
'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
|
|
308
|
-
);
|
|
309
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
310
|
-
'CMCD-Object': 'd=4004',
|
|
311
|
-
'CMCD-Session': 'com.example-myNumericKey=500,com.example-myStringKey="myStringValue"',
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('Section 6, Example #6:', () => {
|
|
316
|
-
const cmcdObjects = [
|
|
317
|
-
new CmcdNextObjectRequest('..%2F300kbps%2Fsegment35.m4v'),
|
|
318
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
319
|
-
];
|
|
320
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
321
|
-
'CMCD=nor%3D%22..%252F300kbps%252Fsegment35.m4v%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
|
|
322
|
-
);
|
|
323
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
324
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
325
|
-
'CMCD-Request': 'nor="..%2F300kbps%2Fsegment35.m4v"',
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('Section 6, Example #7:', () => {
|
|
330
|
-
const cmcdObjects = [
|
|
331
|
-
new CmcdNextRangeRequest('12323-48763'),
|
|
332
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
333
|
-
];
|
|
334
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
335
|
-
'CMCD=nrr%3D%2212323-48763%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
|
|
336
|
-
);
|
|
337
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
338
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
339
|
-
'CMCD-Request': 'nrr="12323-48763"',
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it('Section 6, Example #8:', () => {
|
|
344
|
-
const cmcdObjects = [
|
|
345
|
-
new CmcdNextObjectRequest('..%2F300kbps%2Ftrack.m4v'),
|
|
346
|
-
new CmcdNextRangeRequest('12323-48763'),
|
|
347
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
348
|
-
];
|
|
349
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
350
|
-
'CMCD=nor%3D%22..%252F300kbps%252Ftrack.m4v%22%2Cnrr%3D%2212323-48763%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
|
|
351
|
-
);
|
|
352
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
353
|
-
'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
|
|
354
|
-
'CMCD-Request': 'nor="..%2F300kbps%2Ftrack.m4v",nrr="12323-48763"',
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it('Section 6, Example #9:', () => {
|
|
359
|
-
const cmcdObjects = [
|
|
360
|
-
new CmcdBufferLength(21300),
|
|
361
|
-
new CmcdEncodedBitrate(3200),
|
|
362
|
-
new CmcdBufferStarvation(true),
|
|
363
|
-
new CmcdContentId('faec5fc2-ac30-11ea-bb37-0242ac130002'),
|
|
364
|
-
new CmcdObjectDuration(4004),
|
|
365
|
-
new CmcdDeadline(18500),
|
|
366
|
-
new CmcdMeasuredThroughput(48100),
|
|
367
|
-
new CmcdNextObjectRequest('..%2F300kbps%2Ftrack.m4v'),
|
|
368
|
-
new CmcdNextRangeRequest('12323-48763'),
|
|
369
|
-
new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
|
|
370
|
-
new CmcdPlaybackRate(1.08),
|
|
371
|
-
new CmcdRequestedMaximumThroughput(12000),
|
|
372
|
-
new CmcdStreamingFormat(CmcdStreamingFormatToken.MpegDash),
|
|
373
|
-
new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
|
|
374
|
-
new CmcdStreamType(CmcdStreamTypeToken.Vod),
|
|
375
|
-
new CmcdStartup(true),
|
|
376
|
-
new CmcdTopBitrate(6000),
|
|
377
|
-
new CmcdVersion(1),
|
|
378
|
-
];
|
|
379
|
-
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
380
|
-
'CMCD=bl%3D21300%2Cbr%3D3200%2Cbs%2Ccid%3D%22faec5fc2-ac30-11ea-bb37-0242ac130002%22%2Cd%3D4004%2Cdl%3D18500%2Cmtp%3D48100%2Cnor%3D%22..%252F300kbps%252Ftrack.m4v%22%2Cnrr%3D%2212323-48763%22%2Cot%3Dv%2Cpr%3D1.08%2Crtp%3D12000%2Csf%3Dd%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22%2Cst%3Dv%2Csu%2Ctb%3D6000'
|
|
381
|
-
);
|
|
382
|
-
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
383
|
-
'CMCD-Request': 'bl=21300,dl=18500,mtp=48100,nor="..%2F300kbps%2Ftrack.m4v",nrr="12323-48763",su',
|
|
384
|
-
'CMCD-Object': 'br=3200,d=4004,ot=v,tb=6000',
|
|
385
|
-
'CMCD-Status': 'bs,rtp=12000',
|
|
386
|
-
'CMCD-Session':
|
|
387
|
-
'cid="faec5fc2-ac30-11ea-bb37-0242ac130002",pr=1.08,sf=d,sid="6e2fb550-c457-11e9-bb97-0800200c9a66",st=v',
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
|
|
2
|
-
import { HttpRequest, HttpRequestMethod, HttpRequestType, HttpResponseType, PlayerAPI } from 'bitmovin-player';
|
|
3
|
-
import { CmcdIntegration, CmcdConfig } from '../../src/ts/CmcdIntegration';
|
|
4
|
-
import { CmcdCustomKey, cmcdDataToHeader, cmcdDataToUrlParameter, CmcdHeaderType } from '../../src/ts/Cmcd';
|
|
5
|
-
|
|
6
|
-
// Jest Mocking for helper functions
|
|
7
|
-
jest.mock('../../src/ts/Cmcd', () => {
|
|
8
|
-
const actual = jest.requireActual<typeof import('../../src/ts/Cmcd')>('../../src/ts/Cmcd');
|
|
9
|
-
return {
|
|
10
|
-
...actual,
|
|
11
|
-
CmcdVersion: jest.fn(),
|
|
12
|
-
CmcdStreamType: jest.fn(),
|
|
13
|
-
CmcdPlaybackRate: jest.fn(),
|
|
14
|
-
CmcdObjectType: jest.fn(),
|
|
15
|
-
CmcdStreamingFormat: jest.fn(),
|
|
16
|
-
CmcdStartup: jest.fn(),
|
|
17
|
-
CmcdBufferStarvation: jest.fn(),
|
|
18
|
-
CmcdBufferLength: jest.fn(),
|
|
19
|
-
CmcdContentId: jest.fn(),
|
|
20
|
-
CmcdSessionId: jest.fn(),
|
|
21
|
-
CmcdEncodedBitrate: jest.fn(),
|
|
22
|
-
CmcdDeadline: jest.fn(),
|
|
23
|
-
CmcdTopBitrate: jest.fn(),
|
|
24
|
-
cmcdDataToHeader: jest.fn(),
|
|
25
|
-
cmcdDataToUrlParameter: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('CmcdIntegration', () => {
|
|
30
|
-
let cmcdIntegration: CmcdIntegration;
|
|
31
|
-
let config: CmcdConfig;
|
|
32
|
-
let mockPlayer: PlayerAPI;
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
config = {
|
|
36
|
-
sessionId: 'test-session',
|
|
37
|
-
contentId: 'test-content',
|
|
38
|
-
useQueryArgs: true,
|
|
39
|
-
customKeys: [],
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
cmcdIntegration = new CmcdIntegration(config);
|
|
43
|
-
|
|
44
|
-
mockPlayer = {
|
|
45
|
-
isLive: jest.fn().mockReturnValue(false),
|
|
46
|
-
getPlaybackSpeed: jest.fn().mockReturnValue(1),
|
|
47
|
-
buffer: {
|
|
48
|
-
getLevel: jest.fn().mockReturnValue({
|
|
49
|
-
targetLevel: 10,
|
|
50
|
-
level: 5,
|
|
51
|
-
}),
|
|
52
|
-
},
|
|
53
|
-
getAvailableAudioQualities: jest
|
|
54
|
-
.fn()
|
|
55
|
-
.mockReturnValue([{ bitrate: 64000 }, { bitrate: 128000 }, { bitrate: 256000 }]),
|
|
56
|
-
getAvailableVideoQualities: jest
|
|
57
|
-
.fn()
|
|
58
|
-
.mockReturnValue([{ bitrate: 500000 }, { bitrate: 800000 }, { bitrate: 1200000 }]),
|
|
59
|
-
getAvailableSegments: jest.fn(),
|
|
60
|
-
isStalled: jest.fn().mockReturnValue(false),
|
|
61
|
-
exports: {
|
|
62
|
-
HttpRequestType: {
|
|
63
|
-
MEDIA_AUDIO: 'media/audio',
|
|
64
|
-
MEDIA_VIDEO: 'media/video',
|
|
65
|
-
MANIFEST_HLS_MASTER: 'manifest/hls/master',
|
|
66
|
-
},
|
|
67
|
-
PlayerEvent: {
|
|
68
|
-
StallStarted: 'stallstarted',
|
|
69
|
-
StallEnded: 'stallended',
|
|
70
|
-
Seek: 'seek',
|
|
71
|
-
Seeked: 'seeked',
|
|
72
|
-
TimeShift: 'timeshift',
|
|
73
|
-
TimeShifted: 'timeshifted',
|
|
74
|
-
},
|
|
75
|
-
BufferType: {
|
|
76
|
-
ForwardDuration: 'forwardduration',
|
|
77
|
-
BackwardDuration: 'backwardduration',
|
|
78
|
-
},
|
|
79
|
-
MediaType: {
|
|
80
|
-
Video: 'video',
|
|
81
|
-
Audio: 'audio',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
on: jest.fn(),
|
|
85
|
-
} as unknown as PlayerAPI;
|
|
86
|
-
|
|
87
|
-
cmcdIntegration.setPlayer(mockPlayer);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should throw an error if custom keys without headerType are added when useQueryArgs is false', async () => {
|
|
91
|
-
config.useQueryArgs = false;
|
|
92
|
-
config.customKeys = [new CmcdCustomKey('com.example-myCustomKey', 'value')];
|
|
93
|
-
|
|
94
|
-
expect(() => new CmcdIntegration(config)).toThrowError();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should not throw an error if custom keys with headerType are added when useQueryArgs is false', async () => {
|
|
98
|
-
config.useQueryArgs = false;
|
|
99
|
-
config.customKeys = [new CmcdCustomKey('com.example-myCustomKey', 'value', CmcdHeaderType.Request)];
|
|
100
|
-
|
|
101
|
-
expect(() => new CmcdIntegration(config)).not.toThrowError();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should not throw an error if custom keys without headerType are added when useQueryArgs is true', async () => {
|
|
105
|
-
config.useQueryArgs = true;
|
|
106
|
-
config.customKeys = [new CmcdCustomKey('com.example-myCustomKey', 'value')];
|
|
107
|
-
expect(() => new CmcdIntegration(config)).not.toThrowError();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should not throw an error if custom keys with headerType are added when useQueryArgs is true', async () => {
|
|
111
|
-
config.useQueryArgs = true;
|
|
112
|
-
config.customKeys = [new CmcdCustomKey('com.example-myCustomKey', 'value', CmcdHeaderType.Request)];
|
|
113
|
-
expect(() => new CmcdIntegration(config)).not.toThrowError();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should throw an error if at least on custom key without headerType is added when useQueryArgs is false', async () => {
|
|
117
|
-
config.useQueryArgs = false;
|
|
118
|
-
config.customKeys = [
|
|
119
|
-
new CmcdCustomKey('com.example-myCustomKey1', 'value1', CmcdHeaderType.Status),
|
|
120
|
-
new CmcdCustomKey('com.example-myCustomKey2', 'value2'),
|
|
121
|
-
new CmcdCustomKey('com.example-myCustomKey3', 'value3', CmcdHeaderType.Request),
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
expect(() => new CmcdIntegration(config)).toThrowError();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('preprocessHttpRequest', () => {
|
|
128
|
-
it('should add CMCD data as query parameters when useQueryArgs is true', async () => {
|
|
129
|
-
const request: HttpRequest = {
|
|
130
|
-
credentials: 'omit',
|
|
131
|
-
method: HttpRequestMethod.GET,
|
|
132
|
-
responseType: HttpResponseType.ARRAYBUFFER,
|
|
133
|
-
url: 'https://example.com/manifest.m3u8',
|
|
134
|
-
headers: {},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
(cmcdDataToUrlParameter as jest.Mock).mockReturnValue('CMCD=mockData');
|
|
138
|
-
|
|
139
|
-
const processedRequest = await cmcdIntegration.preprocessHttpRequest(
|
|
140
|
-
HttpRequestType.MANIFEST_HLS_MASTER,
|
|
141
|
-
request
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
expect(processedRequest.url).toBe('https://example.com/manifest.m3u8?CMCD=mockData');
|
|
145
|
-
expect(cmcdDataToUrlParameter).toHaveBeenCalled();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should remove existing CMCD query parameters before adding new ones', async () => {
|
|
149
|
-
const request: HttpRequest = {
|
|
150
|
-
credentials: 'omit',
|
|
151
|
-
method: HttpRequestMethod.GET,
|
|
152
|
-
responseType: HttpResponseType.ARRAYBUFFER,
|
|
153
|
-
url: 'https://example.com/manifest.m3u8?CMCD=oldData',
|
|
154
|
-
headers: {},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
(cmcdDataToUrlParameter as jest.Mock).mockReturnValue('CMCD=newData');
|
|
158
|
-
|
|
159
|
-
const processedRequest = await cmcdIntegration.preprocessHttpRequest(HttpRequestType.MEDIA_VIDEO, request);
|
|
160
|
-
|
|
161
|
-
expect(processedRequest.url).toBe('https://example.com/manifest.m3u8?CMCD=newData');
|
|
162
|
-
expect(cmcdDataToUrlParameter).toHaveBeenCalled();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should add CMCD data as headers when useQueryArgs is false', async () => {
|
|
166
|
-
cmcdIntegration = new CmcdIntegration({ ...config, useQueryArgs: false });
|
|
167
|
-
cmcdIntegration.setPlayer(mockPlayer);
|
|
168
|
-
|
|
169
|
-
const request: HttpRequest = {
|
|
170
|
-
credentials: 'omit',
|
|
171
|
-
method: HttpRequestMethod.GET,
|
|
172
|
-
responseType: HttpResponseType.ARRAYBUFFER,
|
|
173
|
-
url: 'https://example.com/manifest.m3u8?',
|
|
174
|
-
headers: {},
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
(cmcdDataToHeader as jest.Mock).mockReturnValue({ 'CMCD-Header': 'mockData' });
|
|
178
|
-
|
|
179
|
-
const processedRequest = await cmcdIntegration.preprocessHttpRequest(HttpRequestType.MEDIA_VIDEO, request);
|
|
180
|
-
|
|
181
|
-
expect(processedRequest.headers).toEqual({ 'CMCD-Header': 'mockData' });
|
|
182
|
-
expect(cmcdDataToHeader).toHaveBeenCalled();
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|