@bitmovin/player-web-integration-cmcd 0.3.0 → 0.5.0
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 +16 -3
- package/README.md +6 -8
- package/dist/js/Cmcd.d.ts +3 -3
- package/dist/js/CmcdIntegration.d.ts +1 -0
- package/dist/js/bitmovin-player-integration-cmcd.js +1 -1
- package/package.json +3 -3
- package/test/ts/Cmcd.test.ts +83 -3
- package/test/ts/CmcdIntegration.test.ts +69 -57
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-01-14
|
|
11
|
+
### Added
|
|
12
|
+
- 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).
|
|
13
|
+
|
|
14
|
+
## [0.4.0] - 2025-12-01
|
|
15
|
+
### Changed
|
|
16
|
+
- Dependency versions
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Custom keys were not sorted alphabetically using the prefix due to an initial ambiguity in the specification
|
|
20
|
+
|
|
10
21
|
## [0.3.0] - 2025-03-26
|
|
11
22
|
### Added
|
|
12
23
|
- Description in package.json for the project
|
|
@@ -15,17 +26,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
15
26
|
### Fixed
|
|
16
27
|
- DASH loading failure when SegmentTimeline with $number format is used (#6)
|
|
17
28
|
- Duplicate CMCD query parameters for Live manifest (#5)
|
|
18
|
-
- Add `main` property to
|
|
29
|
+
- Add `main` property to package.json to enable usage in Jest tests
|
|
19
30
|
|
|
20
31
|
## [0.2.0] - 2023-10-13
|
|
21
32
|
### Added
|
|
22
|
-
- Support for adding Custom Keys statically in the
|
|
33
|
+
- Support for adding Custom Keys statically in the configuration
|
|
23
34
|
|
|
24
35
|
## 0.1.0 - 2023-05-05
|
|
25
36
|
### Added
|
|
26
37
|
- Initial CMCD release (Beta)
|
|
27
38
|
|
|
28
|
-
[Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.
|
|
39
|
+
[Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.5.0...HEAD
|
|
40
|
+
[0.5.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...v0.5.0
|
|
41
|
+
[0.4.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.3.0...v0.4.0
|
|
29
42
|
[0.3.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.1...v0.3.0
|
|
30
43
|
[0.2.1]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.0...v0.2.1
|
|
31
44
|
[0.2.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.1.0...v0.2.0
|
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
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
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
|
-
Install with npm
|
|
6
|
+
Install with npm:
|
|
7
7
|
```
|
|
8
|
-
npm install --save
|
|
8
|
+
npm install --save @bitmovin/player-web-integration-cmcd
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -45,7 +45,7 @@ After that, you create a Bitmovin Player instance as usual, then pass the player
|
|
|
45
45
|
cmcdIntegration.setPlayer(player);
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
It is
|
|
48
|
+
It is recommended to set the CMCD Session ID to the Analytics Impression ID as this enables you to connect CDN logs with CMCD data to Analytics sessions:
|
|
49
49
|
```js
|
|
50
50
|
cmcdIntegration.setSessionId(player.analytics.getCurrentImpressionId());
|
|
51
51
|
```
|
|
@@ -64,12 +64,10 @@ player.load(source);
|
|
|
64
64
|
- Run `npm run format` to format all files in the `src/` and `test/` folders
|
|
65
65
|
|
|
66
66
|
### Preparing a release
|
|
67
|
-
1.
|
|
68
|
-
2. Use
|
|
69
|
-
3. Run `npm run build`
|
|
70
|
-
4. Commit all the above changes, including the `dist/` folder
|
|
71
|
-
5. Tag the commit of the release (which contains the changes of the `dist/` folder), e.g. with `1.0.0`
|
|
67
|
+
1. Make sure all relevant changes were merged into the `main` branch, and there is an entry for each change in `CHANGELOG.md`
|
|
68
|
+
2. Use the [Release New Version](https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/actions/workflows/release.yml) Github Action Workflow and run it on the `main` branch
|
|
72
69
|
|
|
70
|
+
That's it! The workflow will take care of bumping the version (based on Changelog entries), updating the `CHANGELOG.md` file with release date and version, committing and tagging in this repository, and publishing the package to [NPM](https://www.npmjs.com/package/@bitmovin/player-web-integration-cmcd).
|
|
73
71
|
|
|
74
72
|
## Principles
|
|
75
73
|
- The Bitmovin Player shall not be packaged into the JS file created by the build of this integration. To achieve this, types can be imported and used, but no code must be imported/used (including string enums!)
|
package/dist/js/Cmcd.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare enum CmcdKeysToken {
|
|
|
59
59
|
TopBitrate = "tb",
|
|
60
60
|
CmcdVersion = "v"
|
|
61
61
|
}
|
|
62
|
-
declare enum CmcdHeaderType {
|
|
62
|
+
export declare enum CmcdHeaderType {
|
|
63
63
|
Object = "CMCD-Object",
|
|
64
64
|
Request = "CMCD-Request",
|
|
65
65
|
Status = "CMCD-Status",
|
|
@@ -350,7 +350,7 @@ export declare class CmcdVersion extends CmcdBase {
|
|
|
350
350
|
}
|
|
351
351
|
export declare class CmcdCustomKey extends CmcdBase {
|
|
352
352
|
readonly key: string;
|
|
353
|
-
readonly type
|
|
354
|
-
constructor(key: string, value: string | number);
|
|
353
|
+
readonly type: CmcdHeaderType;
|
|
354
|
+
constructor(key: string, value: string | number, headerType?: CmcdHeaderType);
|
|
355
355
|
}
|
|
356
356
|
export {};
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { AudioAdaptationData, HttpRequest, HttpRequestType, HttpResponse, HttpResponseBody, PlayerAPI, VideoAdaptationData } from 'bitmovin-player';
|
|
12
12
|
import { CmcdCustomKey } from './Cmcd';
|
|
13
13
|
export { CmcdCustomKey as CustomKey } from './Cmcd';
|
|
14
|
+
export { CmcdHeaderType as HeaderType } from './Cmcd';
|
|
14
15
|
export interface CmcdConfig {
|
|
15
16
|
sessionId?: string;
|
|
16
17
|
contentId?: 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={247:function(t,e,n){n.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 P},mP:function(){return g},mc:function(){return i},nf:function(){return o},oI:function(){return S},x9:function(){return V}});var r,i,u,o,s,a,c,p=(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 l(t){return t.sort((function(t,e){var n=t.key.substring(t.key.lastIndexOf("-")+1),r=e.key.substring(e.key.lastIndexOf("-")+1);return n.localeCompare(r)})).filter((function(t){return t.keyValuePairToString()}))}function h(t){var e=l(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(","),u=e.filter((function(t){return t.type===c.Session})).map((function(t){return t.keyValuePairToString()})).join(","),o={};return n&&(o[c.Request]=n),r&&(o[c.Object]=r),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,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 p(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 p(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 p(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 p(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 p(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.Deadline,n.type=c.Request,n}return p(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.MeasuredThroughput,n.type=c.Request,n}return p(e,t),e}(d),R=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.NextObjectRequest,n.type=c.Request,n}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 n=t.call(this,e)||this;return n.key=a.ObjectType,n.type=c.Object,n}return p(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d)),A=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.PlaybackRate,n.type=c.Session,n}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 n=t.call(this,e)||this;return n.key=a.RequestedMaximumThroughput,n.type=c.Status,n}return p(e,t),e}(d),x=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.StreamingFormat,n.type=c.Session,n}return p(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.SessionId,n.type=c.Session,n}return p(e,t),e}(d),D=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.StreamType,n.type=c.Session,n}return p(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),E=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.Startup,n.type=c.Request,n}return p(e,t),e.prototype.keyValuePairToString=function(){return!0===this.value?"".concat(this.key):""},e}(d),q=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.TopBitrate,n.type=c.Object,n}return p(e,t),e}(d),V=function(t){function e(e){var n=t.call(this,e)||this;return n.key=a.CmcdVersion,n.type=c.Session,n}return p(e,t),e.prototype.keyValuePairToString=function(){return this.value===s.v1?"":"".concat(this.key,"=").concat(this.value)},e}(d),P=function(t){function e(e,n){var r=t.call(this,n)||this;r.type=c.Session;var i=e.match(/^(.*-)(.*)$/);if(!i||!i[2])throw new Error("Custom key names MUST carry a hyphenated prefix (and SHOULD use a reverse-DNS syntax)");return r.key=e,r}return p(e,t),e}(d)},498:function(t,e,n){n.r(e),n.d(e,{CmcdIntegration:function(){return u},CustomKey:function(){return r.hq}});var r=n(247),i=function(){return i=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},i.apply(this,arguments)},u=function(){function t(t){var e=this;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 u=e.gatherCmcdData(t,n);if(e.useQueryArgs){var o=new URL(n.url);o.searchParams.delete("CMCD");var s=(0,r.RZ)(u),a=o.toString().includes("?")?"&":"?";n.url="".concat(o.toString()).concat(a).concat(s)}else{var c=(0,r.M)(u);n.headers=i(i({},n.headers),c)}return Promise.resolve(n)},this.preprocessHttpResponse=function(t,n){var r,i,u=n.elapsedTime,o=n.length;if(!u||!o)return Promise.resolve(n);var s=o/u/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.stalledSinceLastRequest=!1,this.currentVideoQuality=null,this.currentAudioQuality=null,this.isSeekingOrTimeshiftingOrStartup=!0,this.lastMeasuredThroughputAudio=0,this.lastMeasuredThroughputVideo=0,this.manifestType=null}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 n,i;if(!this.player)throw new Error("Bitmovin Player not provided!");var u=[];u.push(new r.x9(r.RE.v1)),u.push(new r.gu(this.player.isLive()?r.nf.Live:r.nf.Vod)),u.push(new r.RF(this.player.getPlaybackSpeed())),u.push(this.getObjectType(t)),u.push(this.getStreamingType(t)),this.contentId&&u.push(new r.be(this.contentId)),this.sessionId&&u.push(new r.Ph(this.sessionId)),this.isSeekingOrTimeshiftingOrStartup&&u.push(new r.Ao(!0)),(this.stalledSinceLastRequest||this.player.isStalled())&&(u.push(new r.mP(!0)),this.stalledSinceLastRequest=!1),t===(null===(n=this.player)||void 0===n?void 0:n.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===r.Dh.EncodedBitrate})),n=t.find((function(t){return t.key===r.Dh.ObjectDuration})),i=Boolean(t.find((function(t){return t.key===r.Dh.ObjectDuration}))),u=t.find((function(t){return t.key===r.Dh.Startup})),o=u&&!u.value;if(e&&n&&!i&&!o){var s=1e3*Number(n.value),a=Number(e.value)*(s/2);return[new r.J3(a)]}return[]},t.prototype.getStreamingType=function(t){var e,n,i;return this.manifestType||(t===(null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MANIFEST_DASH)?this.manifestType=r.QU.MpegDash:t===(null===(n=this.player)||void 0===n?void 0:n.exports.HttpRequestType.MANIFEST_HLS_MASTER)?this.manifestType=r.QU.Hls:t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MANIFEST_SMOOTH)?this.manifestType=r.QU.Smooth:this.manifestType=r.QU.Other),new r.Vf(this.manifestType)},t.prototype.getObjectType=function(t){var e,n,i,u,o,s,a,c,p,l,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.TS(r.mc.AudioOnly);break;case null===(n=this.player)||void 0===n?void 0:n.exports.HttpRequestType.MEDIA_VIDEO:S=new r.TS(r.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:S=new r.TS(r.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:S=new r.TS(r.mc.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:S=new r.TS(r.mc.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:S=new r.TS(r.mc.CaptionOrSubtitle);break;default:S=new r.TS(r.mc.Other)}return S},t.prototype.getAudioSegmentRequestSpecificData=function(t){var e,n=[];if(this.currentAudioQuality&&this.currentAudioQuality.bandwidth&&n.push(new r.ZH(Math.round(this.currentAudioQuality.bandwidth/1e3))),this.lastMeasuredThroughputAudio&&n.push(new r.dg(this.lastMeasuredThroughputAudio)),!this.player)return n;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Audio);if(i.targetLevel>0){n.push(new r.oI(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());n.push(new r.O5(1e3*u))}var o=this.player.getAvailableAudioQualities().reduce((function(t,e){return Math.max(t,e.bitrate)}),0)/1e3;if(o>0&&n.push(new r.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];n=n.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing audio segments:",t)}return n},t.prototype.getVideoSegmentRequestSpecificData=function(t){var e,n=[];if(this.currentVideoQuality&&this.currentVideoQuality.bandwidth&&n.push(new r.ZH(Math.round(this.currentVideoQuality.bandwidth/1e3))),this.lastMeasuredThroughputVideo&&n.push(new r.dg(this.lastMeasuredThroughputVideo)),!this.player)return n;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Video);if(i.targetLevel>0){n.push(new r.oI(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());n.push(new r.O5(1e3*u))}var o=this.player.getAvailableVideoQualities().reduce((function(t,e){return Math.max(t,e.bitrate)}),0)/1e3;if(o>0&&n.push(new r.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];n=n.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing video segments:",t)}return n},t.prototype.getNextObjectAndObjectDurationCmcdData=function(t,e){var n=[],i=t.findIndex((function(t){return t.url===e}));if(i>-1){var u=t[i];if(Number.isNaN(u.duration)||n.push(new r.T8(1e3*Number(u.duration))),i+1<t.length){var o=t[i+1];o.url&&n.push(new r.I3(o.url))}}return n},t}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var u=e[r]={exports:{}};return t[r](u,u.exports,n),u.exports}return n.d=function(t,e){for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},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(247),n(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={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)}()}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitmovin/player-web-integration-cmcd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Conviva analytics integration for the Bitmovin Player",
|
|
5
5
|
"types": "dist/js/CmcdIntegration.d.ts",
|
|
6
6
|
"browser": "dist/js/bitmovin-player-integration-cmcd.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"ts-jest": "^29.0.5",
|
|
39
39
|
"ts-loader": "^9.4.2",
|
|
40
40
|
"typescript": "^4.9.5",
|
|
41
|
-
"webpack": "^5.
|
|
41
|
+
"webpack": "^5.76.0",
|
|
42
42
|
"webpack-cli": "^5.0.1",
|
|
43
|
-
"webpack-dev-server": "^
|
|
43
|
+
"webpack-dev-server": "^5.2.1",
|
|
44
44
|
"webpack-merge": "^5.8.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
package/test/ts/Cmcd.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
CmcdCustomKey,
|
|
7
7
|
CmcdDeadline,
|
|
8
8
|
CmcdEncodedBitrate,
|
|
9
|
+
CmcdHeaderType,
|
|
9
10
|
CmcdMeasuredThroughput,
|
|
10
11
|
CmcdNextObjectRequest,
|
|
11
12
|
CmcdNextRangeRequest,
|
|
@@ -79,6 +80,57 @@ describe('Cmcd', () => {
|
|
|
79
80
|
expect(cmcdUrlParams3).toEqual(cmcdUrlParams4);
|
|
80
81
|
});
|
|
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
|
+
|
|
82
134
|
describe('Cmcd classes', () => {
|
|
83
135
|
it('should ignore keys with empty string value', () => {
|
|
84
136
|
expect(new CmcdContentId('').keyValuePairToString()).toEqual('');
|
|
@@ -158,6 +210,34 @@ describe('Cmcd', () => {
|
|
|
158
210
|
});
|
|
159
211
|
});
|
|
160
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
|
+
|
|
161
241
|
describe('CMCD Spec Examples', () => {
|
|
162
242
|
// Examples from CMCD v1 spec Section 6 taken as test cases
|
|
163
243
|
|
|
@@ -220,11 +300,11 @@ describe('Cmcd', () => {
|
|
|
220
300
|
it('Section 6, Example #5:', () => {
|
|
221
301
|
const cmcdObjects = [
|
|
222
302
|
new CmcdObjectDuration(4004),
|
|
223
|
-
new CmcdCustomKey('com.example-myNumericKey', 500),
|
|
224
|
-
new CmcdCustomKey('com.example-myStringKey', 'myStringValue'),
|
|
303
|
+
new CmcdCustomKey('com.example-myNumericKey', 500, CmcdHeaderType.Session),
|
|
304
|
+
new CmcdCustomKey('com.example-myStringKey', 'myStringValue', CmcdHeaderType.Session),
|
|
225
305
|
];
|
|
226
306
|
expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
|
|
227
|
-
'CMCD=
|
|
307
|
+
'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
|
|
228
308
|
);
|
|
229
309
|
expect(cmcdDataToHeader(cmcdObjects)).toEqual({
|
|
230
310
|
'CMCD-Object': 'd=4004',
|
|
@@ -1,55 +1,30 @@
|
|
|
1
1
|
import { describe, beforeEach, it, expect, jest } from '@jest/globals';
|
|
2
|
-
import { HttpRequest, HttpRequestType, PlayerAPI } from 'bitmovin-player';
|
|
2
|
+
import { HttpRequest, HttpRequestMethod, HttpRequestType, HttpResponseType, PlayerAPI } from 'bitmovin-player';
|
|
3
3
|
import { CmcdIntegration, CmcdConfig } from '../../src/ts/CmcdIntegration';
|
|
4
|
-
import { cmcdDataToHeader, cmcdDataToUrlParameter } from '../../src/ts/Cmcd';
|
|
4
|
+
import { CmcdCustomKey, cmcdDataToHeader, cmcdDataToUrlParameter, CmcdHeaderType } from '../../src/ts/Cmcd';
|
|
5
5
|
|
|
6
6
|
// Jest Mocking for helper functions
|
|
7
|
-
jest.mock('../../src/ts/Cmcd', () =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
MpegDash: 'd',
|
|
29
|
-
Smooth: 's',
|
|
30
|
-
Other: 'o',
|
|
31
|
-
},
|
|
32
|
-
CmcdKeysToken: {
|
|
33
|
-
EncodedBitrate: 'br',
|
|
34
|
-
ObjectDuration: 'd',
|
|
35
|
-
Startup: 'su',
|
|
36
|
-
},
|
|
37
|
-
CmcdVersion: jest.fn(),
|
|
38
|
-
CmcdStreamType: jest.fn(),
|
|
39
|
-
CmcdPlaybackRate: jest.fn(),
|
|
40
|
-
CmcdObjectType: jest.fn(),
|
|
41
|
-
CmcdStreamingFormat: jest.fn(),
|
|
42
|
-
CmcdStartup: jest.fn(),
|
|
43
|
-
CmcdBufferStarvation: jest.fn(),
|
|
44
|
-
CmcdBufferLength: jest.fn(),
|
|
45
|
-
CmcdContentId: jest.fn(),
|
|
46
|
-
CmcdSessionId: jest.fn(),
|
|
47
|
-
CmcdEncodedBitrate: jest.fn(),
|
|
48
|
-
CmcdDeadline: jest.fn(),
|
|
49
|
-
CmcdTopBitrate: jest.fn(),
|
|
50
|
-
cmcdDataToHeader: jest.fn(),
|
|
51
|
-
cmcdDataToUrlParameter: jest.fn(),
|
|
52
|
-
}));
|
|
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
|
+
});
|
|
53
28
|
|
|
54
29
|
describe('CmcdIntegration', () => {
|
|
55
30
|
let cmcdIntegration: CmcdIntegration;
|
|
@@ -112,12 +87,49 @@ describe('CmcdIntegration', () => {
|
|
|
112
87
|
cmcdIntegration.setPlayer(mockPlayer);
|
|
113
88
|
});
|
|
114
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
|
+
|
|
115
127
|
describe('preprocessHttpRequest', () => {
|
|
116
128
|
it('should add CMCD data as query parameters when useQueryArgs is true', async () => {
|
|
117
129
|
const request: HttpRequest = {
|
|
118
|
-
credentials:
|
|
119
|
-
method:
|
|
120
|
-
responseType:
|
|
130
|
+
credentials: 'omit',
|
|
131
|
+
method: HttpRequestMethod.GET,
|
|
132
|
+
responseType: HttpResponseType.ARRAYBUFFER,
|
|
121
133
|
url: 'https://example.com/manifest.m3u8',
|
|
122
134
|
headers: {},
|
|
123
135
|
};
|
|
@@ -135,9 +147,9 @@ describe('CmcdIntegration', () => {
|
|
|
135
147
|
|
|
136
148
|
it('should remove existing CMCD query parameters before adding new ones', async () => {
|
|
137
149
|
const request: HttpRequest = {
|
|
138
|
-
credentials:
|
|
139
|
-
method:
|
|
140
|
-
responseType:
|
|
150
|
+
credentials: 'omit',
|
|
151
|
+
method: HttpRequestMethod.GET,
|
|
152
|
+
responseType: HttpResponseType.ARRAYBUFFER,
|
|
141
153
|
url: 'https://example.com/manifest.m3u8?CMCD=oldData',
|
|
142
154
|
headers: {},
|
|
143
155
|
};
|
|
@@ -155,9 +167,9 @@ describe('CmcdIntegration', () => {
|
|
|
155
167
|
cmcdIntegration.setPlayer(mockPlayer);
|
|
156
168
|
|
|
157
169
|
const request: HttpRequest = {
|
|
158
|
-
credentials:
|
|
159
|
-
method:
|
|
160
|
-
responseType:
|
|
170
|
+
credentials: 'omit',
|
|
171
|
+
method: HttpRequestMethod.GET,
|
|
172
|
+
responseType: HttpResponseType.ARRAYBUFFER,
|
|
161
173
|
url: 'https://example.com/manifest.m3u8?',
|
|
162
174
|
headers: {},
|
|
163
175
|
};
|