@playkit-js/playkit-js-providers 2.45.0-canary.0-877671b → 2.45.0-canary.0-0441953

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.
@@ -1,2 +1,2 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(function(){return function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===n(t)?t:String(t)}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,o(n.key),n)}}function s(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t,r){return(t=o(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}e.r(t),e.d(t,{NAME:function(){return S},OVPConfiguration:function(){return y},OVPStatsService:function(){return T},RequestBuilder:function(){return l},VERSION:function(){return C}});var a=function(){return{VERSION:"",DEBUG:{value:"",name:""},ERROR:{value:"",name:""},INFO:{value:"",name:""},OFF:{value:"",name:""},TIME:{value:"",name:""},TRACE:{value:"",name:""},WARN:{value:"",name:""},createDefaultHandler:function(){},debug:function(){},enabledFor:function(){},error:function(){},get:function(){},getLevel:function(){},info:function(){},log:function(){},setHandler:function(){},setLevel:function(){},time:function(){},timeEnd:function(){},trace:function(){},useDefaults:function(){},warn:function(){}}};var c=function(e){return a(e)},f=s((function e(t,n,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};r(this,e),this.severity=t,this.category=n,this.code=o,this.data=i,e._logger.error("Category:".concat(n," | Code:").concat(o," |"),i)}));u(f,"Severity",{RECOVERABLE:1,CRITICAL:2}),u(f,"Category",{NETWORK:1,SERVICE:2,PROVIDER:3}),u(f,"Code",{UNSUPPORTED_SCHEME:1e3,BAD_HTTP_STATUS:1001,HTTP_ERROR:1002,TIMEOUT:1003,MALFORMED_DATA_URI:1004,BAD_SERVER_RESPONSE:1005,MULTIREQUEST_API_ERROR:1006,API_RESPONSE_MISMATCH:1007,ERROR:2e3,BLOCK_ACTION:2001,MEDIA_STATUS_NOT_READY:2002,SCHEDULED_RESTRICTED:2003,DELETED_ENTRY:2004,MISSING_MANDATORY_PARAMS:3e3,MISSING_PLAY_SOURCE:3001,METHOD_NOT_IMPLEMENTED:3002}),u(f,"_logger",c("Error"));var l=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Map;r(this,e),u(this,"retryConfig",{async:!0,timeout:0,maxAttempts:4}),u(this,"_attemptCounter",1),this.headers=t}return s(e,[{key:"getUrl",value:function(e){return e+"/service/"+this.service+(this.action?"/action/"+this.action:"")}},{key:"doHttpRequest",value:function(){var e=this,t=new Promise((function(t,r){e._requestPromise={resolve:t,reject:r}}));return this.url||this._requestPromise.reject(new f(f.Severity.CRITICAL,f.Category.NETWORK,f.Code.MALFORMED_DATA_URI,{url:this.url})),this._createXHR(),t}},{key:"_createXHR",value:function(){var e=this,t=new XMLHttpRequest;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status)try{var r=JSON.parse(t.responseText);return e.responseHeaders=e._getResponseHeaders(t),e._requestPromise.resolve(r)}catch(r){e._requestPromise.reject(e._createError(t,f.Code.BAD_SERVER_RESPONSE,{text:t.responseText}))}},t.open(this.method,this.url,this.retryConfig.async),this.retryConfig.async&&this.retryConfig.timeout&&(t.timeout=this.retryConfig.timeout);var r=performance.now();t.ontimeout=function(){e._handleError(t,f.Code.TIMEOUT,{timeout:(performance.now()-r)/1e3,statusText:t.statusText})},t.onerror=t.onabort=function(){e._handleError(t,f.Code.HTTP_ERROR,{text:t.responseText,statusText:t.statusText})},this.headers.forEach((function(e,r){t.setRequestHeader(r,e)})),t.send(this.params)}},{key:"_getResponseHeaders",value:function(e){return e.getAllResponseHeaders().split("\n").filter((function(e){return 0===e.toLowerCase().indexOf("x-")}))}},{key:"_handleError",value:function(e,t,r){var n=this._createError(e,t,r);if(e.onreadystatechange=function(){},e.onerror=function(){},e.ontimeout=function(){},e.onabort=function(){},!(this.retryConfig.maxAttempts&&this._attemptCounter<this.retryConfig.maxAttempts))return this._requestPromise.reject(n);this._attemptCounter++,this._createXHR()}},{key:"_createError",value:function(e,t,r){return Object.assign(r,{url:this.url,headers:this._getResponseHeaders(e),attempt:this._attemptCounter}),new f(f.Severity.CRITICAL,f.Category.NETWORK,t,r)}}]),e}(),p=function e(t){var r;return Array.isArray(t)?(r=t.length>0?t.slice(0):[]).forEach((function(t,o){("object"===n(t)||Array.isArray(t)&&t.length>0)&&(r[o]=e(t))})):"object"===n(t)?(r=Object.assign({},t),Object.keys(r).forEach((function(t){("object"===n(r[t])||Array.isArray(r[t])&&r[t].length>0)&&(r[t]=e(r[t]))}))):r=t,r},h={serviceUrl:"https://cdnapisec.kaltura.com/api_v3",cdnUrl:"https://cdnapisec.kaltura.com",serviceParams:{apiVersion:"3.3.0",format:1},useApiCaptions:!0,loadThumbnailWithKs:!1,replaceHostOnlyManifestUrls:!1},y=function(){function e(){r(this,e)}return s(e,null,[{key:"set",value:function(e){null!=e&&e.overrideServiceUrl&&(e.serviceUrl=e.overrideServiceUrl),e&&Object.assign(h,e)}},{key:"get",value:function(){return p(h)}},{key:"serviceUrl",get:function(){return h.serviceUrl}}]),e}();function v(e,t){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},v(e,t)}function d(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&v(e,t)}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){if(t&&("object"===n(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return m(e)}function R(e){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},R(e)}var E=s((function e(t){r(this,e),u(this,"hasError",!1),"KalturaAPIException"===t.objectType?(this.hasError=!0,this.error=new b(t.code,t.message)):t.error&&"KalturaAPIException"===t.error.objectType?(this.hasError=!0,this.error=new b(t.error.code,t.error.message)):this.data=t})),b=s((function e(t,n){r(this,e),this.code=t,this.message=n}));var O=function(e){d(i,e);var t,n,o=(t=i,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=R(t);if(n){var o=R(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return g(this,e)});function i(){var e;r(this,i);for(var t=arguments.length,n=new Array(t),s=0;s<t;s++)n[s]=arguments[s];return u(m(e=o.call.apply(o,[this].concat(n))),"requests",[]),e}return s(i,[{key:"add",value:function(e){this.requests.push(e);var t={},r={service:e.service,action:e.action};return Object.assign(t,u({},this.requests.length,Object.assign(r,e.params))),Object.assign(t,this.params),this.params=t,this}},{key:"execute",value:function(e){var t=this;return new Promise((function(r,n){try{t.params=JSON.stringify(t.params)}catch(e){i._logger.error("".concat(e.message)),n(new f(f.Severity.CRITICAL,f.Category.PROVIDER,f.Code.FAILED_PARSING_REQUEST,{error:e,params:t.params}))}t.doHttpRequest().then((function(o){var i=new _(o,e);i.success?r({headers:t.responseHeaders,response:i}):n(new f(f.Severity.CRITICAL,f.Category.NETWORK,f.Code.MULTIREQUEST_API_ERROR,{url:t.url,headers:t.responseHeaders,results:i.results}))}),(function(e){n(e)}))}))}}]),i}(l);u(O,"_logger",c("MultiRequestBuilder"));var _=s((function e(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];r(this,e),u(this,"results",[]);var o=t.result?t.result:t,i=(Array.isArray(o)?o:[o]).map((function(e){return new E(e)})),s=i.filter((function(e){return e.hasError}));s.forEach((function(t){e._logger.error("Service returned an error with error code: ".concat(t.error.code," and message: ").concat(t.error.message,"."))})),this.results=i,n&&s.length||s.length===this.results.length?this.success=!1:(this.results=this.results.filter((function(e){return!e.hasError})),this.success=!0)}));u(_,"_logger",c("MultiRequestResult"));var T=function(e){d(u,e);var t,o,i=(t=u,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=R(t);if(o){var n=R(this).constructor;e=Reflect.construct(r,arguments,n)}else e=r.apply(this,arguments);return g(this,e)});function u(){return r(this,u),i.apply(this,arguments)}return s(u,null,[{key:"collect",value:function(e,t,r,o){var i=y.get(),s={};Object.assign(s,i.serviceParams,{ks:t,clientTag:"html5:v"+r},o);var u,a,c,f,p,h=new l;return h.service="stats",h.action="collect",h.method="GET",h.tag="stats-collect",h.params=s,h.url=e+"?service="+h.service+"&action="+h.action+"&"+(u=h.params,a=[],c=/\[\]$/,f=function(e){return"[object Array]"===Object.prototype.toString.call(e)},p=function(e,t){t="function"==typeof t?t():null==t?"":t,a[a.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)},function e(t,r){var o,i,s;if(t)if(f(r))for(o=0,i=r.length;o<i;o++)c.test(t)?p(t,r[o]):e(t+":"+("object"===n(r[o])?o:""),r[o]);else if(r&&"[object Object]"===String(r))for(s in r)e(t+":"+s,r[s]);else p(t,r);else if(f(r))for(o=0,i=r.length;o<i;o++)p(r[o].name,r[o].value);else for(s in r)e(s,r[s]);return a}("",u).join("&").replace(/%20/g,"+")),h}}]),u}(function(){function e(){r(this,e)}return s(e,null,[{key:"getMultiRequest",value:function(e,t,r){var n=y.get(),o=n.serviceParams;Object.assign(o,{ks:t,clientTag:"html5:v"+e}),r&&Object.assign(o,{partnerId:r});var i=new Map;i.set("Content-Type","application/json");var s=new O(i);return s.method="POST",s.service="multirequest",s.url=s.getUrl(n.serviceUrl),s.params=o,s}}]),e}()),S="@playkit-js/playkit-js-providers-stats-service",C="2.45.0-canary.0-877671b";return t}()}));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(function(){return function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===n(t)?t:String(t)}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,o(n.key),n)}}function s(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t,r){return(t=o(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}e.r(t),e.d(t,{NAME:function(){return S},OVPConfiguration:function(){return y},OVPStatsService:function(){return T},RequestBuilder:function(){return l},VERSION:function(){return C}});var a=function(){return{VERSION:"",DEBUG:{value:"",name:""},ERROR:{value:"",name:""},INFO:{value:"",name:""},OFF:{value:"",name:""},TIME:{value:"",name:""},TRACE:{value:"",name:""},WARN:{value:"",name:""},createDefaultHandler:function(){},debug:function(){},enabledFor:function(){},error:function(){},get:function(){},getLevel:function(){},info:function(){},log:function(){},setHandler:function(){},setLevel:function(){},time:function(){},timeEnd:function(){},trace:function(){},useDefaults:function(){},warn:function(){}}};var c=function(e){return a(e)},f=s((function e(t,n,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};r(this,e),this.severity=t,this.category=n,this.code=o,this.data=i,e._logger.error("Category:".concat(n," | Code:").concat(o," |"),i)}));u(f,"Severity",{RECOVERABLE:1,CRITICAL:2}),u(f,"Category",{NETWORK:1,SERVICE:2,PROVIDER:3}),u(f,"Code",{UNSUPPORTED_SCHEME:1e3,BAD_HTTP_STATUS:1001,HTTP_ERROR:1002,TIMEOUT:1003,MALFORMED_DATA_URI:1004,BAD_SERVER_RESPONSE:1005,MULTIREQUEST_API_ERROR:1006,API_RESPONSE_MISMATCH:1007,ERROR:2e3,BLOCK_ACTION:2001,MEDIA_STATUS_NOT_READY:2002,SCHEDULED_RESTRICTED:2003,DELETED_ENTRY:2004,MISSING_MANDATORY_PARAMS:3e3,MISSING_PLAY_SOURCE:3001,METHOD_NOT_IMPLEMENTED:3002}),u(f,"_logger",c("Error"));var l=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Map;r(this,e),u(this,"retryConfig",{async:!0,timeout:0,maxAttempts:4}),u(this,"_attemptCounter",1),this.headers=t}return s(e,[{key:"getUrl",value:function(e){return e+"/service/"+this.service+(this.action?"/action/"+this.action:"")}},{key:"doHttpRequest",value:function(){var e=this,t=new Promise((function(t,r){e._requestPromise={resolve:t,reject:r}}));return this.url||this._requestPromise.reject(new f(f.Severity.CRITICAL,f.Category.NETWORK,f.Code.MALFORMED_DATA_URI,{url:this.url})),this._createXHR(),t}},{key:"_createXHR",value:function(){var e=this,t=new XMLHttpRequest;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status)try{var r=JSON.parse(t.responseText);return e.responseHeaders=e._getResponseHeaders(t),e._requestPromise.resolve(r)}catch(r){e._requestPromise.reject(e._createError(t,f.Code.BAD_SERVER_RESPONSE,{text:t.responseText}))}},t.open(this.method,this.url,this.retryConfig.async),this.retryConfig.async&&this.retryConfig.timeout&&(t.timeout=this.retryConfig.timeout);var r=performance.now();t.ontimeout=function(){e._handleError(t,f.Code.TIMEOUT,{timeout:(performance.now()-r)/1e3,statusText:t.statusText})},t.onerror=t.onabort=function(){e._handleError(t,f.Code.HTTP_ERROR,{text:t.responseText,statusText:t.statusText})},this.headers.forEach((function(e,r){t.setRequestHeader(r,e)})),t.send(this.params)}},{key:"_getResponseHeaders",value:function(e){return e.getAllResponseHeaders().split("\n").filter((function(e){return 0===e.toLowerCase().indexOf("x-")}))}},{key:"_handleError",value:function(e,t,r){var n=this._createError(e,t,r);if(e.onreadystatechange=function(){},e.onerror=function(){},e.ontimeout=function(){},e.onabort=function(){},!(this.retryConfig.maxAttempts&&this._attemptCounter<this.retryConfig.maxAttempts))return this._requestPromise.reject(n);this._attemptCounter++,this._createXHR()}},{key:"_createError",value:function(e,t,r){return Object.assign(r,{url:this.url,headers:this._getResponseHeaders(e),attempt:this._attemptCounter}),new f(f.Severity.CRITICAL,f.Category.NETWORK,t,r)}}]),e}(),p=function e(t){var r;return Array.isArray(t)?(r=t.length>0?t.slice(0):[]).forEach((function(t,o){("object"===n(t)||Array.isArray(t)&&t.length>0)&&(r[o]=e(t))})):"object"===n(t)?(r=Object.assign({},t),Object.keys(r).forEach((function(t){("object"===n(r[t])||Array.isArray(r[t])&&r[t].length>0)&&(r[t]=e(r[t]))}))):r=t,r},h={serviceUrl:"https://cdnapisec.kaltura.com/api_v3",cdnUrl:"https://cdnapisec.kaltura.com",serviceParams:{apiVersion:"3.3.0",format:1},useApiCaptions:!0,loadThumbnailWithKs:!1,replaceHostOnlyManifestUrls:!1},y=function(){function e(){r(this,e)}return s(e,null,[{key:"set",value:function(e){null!=e&&e.overrideServiceUrl&&(e.serviceUrl=e.overrideServiceUrl),e&&Object.assign(h,e)}},{key:"get",value:function(){return p(h)}},{key:"serviceUrl",get:function(){return h.serviceUrl}}]),e}();function v(e,t){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},v(e,t)}function d(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&v(e,t)}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){if(t&&("object"===n(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return m(e)}function R(e){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},R(e)}var E=s((function e(t){r(this,e),u(this,"hasError",!1),"KalturaAPIException"===t.objectType?(this.hasError=!0,this.error=new b(t.code,t.message)):t.error&&"KalturaAPIException"===t.error.objectType?(this.hasError=!0,this.error=new b(t.error.code,t.error.message)):this.data=t})),b=s((function e(t,n){r(this,e),this.code=t,this.message=n}));var O=function(e){d(i,e);var t,n,o=(t=i,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=R(t);if(n){var o=R(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return g(this,e)});function i(){var e;r(this,i);for(var t=arguments.length,n=new Array(t),s=0;s<t;s++)n[s]=arguments[s];return u(m(e=o.call.apply(o,[this].concat(n))),"requests",[]),e}return s(i,[{key:"add",value:function(e){this.requests.push(e);var t={},r={service:e.service,action:e.action};return Object.assign(t,u({},this.requests.length,Object.assign(r,e.params))),Object.assign(t,this.params),this.params=t,this}},{key:"execute",value:function(e){var t=this;return new Promise((function(r,n){try{t.params=JSON.stringify(t.params)}catch(e){i._logger.error("".concat(e.message)),n(new f(f.Severity.CRITICAL,f.Category.PROVIDER,f.Code.FAILED_PARSING_REQUEST,{error:e,params:t.params}))}t.doHttpRequest().then((function(o){var i=new _(o,e);i.success?r({headers:t.responseHeaders,response:i}):n(new f(f.Severity.CRITICAL,f.Category.NETWORK,f.Code.MULTIREQUEST_API_ERROR,{url:t.url,headers:t.responseHeaders,results:i.results}))}),(function(e){n(e)}))}))}}]),i}(l);u(O,"_logger",c("MultiRequestBuilder"));var _=s((function e(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];r(this,e),u(this,"results",[]);var o=t.result?t.result:t,i=(Array.isArray(o)?o:[o]).map((function(e){return new E(e)})),s=i.filter((function(e){return e.hasError}));s.forEach((function(t){e._logger.error("Service returned an error with error code: ".concat(t.error.code," and message: ").concat(t.error.message,"."))})),this.results=i,n&&s.length||s.length===this.results.length?this.success=!1:(this.results=this.results.filter((function(e){return!e.hasError})),this.success=!0)}));u(_,"_logger",c("MultiRequestResult"));var T=function(e){d(u,e);var t,o,i=(t=u,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=R(t);if(o){var n=R(this).constructor;e=Reflect.construct(r,arguments,n)}else e=r.apply(this,arguments);return g(this,e)});function u(){return r(this,u),i.apply(this,arguments)}return s(u,null,[{key:"collect",value:function(e,t,r,o){var i=y.get(),s={};Object.assign(s,i.serviceParams,{ks:t,clientTag:"html5:v"+r},o);var u,a,c,f,p,h=new l;return h.service="stats",h.action="collect",h.method="GET",h.tag="stats-collect",h.params=s,h.url=e+"?service="+h.service+"&action="+h.action+"&"+(u=h.params,a=[],c=/\[\]$/,f=function(e){return"[object Array]"===Object.prototype.toString.call(e)},p=function(e,t){t="function"==typeof t?t():null==t?"":t,a[a.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)},function e(t,r){var o,i,s;if(t)if(f(r))for(o=0,i=r.length;o<i;o++)c.test(t)?p(t,r[o]):e(t+":"+("object"===n(r[o])?o:""),r[o]);else if(r&&"[object Object]"===String(r))for(s in r)e(t+":"+s,r[s]);else p(t,r);else if(f(r))for(o=0,i=r.length;o<i;o++)p(r[o].name,r[o].value);else for(s in r)e(s,r[s]);return a}("",u).join("&").replace(/%20/g,"+")),h}}]),u}(function(){function e(){r(this,e)}return s(e,null,[{key:"getMultiRequest",value:function(e,t,r){var n=y.get(),o=n.serviceParams;Object.assign(o,{ks:t,clientTag:"html5:v"+e}),r&&Object.assign(o,{partnerId:r});var i=new Map;i.set("Content-Type","application/json");var s=new O(i);return s.method="POST",s.service="multirequest",s.url=s.getUrl(n.serviceUrl),s.params=o,s}}]),e}()),S="@playkit-js/playkit-js-providers-stats-service",C="2.45.0-canary.0-0441953";return t}()}));
2
2
  //# sourceMappingURL=playkit-stats-service.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playkit-js/playkit-js-providers",
