@bitmovin/player-web-integration-cmcd 0.4.0 → 0.6.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 CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-07-29
11
+ ### Changed
12
+ - 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.
13
+
14
+ ### Fixed
15
+ - Query parameters already present on a request URL were re-encoded when `useQueryArgs` is enabled. Only the appended `CMCD` parameter is URL encoded now.
16
+
17
+ ## [0.5.0] - 2026-01-14
18
+ ### Added
19
+ - 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).
20
+
10
21
  ## [0.4.0] - 2025-12-01
11
22
  ### Changed
12
23
  - Dependency versions
@@ -32,7 +43,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
32
43
  ### Added
33
44
  - Initial CMCD release (Beta)
34
45
 
35
- [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...HEAD
46
+ [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.6.0...HEAD
47
+ [0.6.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.5.0...v0.6.0
48
+ [0.5.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...v0.5.0
36
49
  [0.4.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.3.0...v0.4.0
37
50
  [0.3.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.1...v0.3.0
38
51
  [0.2.1]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.0...v0.2.1
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 = CmcdHeaderType.Session;
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,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 P},mP:function(){return g},mc:function(){return i},nf:function(){return o},oI:function(){return S},x9:function(){return V}});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),S=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.BufferLength,r.type=c.Request,r}return p(e,t),e}(d),g=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.BufferStarvation,r.type=c.Status,r}return 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),V=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),P=function(t){function e(e,r){var n=t.call(this,r)||this;n.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 n.key=e,n}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}});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;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}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,S;switch(t){case null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MEDIA_AUDIO:S=new n.TS(n.mc.AudioOnly);break;case null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_VIDEO:S=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:S=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:S=new n.TS(n.mc.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:S=new n.TS(n.mc.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:S=new n.TS(n.mc.CaptionOrSubtitle);break;default:S=new n.TS(n.mc.Other)}return S},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,r){r.d(e,{$y:function(){return o},CT:function(){return T},II:function(){return u},JP:function(){return a},KQ:function(){return s},Nv:function(){return y},P$:function(){return m},Qf:function(){return j},S5:function(){return h},ST:function(){return i},T:function(){return D},W1:function(){return P},Wf:function(){return R},X5:function(){return v},XO:function(){return c},Xk:function(){return g},YM:function(){return E},Yj:function(){return S},e$:function(){return b},fB:function(){return k},hU:function(){return A},nd:function(){return M},o5:function(){return O},p$:function(){return x},w6:function(){return q},xq:function(){return I}});var n,i,u,o,s,a,c,l=(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)});function p(t){return t.sort(function(t,e){return t.key.localeCompare(e.key)}).filter(function(t){return t.keyValuePairToString()})}function h(t){var e=p(t),r=e.filter(function(t){return t.type===c.Request}).map(function(t){return t.keyValuePairToString()}).join(","),n=e.filter(function(t){return t.type===c.Object}).map(function(t){return t.keyValuePairToString()}).join(","),i=e.filter(function(t){return t.type===c.Status}).map(function(t){return t.keyValuePairToString()}).join(","),u=e.filter(function(t){return t.type===c.Session}).map(function(t){return t.keyValuePairToString()}).join(","),o={};return r&&(o[c.Request]=r),n&&(o[c.Object]=n),i&&(o[c.Status]=i),u&&(o[c.Session]=u),o}function y(t){var e=p(t).map(function(t){return t.keyValuePairToString()}).join(",");return"CMCD=".concat(encodeURIComponent(e))}!function(t){t.AudioOnly="a",t.VideoOnly="v",t.MuxedVideoAudio="av",t.ManifestOrPlaylistTextFile="m",t.InitSegment="i",t.CaptionOrSubtitle="c",t.TimedTextTrack="tt",t.CryptographicKeyOrLicenseOrCertificate="k",t.Other="o"}(i||(i={})),function(t){t.MpegDash="d",t.Hls="h",t.Smooth="s",t.Other="o"}(u||(u={})),function(t){t.Vod="v",t.Live="l"}(o||(o={})),function(t){t[t.v1=1]="v1"}(s||(s={})),function(t){t.EncodedBitrate="br",t.BufferLength="bl",t.BufferStarvation="bs",t.ContentId="cid",t.ObjectDuration="d",t.Deadline="dl",t.MeasuredThroughput="mtp",t.NextObjectRequest="nor",t.NextRangeRequest="nrr",t.ObjectType="ot",t.PlaybackRate="pr",t.RequestedMaximumThroughput="rtp",t.StreamingFormat="sf",t.SessionId="sid",t.StreamType="st",t.Startup="su",t.TopBitrate="tb",t.CmcdVersion="v"}(a||(a={})),function(t){t.Object="CMCD-Object",t.Request="CMCD-Request",t.Status="CMCD-Status",t.Session="CMCD-Session"}(c||(c={}));var f,d=function(){function t(t){this.value=t}return t.prototype.keyValuePairToString=function(){return"string"==typeof this.value?this.value?"".concat(this.key,"=").concat((t=this.value,e=/"/g,r=/\\/g,'"'.concat(t.replace(r,"\\\\").replace(e,'\\"'),'"'))):"":"boolean"==typeof this.value&&!0===this.value?"".concat(this.key):"".concat(this.key,"=").concat(this.value);var t,e,r},t}(),v=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.EncodedBitrate,r.type=c.Object,r}return l(e,t),e}(d),S=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.BufferLength,r.type=c.Request,r}return l(e,t),e}(d),g=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.BufferStarvation,r.type=c.Status,r}return l(e,t),e}(d),T=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ContentId,r.type=c.Session,r}return l(e,t),e}(d),m=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ObjectDuration,r.type=c.Object,r}return l(e,t),e}(d),b=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.Deadline,r.type=c.Request,r}return l(e,t),e}(d),O=function(t){function e(e){var r=t.call(this,100*Math.round(e/100))||this;return r.key=a.MeasuredThroughput,r.type=c.Request,r}return l(e,t),e}(d),k=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.NextObjectRequest,r.type=c.Request,r}return l(e,t),e}(d),A=(l(function(t){var e=f.call(this,t)||this;return e.key=a.NextRangeRequest,e.type=c.Request,e},f=d),function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.ObjectType,r.type=c.Object,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d)),M=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.PlaybackRate,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return 1===this.value?"":"".concat(this.key,"=").concat(this.value)},e}(d),R=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.RequestedMaximumThroughput,r.type=c.Status,r}return l(e,t),e}(d),I=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamingFormat,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),x=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.SessionId,r.type=c.Session,r}return l(e,t),e}(d),E=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.StreamType,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return"".concat(this.key,"=").concat(this.value)},e}(d),D=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.Startup,r.type=c.Request,r}return l(e,t),e.prototype.keyValuePairToString=function(){return!0===this.value?"".concat(this.key):""},e}(d),P=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.TopBitrate,r.type=c.Object,r}return l(e,t),e}(d),q=function(t){function e(e){var r=t.call(this,e)||this;return r.key=a.CmcdVersion,r.type=c.Session,r}return l(e,t),e.prototype.keyValuePairToString=function(){return this.value===s.v1?"":"".concat(this.key,"=").concat(this.value)},e}(d),j=function(t){function e(e,r,n){var i=t.call(this,r)||this,u=e.match(/^(.*-)(.*)$/);if(!u||!u[2])throw new Error("Custom key names MUST carry a hyphenated prefix (and SHOULD use a reverse-DNS syntax)");return i.key=e,i.type=Object.values(c).includes(n)?n:null,i}return l(e,t),e}(d)},779:function(t,e,r){r.r(e),r.d(e,{CmcdIntegration:function(){return o},CustomKey:function(){return n.Qf},HeaderType:function(){return n.XO}});var n=r(145),i=function(){return i=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)},u=function(t,e,r){if(r||2===arguments.length)for(var n,i=0,u=e.length;i<u;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))},o=function(){function t(t){var e=this;if(this.onVideoAdaptation=function(t){return e.currentVideoQuality=t.representations.filter(function(e){return e.id===t.suggested})[0],t.suggested},this.onAudioAdaptation=function(t){return e.currentAudioQuality=t.representations.filter(function(e){return e.id===t.suggested})[0],t.suggested},this.preprocessHttpRequest=function(t,r){var o=e.gatherCmcdData(t,r);if(e.useQueryArgs)r.url=function(t,e){var r=t.indexOf("?"),n=t.indexOf("#"),i=-1===n?"":t.slice(n),o=-1===n?t:t.slice(0,n);if(-1===r||-1!==n&&r>n)return"".concat(o,"?").concat(e).concat(i);var s=o.slice(0,r),a=o.slice(r+1).split("&").filter(function(t){return""!==t&&"CMCD"!==t&&!t.startsWith("CMCD=")}),c=u(u([],a,!0),[e],!1).join("&");return"".concat(s,"?").concat(c).concat(i)}(r.url,(0,n.Nv)(o));else{var s=(0,n.S5)(o);r.headers=i(i({},r.headers),s)}return Promise.resolve(r)},this.preprocessHttpResponse=function(t,r){var n,i,u=r.elapsedTime,o=r.length;if(!u||!o)return Promise.resolve(r);var s=o/u/1e3;return t===((null===(n=e.player)||void 0===n?void 0:n.exports.HttpRequestType.MEDIA_AUDIO)||"media/audio")&&(e.lastMeasuredThroughputAudio=Math.round(100*s)/100),t===((null===(i=e.player)||void 0===i?void 0:i.exports.HttpRequestType.MEDIA_VIDEO)||"media/video")&&(e.lastMeasuredThroughputVideo=Math.round(100*s)/100),Promise.resolve(r)},this.useQueryArgs=t.useQueryArgs||!1,this.sessionId=t.sessionId||"",this.contentId=t.contentId||"",this.customKeys=t.customKeys||[],this.stalledSinceLastRequest=!1,this.currentVideoQuality=null,this.currentAudioQuality=null,this.isSeekingOrTimeshiftingOrStartup=!0,this.lastMeasuredThroughputAudio=0,this.lastMeasuredThroughputVideo=0,this.manifestType=null,!1===this.useQueryArgs&&this.customKeys.length>0){var r=this.customKeys.filter(function(t){return null===t.type}).map(function(t){return t.key});if(r.length>0)throw new Error("All custom keys must have an HTTP header type configured if HTTP header mode is used (`CmcdConfig.useQueryArgs = false`), but is missing for "+r.join(", "))}}return t.prototype.setPlayer=function(t){var e=this;this.player=t,this.player.on(t.exports.PlayerEvent.StallStarted,function(){e.stalledSinceLastRequest=!0,e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.StallEnded,function(){return e.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(t.exports.PlayerEvent.Seek,function(){return e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.Seeked,function(){return e.isSeekingOrTimeshiftingOrStartup=!1}),this.player.on(t.exports.PlayerEvent.TimeShift,function(){return e.isSeekingOrTimeshiftingOrStartup=!0}),this.player.on(t.exports.PlayerEvent.TimeShifted,function(){return e.isSeekingOrTimeshiftingOrStartup=!1})},t.prototype.setSessionId=function(t){this.sessionId=t},t.prototype.setContentId=function(t){this.contentId=t},t.prototype.gatherCmcdData=function(t,e){var r,i;if(!this.player)throw new Error("Bitmovin Player not provided!");var u=[];u.push(new n.w6(n.KQ.v1)),u.push(new n.YM(this.player.isLive()?n.$y.Live:n.$y.Vod)),u.push(new n.nd(this.player.getPlaybackSpeed())),u.push(this.getObjectType(t)),u.push(this.getStreamingType(t)),this.contentId&&u.push(new n.CT(this.contentId)),this.sessionId&&u.push(new n.p$(this.sessionId)),this.isSeekingOrTimeshiftingOrStartup&&u.push(new n.T(!0)),(this.stalledSinceLastRequest||this.player.isStalled())&&(u.push(new n.Xk(!0)),this.stalledSinceLastRequest=!1),t===(null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_AUDIO)?u=u.concat(this.getAudioSegmentRequestSpecificData(e)):t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MEDIA_VIDEO)&&(u=u.concat(this.getVideoSegmentRequestSpecificData(e))),u.concat(this.getRequestedMaximumThroughput(u));for(var o=0,s=this.customKeys;o<s.length;o++){var a=s[o];u.push(a)}return u},t.prototype.getRequestedMaximumThroughput=function(t){var e=t.find(function(t){return t.key===n.JP.EncodedBitrate}),r=t.find(function(t){return t.key===n.JP.ObjectDuration}),i=Boolean(t.find(function(t){return t.key===n.JP.ObjectDuration})),u=t.find(function(t){return t.key===n.JP.Startup}),o=u&&!u.value;if(e&&r&&!i&&!o){var s=1e3*Number(r.value),a=Number(e.value)*(s/2);return[new n.Wf(a)]}return[]},t.prototype.getStreamingType=function(t){var e,r,i;return this.manifestType||(t===(null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MANIFEST_DASH)?this.manifestType=n.II.MpegDash:t===(null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MANIFEST_HLS_MASTER)?this.manifestType=n.II.Hls:t===(null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.MANIFEST_SMOOTH)?this.manifestType=n.II.Smooth:this.manifestType=n.II.Other),new n.xq(this.manifestType)},t.prototype.getObjectType=function(t){var e,r,i,u,o,s,a,c,l,p,h,y,f,d,v,S;switch(t){case null===(e=this.player)||void 0===e?void 0:e.exports.HttpRequestType.MEDIA_AUDIO:S=new n.hU(n.ST.AudioOnly);break;case null===(r=this.player)||void 0===r?void 0:r.exports.HttpRequestType.MEDIA_VIDEO:S=new n.hU(n.ST.VideoOnly);break;case null===(i=this.player)||void 0===i?void 0:i.exports.HttpRequestType.DRM_CERTIFICATE_FAIRPLAY:case null===(u=this.player)||void 0===u?void 0:u.exports.HttpRequestType.DRM_LICENSE_CLEARKEY:case null===(o=this.player)||void 0===o?void 0:o.exports.HttpRequestType.DRM_LICENSE_FAIRPLAY:case null===(s=this.player)||void 0===s?void 0:s.exports.HttpRequestType.DRM_LICENSE_PLAYREADY:case null===(a=this.player)||void 0===a?void 0:a.exports.HttpRequestType.DRM_LICENSE_WIDEVINE:case null===(c=this.player)||void 0===c?void 0:c.exports.HttpRequestType.KEY_HLS_AES:S=new n.hU(n.ST.CryptographicKeyOrLicenseOrCertificate);break;case null===(l=this.player)||void 0===l?void 0:l.exports.HttpRequestType.MANIFEST_ADS:case null===(p=this.player)||void 0===p?void 0:p.exports.HttpRequestType.MANIFEST_DASH:case null===(h=this.player)||void 0===h?void 0:h.exports.HttpRequestType.MANIFEST_HLS_MASTER:case null===(y=this.player)||void 0===y?void 0:y.exports.HttpRequestType.MANIFEST_HLS_VARIANT:case null===(f=this.player)||void 0===f?void 0:f.exports.HttpRequestType.MANIFEST_SMOOTH:S=new n.hU(n.ST.ManifestOrPlaylistTextFile);break;case null===(d=this.player)||void 0===d?void 0:d.exports.HttpRequestType.MEDIA_SEGMENTINDEX:S=new n.hU(n.ST.InitSegment);break;case null===(v=this.player)||void 0===v?void 0:v.exports.HttpRequestType.MEDIA_SUBTITLES:S=new n.hU(n.ST.CaptionOrSubtitle);break;default:S=new n.hU(n.ST.Other)}return S},t.prototype.getAudioSegmentRequestSpecificData=function(t){var e,r=[];if(this.currentAudioQuality&&this.currentAudioQuality.bandwidth&&r.push(new n.X5(Math.round(this.currentAudioQuality.bandwidth/1e3))),this.lastMeasuredThroughputAudio&&r.push(new n.o5(this.lastMeasuredThroughputAudio)),!this.player)return r;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Audio);if(i.targetLevel>0){r.push(new n.Yj(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.e$(1e3*u))}var o=this.player.getAvailableAudioQualities().reduce(function(t,e){return Math.max(t,e.bitrate)},0)/1e3;if(o>0&&r.push(new n.W1(o)),this.currentVideoQuality)try{var s=this.player.getAvailableSegments();for(var a in s)if(a.startsWith("video/")){var c=s[a][this.currentVideoQuality.id];r=r.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing audio segments:",t)}return r},t.prototype.getVideoSegmentRequestSpecificData=function(t){var e,r=[];if(this.currentVideoQuality&&this.currentVideoQuality.bandwidth&&r.push(new n.X5(Math.round(this.currentVideoQuality.bandwidth/1e3))),this.lastMeasuredThroughputVideo&&r.push(new n.o5(this.lastMeasuredThroughputVideo)),!this.player)return r;var i=this.player.buffer.getLevel(this.player.exports.BufferType.ForwardDuration,this.player.exports.MediaType.Video);if(i.targetLevel>0){r.push(new n.Yj(1e3*i.level));var u=i.level/(null===(e=this.player)||void 0===e?void 0:e.getPlaybackSpeed());r.push(new n.e$(1e3*u))}var o=this.player.getAvailableVideoQualities().reduce(function(t,e){return Math.max(t,e.bitrate)},0)/1e3;if(o>0&&r.push(new n.W1(o)),this.currentVideoQuality)try{var s=this.player.getAvailableSegments();for(var a in s)if(a.startsWith("video/")){var c=s[a][this.currentVideoQuality.id];r=r.concat(this.getNextObjectAndObjectDurationCmcdData(c,t.url))}}catch(t){console.error("Error processing video segments:",t)}return r},t.prototype.getNextObjectAndObjectDurationCmcdData=function(t,e){var r=[],i=t.findIndex(function(t){return t.url===e});if(i>-1){var u=t[i];if(Number.isNaN(u.duration)||r.push(new n.P$(1e3*Number(u.duration))),i+1<t.length){var o=t[i+1];o.url&&r.push(new n.fB(o.url))}}return r},t}()}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var u=e[n]={exports:{}};return t[n](u,u.exports,r),u.exports}return r.d=function(t,e){if(Array.isArray(e))for(var n=0;n<e.length;){var i=e[n++],u=e[n++];r.o(t,i)?0===u&&n++:0===u?Object.defineProperty(t,i,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,i,{enumerable:!0,get:u})}else for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(145),r(779)}()});
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@bitmovin/player-web-integration-cmcd",
3
- "version": "0.4.0",
3
+ "version": "0.6.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",
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": "ssh://git@github.com:bitmovin/bitmovin-player-web-integration-cmcd.git"
16
+ "url": "ssh://git@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
@@ -1,5 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'jsdom',
5
- };
@@ -1,360 +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
- CmcdMeasuredThroughput,
10
- CmcdNextObjectRequest,
11
- CmcdNextRangeRequest,
12
- CmcdObjectDuration,
13
- CmcdObjectType,
14
- CmcdObjectTypeToken,
15
- CmcdPlaybackRate,
16
- CmcdRequestedMaximumThroughput,
17
- CmcdSessionId,
18
- CmcdStartup,
19
- CmcdStreamType,
20
- CmcdStreamTypeToken,
21
- CmcdStreamingFormat,
22
- CmcdStreamingFormatToken,
23
- CmcdTopBitrate,
24
- CmcdVersion,
25
- CmcdVersionNumbers,
26
- cmcdDataToHeader,
27
- cmcdDataToUrlParameter,
28
- } from '../../src/ts/Cmcd';
29
-
30
- describe('Cmcd', () => {
31
- beforeEach(() => {
32
- // fresh setup before every test case
33
- });
34
-
35
- it('should transform CMCD objects to URL parameter', () => {
36
- const cmcdObjects = [
37
- new CmcdEncodedBitrate(500),
38
- new CmcdBufferLength(0),
39
- new CmcdBufferStarvation(true),
40
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
41
- ];
42
-
43
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=bl%3D0%2Cbr%3D500%2Cbs%2Cot%3Dv');
44
- });
45
-
46
- it('should always sort the URL parameters alphabetically by CMCD key', () => {
47
- const cmcdObjects1 = [
48
- new CmcdEncodedBitrate(500),
49
- new CmcdBufferLength(0),
50
- new CmcdBufferStarvation(true),
51
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
52
- ];
53
- const cmcdObjects2 = [
54
- new CmcdBufferLength(0),
55
- new CmcdBufferStarvation(true),
56
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
57
- new CmcdEncodedBitrate(500),
58
- ];
59
- const cmcdObjects3 = [
60
- new CmcdBufferStarvation(true),
61
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
62
- new CmcdBufferLength(0),
63
- new CmcdEncodedBitrate(500),
64
- ];
65
- const cmcdObjects4 = [
66
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
67
- new CmcdBufferLength(0),
68
- new CmcdBufferStarvation(true),
69
- new CmcdEncodedBitrate(500),
70
- ];
71
-
72
- const cmcdUrlParams1 = cmcdDataToUrlParameter(cmcdObjects1);
73
- const cmcdUrlParams2 = cmcdDataToUrlParameter(cmcdObjects2);
74
- const cmcdUrlParams3 = cmcdDataToUrlParameter(cmcdObjects3);
75
- const cmcdUrlParams4 = cmcdDataToUrlParameter(cmcdObjects4);
76
-
77
- expect(cmcdUrlParams1).toEqual(cmcdUrlParams2);
78
- expect(cmcdUrlParams2).toEqual(cmcdUrlParams3);
79
- expect(cmcdUrlParams3).toEqual(cmcdUrlParams4);
80
- });
81
-
82
- it('should sort custom keys alphabetically with standard keys according to full key name', () => {
83
- const cmcdObjects = [
84
- new CmcdObjectDuration(4004), // key: 'd'
85
- new CmcdCustomKey('com.example-myNumericKey', 500), // key: 'com.example-myNumericKey'
86
- new CmcdCustomKey('com.example-myStringKey', 'myStringValue'), // key: 'com.example-myStringKey'
87
- ];
88
-
89
- const result = cmcdDataToUrlParameter(cmcdObjects);
90
-
91
- // Custom keys should come first alphabetically before 'd'
92
- // Expected order: 'com.example-myNumericKey', 'com.example-myStringKey', 'd'
93
- expect(result).toEqual('CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004');
94
- });
95
-
96
- it('should maintain strict alphabetical order regardless of input order with mixed custom and standard keys', () => {
97
- const cmcdObjects1 = [
98
- new CmcdObjectDuration(4004), // 'd'
99
- new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
100
- new CmcdBufferLength(0), // 'bl'
101
- ];
102
-
103
- const cmcdObjects2 = [
104
- new CmcdBufferLength(0), // 'bl'
105
- new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
106
- new CmcdObjectDuration(4004), // 'd'
107
- ];
108
-
109
- const result1 = cmcdDataToUrlParameter(cmcdObjects1);
110
- const result2 = cmcdDataToUrlParameter(cmcdObjects2);
111
-
112
- expect(result1).toEqual(result2);
113
- // Should be: bl, com.example-myKey, d
114
- expect(result1).toEqual('CMCD=bl%3D0%2Ccom.example-myKey%3D500%2Cd%3D4004');
115
- });
116
-
117
- it('should sort custom keys that come after standard keys alphabetically', () => {
118
- const cmcdObjects = [
119
- new CmcdBufferLength(100), // 'bl'
120
- new CmcdCustomKey('z-custom-key', 'value'), // 'z-custom-key' - should come last
121
- new CmcdObjectDuration(4004), // 'd'
122
- new CmcdCustomKey('m-custom-key', 123), // 'm-custom-key' - should come between 'd' and 'z'
123
- ];
124
-
125
- const result = cmcdDataToUrlParameter(cmcdObjects);
126
-
127
- // Expected alphabetical order: bl, d, m-custom-key, z-custom-key
128
- expect(result).toEqual('CMCD=bl%3D100%2Cd%3D4004%2Cm-custom-key%3D123%2Cz-custom-key%3D%22value%22');
129
- });
130
-
131
- describe('Cmcd classes', () => {
132
- it('should ignore keys with empty string value', () => {
133
- expect(new CmcdContentId('').keyValuePairToString()).toEqual('');
134
- });
135
-
136
- it('should quote strings', () => {
137
- expect(new CmcdContentId('test-content-id').keyValuePairToString()).toEqual('cid="test-content-id"');
138
- });
139
-
140
- it('should escape backslashes in strings', () => {
141
- expect(new CmcdContentId('test-\\content\\-id').keyValuePairToString()).toEqual('cid="test-\\\\content\\\\-id"');
142
- });
143
-
144
- it('should escape quotes in strings', () => {
145
- expect(new CmcdContentId('"test"-content-id').keyValuePairToString()).toEqual('cid="\\"test\\"-content-id"');
146
- });
147
-
148
- it('should escape quotes and backslashes in strings', () => {
149
- expect(new CmcdContentId('"test"-content\\-id').keyValuePairToString()).toEqual(
150
- 'cid="\\"test\\"-content\\\\-id"'
151
- );
152
- });
153
-
154
- it('should truncate true boolean values to just include the CMCD key', () => {
155
- expect(new CmcdBufferStarvation(true).keyValuePairToString()).toEqual('bs');
156
- });
157
-
158
- it('should explicitly list false boolean values', () => {
159
- expect(new CmcdBufferStarvation(false).keyValuePairToString()).toEqual('bs=false');
160
- });
161
-
162
- it('should list number values "as is"', () => {
163
- expect(new CmcdEncodedBitrate(5432).keyValuePairToString()).toEqual('br=5432');
164
- });
165
-
166
- it('should list token values "as is"', () => {
167
- expect(new CmcdObjectType(CmcdObjectTypeToken.VideoOnly).keyValuePairToString()).toEqual('ot=v');
168
- expect(new CmcdObjectType(CmcdObjectTypeToken.AudioOnly).keyValuePairToString()).toEqual('ot=a');
169
- expect(new CmcdObjectType(CmcdObjectTypeToken.CaptionOrSubtitle).keyValuePairToString()).toEqual('ot=c');
170
- expect(
171
- new CmcdObjectType(CmcdObjectTypeToken.CryptographicKeyOrLicenseOrCertificate).keyValuePairToString()
172
- ).toEqual('ot=k');
173
- expect(new CmcdObjectType(CmcdObjectTypeToken.InitSegment).keyValuePairToString()).toEqual('ot=i');
174
- expect(new CmcdObjectType(CmcdObjectTypeToken.ManifestOrPlaylistTextFile).keyValuePairToString()).toEqual('ot=m');
175
- expect(new CmcdObjectType(CmcdObjectTypeToken.MuxedVideoAudio).keyValuePairToString()).toEqual('ot=av');
176
- expect(new CmcdObjectType(CmcdObjectTypeToken.Other).keyValuePairToString()).toEqual('ot=o');
177
- expect(new CmcdObjectType(CmcdObjectTypeToken.TimedTextTrack).keyValuePairToString()).toEqual('ot=tt');
178
- });
179
-
180
- it('should round buffer length, deadline values to nearest 100ms', () => {
181
- expect(new CmcdBufferLength(5452).keyValuePairToString()).toEqual('bl=5500');
182
- expect(new CmcdBufferLength(5450).keyValuePairToString()).toEqual('bl=5500');
183
- expect(new CmcdBufferLength(5432).keyValuePairToString()).toEqual('bl=5400');
184
- expect(new CmcdDeadline(5452).keyValuePairToString()).toEqual('dl=5500');
185
- expect(new CmcdDeadline(5450).keyValuePairToString()).toEqual('dl=5500');
186
- expect(new CmcdDeadline(5432).keyValuePairToString()).toEqual('dl=5400');
187
- });
188
-
189
- it('should round measured throughput values to nearest 100kbps', () => {
190
- expect(new CmcdMeasuredThroughput(87654).keyValuePairToString()).toEqual('mtp=87700');
191
- expect(new CmcdMeasuredThroughput(87650).keyValuePairToString()).toEqual('mtp=87700');
192
- expect(new CmcdMeasuredThroughput(87649).keyValuePairToString()).toEqual('mtp=87600');
193
- });
194
-
195
- it('should remove playback rate if value is 1', () => {
196
- expect(new CmcdPlaybackRate(1).keyValuePairToString()).toEqual('');
197
- });
198
-
199
- it('should add playback rate if value is not 1', () => {
200
- expect(new CmcdPlaybackRate(1.08).keyValuePairToString()).toEqual('pr=1.08');
201
- expect(new CmcdPlaybackRate(0).keyValuePairToString()).toEqual('pr=0');
202
- expect(new CmcdPlaybackRate(2.52).keyValuePairToString()).toEqual('pr=2.52');
203
- });
204
-
205
- it('should remove CMCD version if value is 1', () => {
206
- expect(new CmcdVersion(CmcdVersionNumbers.v1).keyValuePairToString()).toEqual('');
207
- });
208
- });
209
-
210
- describe('CMCD Spec Examples', () => {
211
- // Examples from CMCD v1 spec Section 6 taken as test cases
212
-
213
- it('Section 6, Example #1:', () => {
214
- const cmcdObjects = [new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66')];
215
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=sid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22');
216
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
217
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
218
- });
219
- });
220
-
221
- it('Section 6, Example #2:', () => {
222
- const cmcdObjects = [
223
- new CmcdEncodedBitrate(3200),
224
- new CmcdBufferStarvation(true),
225
- new CmcdObjectDuration(4004),
226
- new CmcdMeasuredThroughput(25432),
227
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
228
- new CmcdRequestedMaximumThroughput(15000),
229
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
230
- new CmcdTopBitrate(6000),
231
- ];
232
-
233
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
234
- 'CMCD=br%3D3200%2Cbs%2Cd%3D4004%2Cmtp%3D25400%2Cot%3Dv%2Crtp%3D15000%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22%2Ctb%3D6000'
235
- );
236
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
237
- 'CMCD-Request': 'mtp=25400',
238
- 'CMCD-Object': 'br=3200,d=4004,ot=v,tb=6000',
239
- 'CMCD-Status': 'bs,rtp=15000',
240
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
241
- });
242
- });
243
-
244
- it('Section 6, Example #3:', () => {
245
- const cmcdObjects = [
246
- new CmcdBufferStarvation(true),
247
- new CmcdRequestedMaximumThroughput(15000),
248
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
249
- ];
250
- // Small mistake in the CMCD spec where 'bs' was truncated to 'b' in this query arg example
251
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
252
- 'CMCD=bs%2Crtp%3D15000%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
253
- );
254
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
255
- 'CMCD-Status': 'bs,rtp=15000',
256
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
257
- });
258
- });
259
-
260
- it('Section 6, Example #4:', () => {
261
- const cmcdObjects = [new CmcdBufferStarvation(true), new CmcdStartup(true)];
262
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual('CMCD=bs%2Csu');
263
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
264
- 'CMCD-Status': 'bs',
265
- 'CMCD-Request': 'su',
266
- });
267
- });
268
-
269
- it('Section 6, Example #5:', () => {
270
- const cmcdObjects = [
271
- new CmcdObjectDuration(4004),
272
- new CmcdCustomKey('com.example-myNumericKey', 500),
273
- new CmcdCustomKey('com.example-myStringKey', 'myStringValue'),
274
- ];
275
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
276
- 'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
277
- );
278
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
279
- 'CMCD-Object': 'd=4004',
280
- 'CMCD-Session': 'com.example-myNumericKey=500,com.example-myStringKey="myStringValue"',
281
- });
282
- });
283
-
284
- it('Section 6, Example #6:', () => {
285
- const cmcdObjects = [
286
- new CmcdNextObjectRequest('..%2F300kbps%2Fsegment35.m4v'),
287
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
288
- ];
289
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
290
- 'CMCD=nor%3D%22..%252F300kbps%252Fsegment35.m4v%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
291
- );
292
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
293
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
294
- 'CMCD-Request': 'nor="..%2F300kbps%2Fsegment35.m4v"',
295
- });
296
- });
297
-
298
- it('Section 6, Example #7:', () => {
299
- const cmcdObjects = [
300
- new CmcdNextRangeRequest('12323-48763'),
301
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
302
- ];
303
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
304
- 'CMCD=nrr%3D%2212323-48763%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
305
- );
306
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
307
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
308
- 'CMCD-Request': 'nrr="12323-48763"',
309
- });
310
- });
311
-
312
- it('Section 6, Example #8:', () => {
313
- const cmcdObjects = [
314
- new CmcdNextObjectRequest('..%2F300kbps%2Ftrack.m4v'),
315
- new CmcdNextRangeRequest('12323-48763'),
316
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
317
- ];
318
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
319
- 'CMCD=nor%3D%22..%252F300kbps%252Ftrack.m4v%22%2Cnrr%3D%2212323-48763%22%2Csid%3D%226e2fb550-c457-11e9-bb97-0800200c9a66%22'
320
- );
321
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
322
- 'CMCD-Session': 'sid="6e2fb550-c457-11e9-bb97-0800200c9a66"',
323
- 'CMCD-Request': 'nor="..%2F300kbps%2Ftrack.m4v",nrr="12323-48763"',
324
- });
325
- });
326
-
327
- it('Section 6, Example #9:', () => {
328
- const cmcdObjects = [
329
- new CmcdBufferLength(21300),
330
- new CmcdEncodedBitrate(3200),
331
- new CmcdBufferStarvation(true),
332
- new CmcdContentId('faec5fc2-ac30-11ea-bb37-0242ac130002'),
333
- new CmcdObjectDuration(4004),
334
- new CmcdDeadline(18500),
335
- new CmcdMeasuredThroughput(48100),
336
- new CmcdNextObjectRequest('..%2F300kbps%2Ftrack.m4v'),
337
- new CmcdNextRangeRequest('12323-48763'),
338
- new CmcdObjectType(CmcdObjectTypeToken.VideoOnly),
339
- new CmcdPlaybackRate(1.08),
340
- new CmcdRequestedMaximumThroughput(12000),
341
- new CmcdStreamingFormat(CmcdStreamingFormatToken.MpegDash),
342
- new CmcdSessionId('6e2fb550-c457-11e9-bb97-0800200c9a66'),
343
- new CmcdStreamType(CmcdStreamTypeToken.Vod),
344
- new CmcdStartup(true),
345
- new CmcdTopBitrate(6000),
346
- new CmcdVersion(1),
347
- ];
348
- expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
349
- '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'
350
- );
351
- expect(cmcdDataToHeader(cmcdObjects)).toEqual({
352
- 'CMCD-Request': 'bl=21300,dl=18500,mtp=48100,nor="..%2F300kbps%2Ftrack.m4v",nrr="12323-48763",su',
353
- 'CMCD-Object': 'br=3200,d=4004,ot=v,tb=6000',
354
- 'CMCD-Status': 'bs,rtp=12000',
355
- 'CMCD-Session':
356
- 'cid="faec5fc2-ac30-11ea-bb37-0242ac130002",pr=1.08,sf=d,sid="6e2fb550-c457-11e9-bb97-0800200c9a66",st=v',
357
- });
358
- });
359
- });
360
- });
@@ -1,173 +0,0 @@
1
- import { describe, beforeEach, it, expect, jest } from '@jest/globals';
2
- import { HttpRequest, HttpRequestType, PlayerAPI } from 'bitmovin-player';
3
- import { CmcdIntegration, CmcdConfig } from '../../src/ts/CmcdIntegration';
4
- import { cmcdDataToHeader, cmcdDataToUrlParameter } from '../../src/ts/Cmcd';
5
-
6
- // Jest Mocking for helper functions
7
- jest.mock('../../src/ts/Cmcd', () => ({
8
- CmcdVersionNumbers: {
9
- v1: 1,
10
- },
11
- CmcdStreamTypeToken: {
12
- Live: 'live',
13
- Vod: 'vod',
14
- },
15
- CmcdObjectTypeToken: {
16
- AudioOnly: 'a',
17
- VideoOnly: 'v',
18
- ManifestOrPlaylistTextFile: 'm',
19
- InitSegment: 'i',
20
- CaptionOrSubtitle: 'c',
21
- CryptographicKeyOrLicenseOrCertificate: 'k',
22
- MuxedVideoAudio: 'av',
23
- Other: 'o',
24
- TimedTextTrack: 'tt',
25
- },
26
- CmcdStreamingFormatToken: {
27
- Hls: 'h',
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
- }));
53
-
54
- describe('CmcdIntegration', () => {
55
- let cmcdIntegration: CmcdIntegration;
56
- let config: CmcdConfig;
57
- let mockPlayer: PlayerAPI;
58
-
59
- beforeEach(() => {
60
- config = {
61
- sessionId: 'test-session',
62
- contentId: 'test-content',
63
- useQueryArgs: true,
64
- customKeys: [],
65
- };
66
-
67
- cmcdIntegration = new CmcdIntegration(config);
68
-
69
- mockPlayer = {
70
- isLive: jest.fn().mockReturnValue(false),
71
- getPlaybackSpeed: jest.fn().mockReturnValue(1),
72
- buffer: {
73
- getLevel: jest.fn().mockReturnValue({
74
- targetLevel: 10,
75
- level: 5,
76
- }),
77
- },
78
- getAvailableAudioQualities: jest
79
- .fn()
80
- .mockReturnValue([{ bitrate: 64000 }, { bitrate: 128000 }, { bitrate: 256000 }]),
81
- getAvailableVideoQualities: jest
82
- .fn()
83
- .mockReturnValue([{ bitrate: 500000 }, { bitrate: 800000 }, { bitrate: 1200000 }]),
84
- getAvailableSegments: jest.fn(),
85
- isStalled: jest.fn().mockReturnValue(false),
86
- exports: {
87
- HttpRequestType: {
88
- MEDIA_AUDIO: 'media/audio',
89
- MEDIA_VIDEO: 'media/video',
90
- MANIFEST_HLS_MASTER: 'manifest/hls/master',
91
- },
92
- PlayerEvent: {
93
- StallStarted: 'stallstarted',
94
- StallEnded: 'stallended',
95
- Seek: 'seek',
96
- Seeked: 'seeked',
97
- TimeShift: 'timeshift',
98
- TimeShifted: 'timeshifted',
99
- },
100
- BufferType: {
101
- ForwardDuration: 'forwardduration',
102
- BackwardDuration: 'backwardduration',
103
- },
104
- MediaType: {
105
- Video: 'video',
106
- Audio: 'audio',
107
- },
108
- },
109
- on: jest.fn(),
110
- } as unknown as PlayerAPI;
111
-
112
- cmcdIntegration.setPlayer(mockPlayer);
113
- });
114
-
115
- describe('preprocessHttpRequest', () => {
116
- it('should add CMCD data as query parameters when useQueryArgs is true', async () => {
117
- const request: HttpRequest = {
118
- credentials: undefined,
119
- method: undefined,
120
- responseType: undefined,
121
- url: 'https://example.com/manifest.m3u8',
122
- headers: {},
123
- };
124
-
125
- (cmcdDataToUrlParameter as jest.Mock).mockReturnValue('CMCD=mockData');
126
-
127
- const processedRequest = await cmcdIntegration.preprocessHttpRequest(
128
- HttpRequestType.MANIFEST_HLS_MASTER,
129
- request
130
- );
131
-
132
- expect(processedRequest.url).toBe('https://example.com/manifest.m3u8?CMCD=mockData');
133
- expect(cmcdDataToUrlParameter).toHaveBeenCalled();
134
- });
135
-
136
- it('should remove existing CMCD query parameters before adding new ones', async () => {
137
- const request: HttpRequest = {
138
- credentials: undefined,
139
- method: undefined,
140
- responseType: undefined,
141
- url: 'https://example.com/manifest.m3u8?CMCD=oldData',
142
- headers: {},
143
- };
144
-
145
- (cmcdDataToUrlParameter as jest.Mock).mockReturnValue('CMCD=newData');
146
-
147
- const processedRequest = await cmcdIntegration.preprocessHttpRequest(HttpRequestType.MEDIA_VIDEO, request);
148
-
149
- expect(processedRequest.url).toBe('https://example.com/manifest.m3u8?CMCD=newData');
150
- expect(cmcdDataToUrlParameter).toHaveBeenCalled();
151
- });
152
-
153
- it('should add CMCD data as headers when useQueryArgs is false', async () => {
154
- cmcdIntegration = new CmcdIntegration({ ...config, useQueryArgs: false });
155
- cmcdIntegration.setPlayer(mockPlayer);
156
-
157
- const request: HttpRequest = {
158
- credentials: undefined,
159
- method: undefined,
160
- responseType: undefined,
161
- url: 'https://example.com/manifest.m3u8?',
162
- headers: {},
163
- };
164
-
165
- (cmcdDataToHeader as jest.Mock).mockReturnValue({ 'CMCD-Header': 'mockData' });
166
-
167
- const processedRequest = await cmcdIntegration.preprocessHttpRequest(HttpRequestType.MEDIA_VIDEO, request);
168
-
169
- expect(processedRequest.headers).toEqual({ 'CMCD-Header': 'mockData' });
170
- expect(cmcdDataToHeader).toHaveBeenCalled();
171
- });
172
- });
173
- });