@bitmovin/player-web-integration-cmcd 0.4.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 CHANGED
@@ -7,6 +7,10 @@ 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
+
10
14
  ## [0.4.0] - 2025-12-01
11
15
  ### Changed
12
16
  - Dependency versions
@@ -32,7 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
32
36
  ### Added
33
37
  - Initial CMCD release (Beta)
34
38
 
35
- [Unreleased]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.4.0...HEAD
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
36
41
  [0.4.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.3.0...v0.4.0
37
42
  [0.3.0]: https://github.com/bitmovin/bitmovin-player-web-integration-cmcd/compare/v0.2.1...v0.3.0
38
43
  [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={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.4.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",
@@ -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,
@@ -87,19 +88,21 @@ describe('Cmcd', () => {
87
88
  ];
88
89
 
89
90
  const result = cmcdDataToUrlParameter(cmcdObjects);
90
-
91
+
91
92
  // Custom keys should come first alphabetically before 'd'
92
93
  // 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
+ expect(result).toEqual(
95
+ 'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
96
+ );
94
97
  });
95
98
 
96
99
  it('should maintain strict alphabetical order regardless of input order with mixed custom and standard keys', () => {
97
100
  const cmcdObjects1 = [
98
101
  new CmcdObjectDuration(4004), // 'd'
99
- new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
102
+ new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
100
103
  new CmcdBufferLength(0), // 'bl'
101
104
  ];
102
-
105
+
103
106
  const cmcdObjects2 = [
104
107
  new CmcdBufferLength(0), // 'bl'
105
108
  new CmcdCustomKey('com.example-myKey', 500), // 'com.example-myKey'
@@ -108,7 +111,7 @@ describe('Cmcd', () => {
108
111
 
109
112
  const result1 = cmcdDataToUrlParameter(cmcdObjects1);
110
113
  const result2 = cmcdDataToUrlParameter(cmcdObjects2);
111
-
114
+
112
115
  expect(result1).toEqual(result2);
113
116
  // Should be: bl, com.example-myKey, d
114
117
  expect(result1).toEqual('CMCD=bl%3D0%2Ccom.example-myKey%3D500%2Cd%3D4004');
@@ -123,7 +126,7 @@ describe('Cmcd', () => {
123
126
  ];
124
127
 
125
128
  const result = cmcdDataToUrlParameter(cmcdObjects);
126
-
129
+
127
130
  // Expected alphabetical order: bl, d, m-custom-key, z-custom-key
128
131
  expect(result).toEqual('CMCD=bl%3D100%2Cd%3D4004%2Cm-custom-key%3D123%2Cz-custom-key%3D%22value%22');
129
132
  });
@@ -207,6 +210,34 @@ describe('Cmcd', () => {
207
210
  });
208
211
  });
209
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
+
210
241
  describe('CMCD Spec Examples', () => {
211
242
  // Examples from CMCD v1 spec Section 6 taken as test cases
212
243
 
@@ -269,8 +300,8 @@ describe('Cmcd', () => {
269
300
  it('Section 6, Example #5:', () => {
270
301
  const cmcdObjects = [
271
302
  new CmcdObjectDuration(4004),
272
- new CmcdCustomKey('com.example-myNumericKey', 500),
273
- new CmcdCustomKey('com.example-myStringKey', 'myStringValue'),
303
+ new CmcdCustomKey('com.example-myNumericKey', 500, CmcdHeaderType.Session),
304
+ new CmcdCustomKey('com.example-myStringKey', 'myStringValue', CmcdHeaderType.Session),
274
305
  ];
275
306
  expect(cmcdDataToUrlParameter(cmcdObjects)).toEqual(
276
307
  'CMCD=com.example-myNumericKey%3D500%2Ccom.example-myStringKey%3D%22myStringValue%22%2Cd%3D4004'
@@ -357,4 +388,4 @@ describe('Cmcd', () => {
357
388
  });
358
389
  });
359
390
  });
360
- });
391
+ });
@@ -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
- 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
- }));
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: undefined,
119
- method: undefined,
120
- responseType: undefined,
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: undefined,
139
- method: undefined,
140
- responseType: undefined,
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: undefined,
159
- method: undefined,
160
- responseType: undefined,
170
+ credentials: 'omit',
171
+ method: HttpRequestMethod.GET,
172
+ responseType: HttpResponseType.ARRAYBUFFER,
161
173
  url: 'https://example.com/manifest.m3u8?',
162
174
  headers: {},
163
175
  };