3
- "version": "2.45.0-canary.0-877671b",
3
+ "version": "2.45.0-canary.0-0441953",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/**/*",
@@ -1,6 +1,7 @@
1
1
  import MultiRequestBuilder, {MultiRequestResult} from './multi-request-builder';
2
2
  import Error from '../../util/error/error';
3
3
  import {ILoader, ProviderNetworkRetryParameters} from '../../types';
4
+ import RequestSequenceBuilder from '../ott/request-sequence-builder';
4
5
 
5
6
  export default class DataLoaderManager {
6
7
  /**
@@ -15,6 +16,13 @@ export default class DataLoaderManager {
15
16
  * @protected
16
17
  */
17
18
  protected _multiRequest!: MultiRequestBuilder;
19
+
20
+ /**
21
+ * @member - Loaders single requests
22
+ * @type {RequestSequenceBuilder}
23
+ * @protected
24
+ */
25
+ protected _singleRequests!: RequestSequenceBuilder;
18
26
  /**
19
27
  * @member - Loaders multi response
20
28
  * @type {MultiRequestResult}
@@ -32,6 +40,7 @@ export default class DataLoaderManager {
32
40
 
33
41
  constructor(networkRetryConfig: ProviderNetworkRetryParameters) {
34
42
  this._networkRetryConfig = networkRetryConfig;
43
+ this._singleRequests = new RequestSequenceBuilder();
35
44
  }
36
45
 
37
46
  /**
@@ -46,7 +55,12 @@ export default class DataLoaderManager {
46
55
  const execution_loader = new loader(params);
47
56
  if (execution_loader.isValid()) {
48
57
  this._loaders.set(loader.id, execution_loader);
49
- // Get the start index from the multiReqeust before adding current execution_loader requests
58
+ const disableMultirequest = (execution_loader as any).disableMultirequest;
59
+ if (disableMultirequest) {
60
+ this._singleRequests.add(execution_loader);
61
+ }
62
+ else {
63
+ // Get the start index from the multiRequest before adding current execution_loader requests
50
64
  const startIndex = this._multiRequest.requests.length;
51
65
  // Get the requests
52
66
  const requests = execution_loader.requests;
@@ -61,6 +75,7 @@ export default class DataLoaderManager {
61
75
  const executionLoaderResponseMap = Array.from(new Array(requests.length), (val, index) => index + startIndex);
62
76
  // Add to map
63
77
  this._loadersResponseMap.set(loader.id, executionLoaderResponseMap);
78
+ }
64
79
  }
65
80
  }
66
81
 
@@ -72,24 +87,31 @@ export default class DataLoaderManager {
72
87
  */
73
88
  public fetchData(requestsMustSucceed?: boolean): Promise<any> {
74
89
  return new Promise((resolve, reject) => {
75
- this._multiRequest.execute(requestsMustSucceed).then(
76
- data => {
77
- this._multiResponse = data.response;
78
- const preparedData: any = this.prepareData(data.response);
79
- if (preparedData.success) {
80
- resolve(this._loaders);
81
- } else {
82
- reject(
83
- new Error(Error.Severity.CRITICAL, Error.Category.NETWORK, Error.Code.API_RESPONSE_MISMATCH, {
84
- headers: data.headers
85
- })
86
- );
90
+ if (this._singleRequests.loaders.size > 0) {
91
+ this._singleRequests.execute()
92
+ .then(() => resolve(this._loaders))
93
+ .catch(err => reject(err));
94
+ }
95
+ else {
96
+ this._multiRequest.execute(requestsMustSucceed).then(
97
+ data => {
98
+ this._multiResponse = data.response;
99
+ const preparedData: any = this.prepareData(data.response);
100
+ if (preparedData.success) {
101
+ resolve(this._loaders);
102
+ } else {
103
+ reject(
104
+ new Error(Error.Severity.CRITICAL, Error.Category.NETWORK, Error.Code.API_RESPONSE_MISMATCH, {
105
+ headers: data.headers
106
+ })
107
+ );
108
+ }
109
+ },
110
+ err => {
111
+ reject(err);
87
112
  }
88
- },
89
- err => {
90
- reject(err);
91
- }
92
- );
113
+ );
114
+ }
93
115
  });
94
116
  }
95
117
 
@@ -12,6 +12,7 @@ export default class OTTAssetLoader implements ILoader {
12
12
  private _entryId: string;
13
13
  private _requests!: Array<RequestBuilder>;
14
14
  private _response: any = {};
15
+ private _disableMultirequest: boolean = OTTConfiguration.get().ottDisableMultirequest;
15
16
 
16
17
  public static get id(): string {
17
18
  return 'asset';
@@ -43,6 +44,10 @@ export default class OTTAssetLoader implements ILoader {
43
44
  return this._response;
44
45
  }
45
46
 
47
+ public get disableMultirequest(): boolean {
48
+ return this._disableMultirequest;
49
+ }
50
+
46
51
  /**
47
52
  * Builds loader requests
48
53
  * @function
@@ -7,6 +7,7 @@ export default class OTTSessionLoader implements ILoader {
7
7
  private _partnerId: number;
8
8
  private _requests!: Array<RequestBuilder>;
9
9
  private _response: any = {};
10
+ private _disableMultirequest: boolean = OTTConfiguration.get().ottDisableMultirequest;
10
11
 
11
12
  public static get id(): string {
12
13
  return 'session';
@@ -37,6 +38,10 @@ export default class OTTSessionLoader implements ILoader {
37
38
  return this._response.ks;
38
39
  }
39
40
 
41
+ public get disableMultirequest(): boolean {
42
+ return this._disableMultirequest;
43
+ }
44
+
40
45
  /**
41
46
  * Builds loader requests
42
47
  * @function
@@ -0,0 +1,168 @@
1
+ import { ILoader } from '../../types';
2
+ import getLogger from '../../util/logger';
3
+ import OTTConfiguration from './config';
4
+ import RequestBuilder from '../../util/request-builder';
5
+ import ServiceResult from '../common/base-service-result';
6
+ import Error from '../../util/error/error';
7
+
8
+ /**
9
+ * RequestSequenceBuilder provides a builder pattern for executing multiple individual requests
10
+ * sequentially, as an alternative to the MultiRequestBuilder which batches them together.
11
+ * @class RequestSequenceBuilder
12
+ */
13
+ export default class RequestSequenceBuilder {
14
+ private _logger = getLogger('RequestSequenceBuilder');
15
+
16
+ /**
17
+ * Loaders to be executed
18
+ * @type {Map<string, ILoader>}
19
+ * @private
20
+ */
21
+ public loaders: Map<string, ILoader> = new Map();
22
+
23
+ /**
24
+ * Global parameters for all requests
25
+ * @type {Record<string, unknown>}
26
+ * @private
27
+ */
28
+ private _globalParams: Record<string, unknown> = { apiVersion: OTTConfiguration.get().serviceParams?.apiVersion };
29
+
30
+
31
+ /**
32
+ * Add a loader to the builder
33
+ * @function add
34
+ * @param {ILoader} loader The loader to add
35
+ */
36
+ public add(loader: ILoader): void {
37
+ this.loaders.set(loader.constructor.name, loader);
38
+ }
39
+
40
+ /**
41
+ * Executes a single request
42
+ * @function execute
43
+ * @param {RequestBuilder} request - The request to execute
44
+ * @returns {Promise<ServiceResult>} - Promise with the service result
45
+ */
46
+ private async _executeRequest(
47
+ request: RequestBuilder
48
+ ): Promise<ServiceResult> {
49
+ request.params = JSON.stringify({ ...this._globalParams, ...request.params });
50
+ try {
51
+ const data = await request.doHttpRequest();
52
+ const serviceResult = new ServiceResult(data.result || data);
53
+ if (serviceResult.hasError) {
54
+ const { code, message } = serviceResult.error;
55
+ this._logger.error(
56
+ `Service returned an error with error code: ${code} and message: ${message}.`
57
+ );
58
+ }
59
+ return serviceResult;
60
+ } catch (error) {
61
+ throw new Error(
62
+ Error.Severity.CRITICAL,
63
+ Error.Category.NETWORK,
64
+ Error.Code.API_RESPONSE_MISMATCH,
65
+ { error, request }
66
+ );
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Executes multiple requests sequentially
72
+ * @function executeSequence
73
+ * @param {Array<RequestBuilder>} requests - The requests to execute in order
74
+ * @returns {Promise<SingleRequestsResult>} - Promise with the combined results
75
+ */
76
+ private async _executeSequence(
77
+ requests: Array<RequestBuilder>
78
+ ): Promise<SingleRequestsResult> {
79
+ const results: Array<ServiceResult> = [];
80
+
81
+ for (const request of requests) {
82
+ try {
83
+ const serviceResult = await this._executeRequest(request);
84
+ results.push(serviceResult);
85
+ } catch (error) {
86
+ this._logger.error(`Request execution failed: ${error.message}`);
87
+ }
88
+ }
89
+ // Create result object and check for success
90
+ const singleRequestsResult = new SingleRequestsResult(results);
91
+ if (singleRequestsResult.success) {
92
+ return singleRequestsResult;
93
+ } else {
94
+ const errorResult = results.find(result => result.hasError);
95
+ if (errorResult) {
96
+ const { message, code } = errorResult.error;
97
+ throw new Error(
98
+ Error.Severity.CRITICAL,
99
+ Error.Category.NETWORK,
100
+ Error.Code.API_RESPONSE_MISMATCH,
101
+ {
102
+ error: errorResult.error,
103
+ errorMessage: `Request returned an error: ${message} (code: ${code})`
104
+ }
105
+ );
106
+ }
107
+ return singleRequestsResult;
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Executes all added loaders as separate requests
113
+ * @function execute
114
+ * @returns {Promise<Map<string, ILoader>>} - Promise with the loaded loaders
115
+ */
116
+ public async execute(): Promise<Map<string, ILoader>> {
117
+ const sessionLoader = this.loaders.get('OTTSessionLoader');
118
+ const assetLoader = this.loaders.get('OTTAssetLoader');
119
+ let ks = '';
120
+ try {
121
+ if (sessionLoader) {
122
+ const serviceResult = await this._executeRequest(sessionLoader.requests[0]);
123
+ sessionLoader.response = [{ data: serviceResult.data }];
124
+ ks = serviceResult.data.ks || '';
125
+ }
126
+ if (assetLoader) {
127
+ assetLoader.requests.forEach((request: RequestBuilder) => {
128
+ if (request.params.ks === '{1:result:ks}') {
129
+ request.params.ks = ks;
130
+ }
131
+ });
132
+ const requestsResult = await this._executeSequence(assetLoader.requests);
133
+ assetLoader.response = requestsResult.results;
134
+ }
135
+ } catch (error) {
136
+ this._logger.error(`loaders execution failed: ${error.message}`);
137
+ }
138
+ return this.loaders;
139
+ }
140
+ }
141
+
142
+ export class SingleRequestsResult {
143
+ private static _logger = getLogger('SingleRequestsResult');
144
+ public success: boolean;
145
+ public results: Array<ServiceResult>;
146
+
147
+ constructor(results: Array<ServiceResult>, requestsMustSucceed = true) {
148
+ this.results = [...results];
149
+ const errorResults = this.results.filter(({ hasError }) => hasError);
150
+ for (const serviceResult of errorResults) {
151
+ const { code, message } = serviceResult.error;
152
+ SingleRequestsResult._logger.error(
153
+ `Service returned an error with error code: ${code} and message: ${message}.`
154
+ );
155
+ }
156
+ const allRequestsFailed = errorResults.length === this.results.length;
157
+ const someRequestsFailed = requestsMustSucceed && errorResults.length > 0;
158
+
159
+ if (allRequestsFailed || someRequestsFailed) {
160
+ this.success = false;
161
+ } else {
162
+ if (!requestsMustSucceed) {
163
+ this.results = this.results.filter(serviceResult => !serviceResult.hasError);
164
+ }
165
+ this.success = true;
166
+ }
167
+ }
168
+ }