@playkit-js/playkit-js-providers 2.41.0-canary.0-2452bbc → 2.41.0-canary.0-3d6d02a

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.
Files changed (44) hide show
  1. package/analytics-service/package.json +6 -0
  2. package/bookmark-service/package.json +6 -0
  3. package/dist/analytics-service.d.ts +160 -0
  4. package/dist/bookmark-service.d.ts +157 -0
  5. package/dist/ott-provider.d.ts +545 -0
  6. package/dist/{index.d.ts → ovp-provider.d.ts} +102 -120
  7. package/dist/playkit-analytics-service.js +1 -1
  8. package/dist/playkit-analytics-service.js.map +1 -1
  9. package/dist/playkit-bookmark-service.js +1 -1
  10. package/dist/playkit-bookmark-service.js.map +1 -1
  11. package/dist/playkit-ott-provider.js +1 -1
  12. package/dist/playkit-ott-provider.js.map +1 -1
  13. package/dist/playkit-ovp-provider.js +1 -1
  14. package/dist/playkit-ovp-provider.js.map +1 -1
  15. package/dist/playkit-stats-service.js +1 -1
  16. package/dist/playkit-stats-service.js.map +1 -1
  17. package/dist/stats-service.d.ts +159 -0
  18. package/dist/tsdoc-metadata.json +1 -1
  19. package/dist/types.d.ts +391 -0
  20. package/ott-provider/package.json +6 -0
  21. package/ovp-provider/package.json +6 -0
  22. package/package.json +29 -21
  23. package/src/entities/document-source.ts +31 -0
  24. package/src/entities/media-entry.ts +2 -1
  25. package/src/entities/media-sources.ts +6 -1
  26. package/src/k-provider/common/base-provider.ts +14 -3
  27. package/src/k-provider/ott/provider.ts +1 -0
  28. package/src/k-provider/ovp/loaders/media-entry-loader.ts +4 -4
  29. package/src/k-provider/ovp/provider-parser.ts +22 -2
  30. package/src/k-provider/ovp/provider.ts +9 -5
  31. package/src/k-provider/ovp/regex-action-handler.ts +51 -44
  32. package/src/k-provider/ovp/response-types/kaltura-media-entries.ts +1 -7
  33. package/src/k-provider/ovp/services/base-entry-service.ts +2 -2
  34. package/src/types/index.ts +0 -8
  35. package/src/types/media-config-sources.ts +2 -0
  36. package/src/types/media-sources.ts +2 -0
  37. package/src/types/provider-options.ts +1 -0
  38. package/stats-service/package.json +6 -0
  39. package/types/package.json +5 -0
  40. package/playkit-analytics-service/package.json +0 -5
  41. package/playkit-bookmark-service/package.json +0 -5
  42. package/playkit-ott-provider/package.json +0 -5
  43. package/playkit-ovp-provider/package.json +0 -5
  44. package/playkit-stats-service/package.json +0 -5
@@ -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 s=t();for(var r in s)("object"==typeof exports?exports:e)[r]=s[r]}}(globalThis,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ContextType:()=>$,MediaType:()=>X,NAME:()=>G,Provider:()=>W,VERSION:()=>J});const s={get:()=>({VERSION:"",DEBUG:{value:"",name:""},ERROR:{value:"",name:""},INFO:{value:"",name:""},OFF:{value:"",name:""},TIME:{value:"",name:""},TRACE:{value:"",name:""},WARN:{value:"",name:""},createDefaultHandler:()=>{},debug:()=>{},enabledFor:()=>{},error:()=>{},get:()=>{},getLevel:()=>{},info:()=>{},log:()=>{},setHandler:()=>{},setLevel:()=>{},time:()=>{},timeEnd:()=>{},trace:()=>{},useDefaults:()=>{},warn:()=>{}})};let r={};function a(e){return s.get(e)}const i=a,o={RECOVERABLE:1,CRITICAL:2},n={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,MISSING_MANDATORY_PARAMS:3e3,MISSING_PLAY_SOURCE:3001,METHOD_NOT_IMPLEMENTED:3002},c={NETWORK:1,SERVICE:2,PROVIDER:3};class h{static Severity=o;static Category=c;static Code=n;static _logger=i("Error");constructor(e,t,s,r={}){this.severity=e,this.category=t,this.code=s,this.data=r,h._logger.error(`Category:${t} | Code:${s} |`,r)}}class u{_networkRetryConfig={async:!0,timeout:0,maxAttempts:4};get partnerId(){return this._partnerId}get widgetId(){return this._widgetId||this.defaultWidgetId}get defaultWidgetId(){return"_"+this._partnerId}get uiConfId(){return this._uiConfId}get ks(){return this._ks}set ks(e){this._ks=e}get playerVersion(){return this._playerVersion}get isAnonymous(){return this._isAnonymous}constructor(e,t){!function(e){e&&"function"==typeof e.getLogger&&(s.get=e.getLogger),e&&e.LogLevel&&(r=e.LogLevel)}(e.logger),this._partnerId=e.partnerId,this._widgetId=e.widgetId,this._uiConfId=e.uiConfId,this._isAnonymous=!e.ks,this._ks=e.ks||"",this._playerVersion=t}getMediaConfig(e){return Promise.reject(new h(h.Severity.CRITICAL,h.Category.PROVIDER,h.Code.METHOD_NOT_IMPLEMENTED,{message:"getMediaConfig method must be implement by the derived class"}))}getPlaylistConfig(e){return Promise.reject(new h(h.Severity.CRITICAL,h.Category.PROVIDER,h.Code.METHOD_NOT_IMPLEMENTED,{message:"The provider does not support loading playlist by id"}))}getEntryListConfig(e){return Promise.reject(new h(h.Severity.CRITICAL,h.Category.PROVIDER,h.Code.METHOD_NOT_IMPLEMENTED,{message:"The provider does not support loading entry list"}))}_verifyHasSources(e){if(0===e.hls.concat(e.dash,e.progressive,e.image).length)throw new h(h.Severity.CRITICAL,h.Category.SERVICE,h.Code.MISSING_PLAY_SOURCE,{action:"",messages:`No play source for entry id: ${e.id}`})}get LogLevel(){return r}getLogLevel(e){return function(e){return a(e).getLevel()}(e)}setLogLevel(e,t){!function(e,t){a(t).setLevel(e)}(e,t)}}const d=e=>{let t;return Array.isArray(e)?(t=e.length>0?e.slice(0):[],t.forEach(((e,s)=>{("object"==typeof e||Array.isArray(e)&&e.length>0)&&(t[s]=d(e))}))):"object"==typeof e?(t=Object.assign({},e),Object.keys(t).forEach((e=>{("object"==typeof t[e]||Array.isArray(t[e])&&t[e].length>0)&&(t[e]=d(t[e]))}))):t=e,t},p={serviceParams:{apiVersion:"7.8.1"}};class l{static set(e){e&&Object.assign(p,e)}static get(){return d(p)}}class g{_loadersResponseMap=new Map;_loaders=new Map;constructor(e){this._networkRetryConfig=e}add(e,t,s){const r=new e(t);if(r.isValid()){this._loaders.set(e.id,r);const t=this._multiRequest.requests.length,a=r.requests;this._multiRequest.retryConfig=this._networkRetryConfig,a.forEach((e=>{e.params=e.params||{},e.params.ks=e.params.ks||s,this._multiRequest.add(e)}));const i=Array.from(new Array(a.length),((e,s)=>s+t));this._loadersResponseMap.set(e.id,i)}}fetchData(e){return new Promise(((t,s)=>{this._multiRequest.execute(e).then((e=>{this._multiResponse=e.response,this.prepareData(e.response).success?t(this._loaders):s(new h(h.Severity.CRITICAL,h.Category.NETWORK,h.Code.API_RESPONSE_MISMATCH,{headers:e.headers}))}),(e=>{s(e)}))}))}prepareData(e){return this._loaders.forEach(((t,s)=>{const r=this._loadersResponseMap.get(s);try{r&&r.length>0&&(t.response=e.results.slice(r[0],r[r.length-1]+1))}catch(e){return{success:!1,error:e}}})),{success:!0,data:this._loaders}}}class m{retryConfig={async:!0,timeout:0,maxAttempts:4};_attemptCounter=1;constructor(e=new Map){this.headers=e}getUrl(e){return e+"/service/"+this.service+(this.action?"/action/"+this.action:"")}doHttpRequest(){const e=new Promise(((e,t)=>{this._requestPromise={resolve:e,reject:t}}));return this.url||this._requestPromise.reject(new h(h.Severity.CRITICAL,h.Category.NETWORK,h.Code.MALFORMED_DATA_URI,{url:this.url})),this._createXHR(),e}_createXHR(){const e=new XMLHttpRequest;e.onreadystatechange=()=>{if(4===e.readyState&&200===e.status)try{const t=JSON.parse(e.responseText);return this.responseHeaders=this._getResponseHeaders(e),this._requestPromise.resolve(t)}catch(t){this._requestPromise.reject(this._createError(e,h.Code.BAD_SERVER_RESPONSE,{text:e.responseText}))}},e.open(this.method,this.url,this.retryConfig.async),this.retryConfig.async&&this.retryConfig.timeout&&(e.timeout=this.retryConfig.timeout);const t=performance.now();e.ontimeout=()=>{this._handleError(e,h.Code.TIMEOUT,{timeout:(performance.now()-t)/1e3,statusText:e.statusText})},e.onerror=e.onabort=()=>{this._handleError(e,h.Code.HTTP_ERROR,{text:e.responseText,statusText:e.statusText})},this.headers.forEach(((t,s)=>{e.setRequestHeader(s,t)})),e.send(this.params)}_getResponseHeaders(e){return e.getAllResponseHeaders().split("\n").filter((e=>0===e.toLowerCase().indexOf("x-")))}_handleError(e,t,s){const r=this._createError(e,t,s);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(r);this._attemptCounter++,this._createXHR()}_createError(e,t,s){return Object.assign(s,{url:this.url,headers:this._getResponseHeaders(e),attempt:this._attemptCounter}),new h(h.Severity.CRITICAL,h.Category.NETWORK,t,s)}}class y{hasError=!1;constructor(e){"KalturaAPIException"===e.objectType?(this.hasError=!0,this.error=new _(e.code,e.message)):e.error&&"KalturaAPIException"===e.error.objectType?(this.hasError=!0,this.error=new _(e.error.code,e.error.message)):this.data=e}}class _{constructor(e,t){this.code=e,this.message=t}}class T extends m{static _logger=i("MultiRequestBuilder");requests=[];add(e){this.requests.push(e);const t={},s={service:e.service,action:e.action};return Object.assign(t,{[this.requests.length]:Object.assign(s,e.params)}),Object.assign(t,this.params),this.params=t,this}execute(e){return new Promise(((t,s)=>{try{this.params=JSON.stringify(this.params)}catch(e){T._logger.error(`${e.message}`),s(new h(h.Severity.CRITICAL,h.Category.PROVIDER,h.Code.FAILED_PARSING_REQUEST,{error:e,params:this.params}))}this.doHttpRequest().then((r=>{const a=new E(r,e);a.success?t({headers:this.responseHeaders,response:a}):s(new h(h.Severity.CRITICAL,h.Category.NETWORK,h.Code.MULTIREQUEST_API_ERROR,{url:this.url,headers:this.responseHeaders,results:a.results}))}),(e=>{s(e)}))}))}}class E{static _logger=i("MultiRequestResult");results=[];constructor(e,t=!0){const s=e.result?e.result:e,r=(Array.isArray(s)?s:[s]).map((e=>new y(e))),a=r.filter((e=>e.hasError));a.forEach((e=>{E._logger.error(`Service returned an error with error code: ${e.error.code} and message: ${e.error.message}.`)})),this.results=r,t&&a.length||a.length===this.results.length?this.success=!1:(this.results=this.results.filter((e=>!e.hasError)),this.success=!0)}}class f{static getMultiRequest(e,t){const s=l.get(),r=s.serviceParams;e&&Object.assign(r,{ks:e}),t&&Object.assign(r,{partnerId:t});const a=new Map;a.set("Content-Type","application/json");const i=new T(a);return i.method="POST",i.service="multirequest",i.url=i.getUrl(s.serviceUrl),i.params=r,i}}class R extends g{constructor(e,t="",s){super(s),this._multiRequest=f.getMultiRequest(t,e)}}class I extends f{static anonymousLogin(e,t,s){const r=new Map;r.set("Content-Type","application/json");const a=new m(r);a.service="ottuser",a.action="anonymousLogin",a.method="POST",a.url=a.getUrl(e);const i={partnerId:t};return s&&Object.assign(i,{udid:s}),a.params=i,a}}class A{_response={};static get id(){return"session"}constructor(e){this.requests=this.buildRequests(e),this._partnerId=e.partnerId}set requests(e){this._requests=e}get requests(){return this._requests}set response(e){this._response.ks=e[0].data.ks}get response(){return this._response.ks}buildRequests(e){const t=l.get(),s=[];return s.push(I.anonymousLogin(t.serviceUrl,e.partnerId,e.udid)),s}isValid(){return!!this._partnerId}}const C="asset";class O extends f{static getPlaybackContext(e,t,s,r,a){const i=new Map;i.set("Content-Type","application/json");const o=new m(i);o.service=C,o.action="getPlaybackContext",o.method="POST",o.url=o.getUrl(e);const n={objectType:"KalturaPlaybackContextOptions"};return Object.assign(n,a),o.params={assetId:s,assetType:r,contextDataParams:n,ks:t},o}static get(e,t,s,r){const a=new Map;a.set("Content-Type","application/json");const i=new m(a);return i.service=C,i.action="get",i.method="POST",i.url=i.getUrl(e),i.params={id:s,assetReferenceType:r,ks:t},i}}class S{constructor(e){this.message=e.message,this.code=e.code}}class D{static Type={BLOCK:"BLOCK",START_DATE_OFFSET:"START_DATE_OFFSET",END_DATE_OFFSET:"END_DATE_OFFSET",USER_BLOCK:"USER_BLOCK",ALLOW_PLAYBACK:"ALLOW_PLAYBACK",BLOCK_PLAYBACK:"BLOCK_PLAYBACK",APPLY_DISCOUNT_MODULE:"APPLY_DISCOUNT_MODULE"};constructor(e){this.type=e.type}}class L{static Scheme={"drm.PLAYREADY_CENC":"com.microsoft.playready","drm.WIDEVINE_CENC":"com.widevine.alpha","fairplay.FAIRPLAY":"com.apple.fairplay",WIDEVINE_CENC:"com.widevine.alpha",PLAYREADY_CENC:"com.microsoft.playready",FAIRPLAY:"com.apple.fairplay"};constructor(e){this.scheme=e.scheme,this.licenseURL=e.licenseURL,this.certificate=e.certificate}}class v{drm=[];constructor(e){this.format=e.format,this.adsPolicy=e.adsPolicy,this.adsParam=e.adsParam,this.duration=e.duration,this.url=e.url,this.type=e.type,this.fileId=e.id,this.protocols=e.protocols,e.drm&&e.drm.map((e=>this.drm.push(new L(e))))}hasDrmData(){return this.drm&&this.drm.length>0}getProtocol(e){let t="";if(this.protocols&&this.protocols.length>0)this.protocols.split(",").forEach((s=>{s===e&&(t=s)}));else if("http"===e)return e;return t}}class P{static StreamerType={HLS:"hls",DASH:"dash",PROGRESSIVE:"progressive"};constructor(e){this.streamertype=e.streamertype,this.url=e.url}}class w extends y{static Type={DOWNLOAD:"DOWNLOAD",TRAILER:"TRAILER",CATCHUP:"CATCHUP",START_OVER:"START_OVER",PLAYBACK:"PLAYBACK"};sources=[];actions=[];messages=[];plugins=[];constructor(e){if(super(e),!this.hasError){const t=e.messages;t&&t.map((e=>this.messages.push(new S(e))));const s=e.actions;s&&s.map((e=>this.actions.push(new D(e))));const r=e.sources;r&&r.map((e=>this.sources.push(new v(e))));const a=e.plugins;a&&a.map((e=>this.plugins.push(new P(e))))}}hasBlockAction(){return void 0!==this.getBlockAction()}getBlockAction(){return this.actions.find((e=>e.type===D.Type.BLOCK))}getErrorMessages(){return this.messages}}class M extends y{static Type={MEDIA:"media",RECORDING:"recording",EPG:"epg"};static AssetReferenceType={MEDIA:"media",EPG_INTERNAL:"epg_internal",EPG_EXTERNAL:"epg_external",NPVR:"nPVR"};name="";description="";tags=[];metas=[];pictures=[];constructor(e){super(e),this.hasError||(this.id=e.id,this.name=e.name,this.description=e.description,this.createDate=e.createDate,this.endDate=e.endDate,this.plays=e.plays,this.views=e.views,this.metas=this._formatTagsMetas(e.metas),this.tags=this._formatTagsMetas(e.tags),this.pictures=e.images)}_formatTagsMetas(e){const t=[];return Object.keys(e).forEach((s=>{if(e[s].objects){let r="";e[s].objects.forEach((e=>{r+=e.value+"|"})),t.push({key:s,value:r})}else t.push({key:s,value:e[s].value})})),t}}class b{_response={};static get id(){return"asset"}constructor(e){this.requests=this.buildRequests(e),this._entryId=e.entryId}set requests(e){this._requests=e}get requests(){return this._requests}set response(e){this._response.mediaDataResult=new M(e[0].data),this._response.playBackContextResult=new w(e[1].data)}get response(){return this._response}buildRequests(e){const t=l.get(),s=[];return s.push(O.get(t.serviceUrl,e.ks,e.entryId,e.assetReferenceType)),s.push(O.getPlaybackContext(t.serviceUrl,e.ks,e.entryId,e.type,e.playbackContext)),s}isValid(){return!!this._entryId}}class N{_response={playlistItems:{entries:[]}};static get id(){return"asset_list"}constructor(e){this.requests=this.buildRequests(e),this._entries=e.entries}set requests(e){this._requests=e}get requests(){return this._requests}set response(e){e.forEach((e=>{this._response.playlistItems.entries.push({mediaDataResult:new M(e.data)})}))}get response(){return this._response}buildRequests(e){const t=l.get(),s=[];return e.entries.forEach((r=>{const a=r.assetReferenceType||M.AssetReferenceType.MEDIA;s.push(O.get(t.serviceUrl,e.ks,r.entryId||r,a))})),s}isValid(){return!(!this._entries||!this._entries.length)}}const k={DASH:{name:"dash",mimeType:"application/dash+xml",pathExt:"mpd"},HLS:{name:"hls",mimeType:"application/x-mpegURL",pathExt:"m3u8"},WVM:{name:"wvm",mimeType:"video/wvm",pathExt:"wvm"},MP4:{name:"mp4",mimeType:"video/mp4",pathExt:"mp4"},MP3:{name:"mp3",mimeType:"audio/mpeg",pathExt:"mp3"}},x=new Map([["mpegdash",k.DASH],["applehttp",k.HLS],["url",k.MP4]]);function j(e){const t=x.get(e);return!!t&&t.name===k.MP4.name}class U{constructor(){this.progressive=[],this.dash=[],this.hls=[],this.image=[]}map(e,t){if(t)switch(t.name){case k.MP4.name:this.progressive.push(e);break;case k.DASH.name:this.dash.push(e);break;case k.HLS.name:this.hls.push(e)}}toJSON(){const e={progressive:[],dash:[],hls:[],image:[]};return this.progressive.forEach((t=>e.progressive.push(t.toJSON()))),this.hls.forEach((t=>e.hls.push(t.toJSON()))),this.dash.forEach((t=>e.dash.push(t.toJSON()))),e.image=this.image,e}}class B{static Type={VOD:"Vod",LIVE:"Live",IMAGE:"Image",AUDIO:"Audio",UNKNOWN:"Unknown"};static DvrStatus={ON:1,OFF:0};constructor(){this.metadata=new Map,this.sources=new U,this.type=B.Type.UNKNOWN}toJSON(){return{id:this.id,name:this.name,sources:this.sources.toJSON(),duration:this.duration,dvrStatus:this.dvrStatus,status:this.status,metadata:this.metadata,type:this.type,poster:this.poster,assetReferenceType:this.assetReferenceType,downloadUrl:this.downloadUrl}}}class q{constructor(e,t,s){this.licenseUrl=e,this.scheme=t,s&&(this.certificate=s)}toJSON(){const e={licenseUrl:this.licenseUrl,scheme:this.scheme};return this.certificate&&(e.certificate=this.certificate),e}}class V{toJSON(){const e={id:this.id,url:this.url,mimetype:this.mimetype};return this.bandwidth&&(e.bandwidth=this.bandwidth),this.width&&(e.width=this.width),this.height&&(e.height=this.height),this.label&&(e.label=this.label),this.drmData&&this.drmData.length>0&&(e.drmData=[],this.drmData.forEach((t=>{Array.isArray(e.drmData)&&e.drmData.push(t.toJSON())}))),e}}class H{constructor(){this.items=[]}}class K{constructor(e){this.url=e.url,this.clickThroughUrl=e.clickThroughUrl}}const F={[M.Type.MEDIA]:{[w.Type.TRAILER]:()=>({type:B.Type.VOD}),[w.Type.PLAYBACK]:e=>"KalturaLiveAsset"===e.objectType?{type:B.Type.LIVE,dvrStatus:e.enableTrickPlay?B.DvrStatus.ON:B.DvrStatus.OFF}:parseInt(e.externalIds)>0?{type:B.Type.LIVE,dvrStatus:B.DvrStatus.OFF}:{type:B.Type.VOD}},[M.Type.EPG]:{[w.Type.CATCHUP]:()=>({type:B.Type.VOD}),[w.Type.START_OVER]:()=>({type:B.Type.LIVE,dvrStatus:B.DvrStatus.ON})},[M.Type.RECORDING]:{[w.Type.PLAYBACK]:()=>({type:B.Type.VOD})}};class Y{static _logger=i("OTTProviderParser");static getMediaEntry(e,t){const s=new B;Y._fillBaseData(s,e,t);const r=e.playBackContextResult,a=e.mediaDataResult,i=r.sources,o=Y._filterSourcesByFormats(i,t.formats);s.sources=Y._getParsedSources(o);const n=Y._getMediaType(a.data,t.mediaType,t.contextType);return s.type=n.type,s.dvrStatus=n.dvrStatus,s.duration=Math.max.apply(Math,i.map((e=>e.duration))),s}static getEntryList(e,t){const s=new H;return e.playlistItems.entries.forEach((e=>{const r=new B,a=t.find((t=>t.entryId===e.mediaDataResult.id));Y._fillBaseData(r,e,a),s.items.push(r)})),s}static getBumper(e){const t=e.playBackContextResult.plugins.find((e=>e.streamertype===P.StreamerType.PROGRESSIVE));if(t)return new K(t)}static _fillBaseData(e,t,s){const r=t.mediaDataResult,a=Y.reconstructMetadata(r);return a.description=r.description,a.name=r.name,r.createDate&&(a.createdAt=r.createDate),r.endDate&&(a.endDate=r.endDate),r.data.entryId&&(a.entryId=r.data.entryId),r.data.epgId&&(a.epgId=r.data.epgId),r.data.recordingId&&(a.recordingId=r.data.recordingId),s&&s.mediaType&&(a.mediaType=s.mediaType),s&&s.contextType&&(a.contextType=s.contextType),e.metadata=a,e.poster=Y._getPoster(r.pictures),e.id=r.id,e}static reconstructMetadata(e){return{metas:Y.addToMetaObject(e.metas),tags:Y.addToMetaObject(e.tags)}}static addToMetaObject(e){const t={};return e&&e.forEach((e=>{t[e.key]=e.value})),t}static _getPoster(e){if(e&&e.length>0){const t=e[0].url;return/.*\/thumbnail\/.*(?:width|height)\/\d+\/(?:height|width)\/\d+/.test(t)?t:e.map((e=>({url:e.url,width:e.width,height:e.height})))}return""}static _getMediaType(e,t,s){let r={type:B.Type.UNKNOWN};return F[t]&&F[t][s]&&(r=F[t][s](e)),r}static _filterSourcesByFormats(e,t){return t.length>0&&(e=e.filter((e=>t.includes(e.type)))),e}static _getParsedSources(e){const t=new U,s=e=>{const s=Y._parseAdaptiveSource(e);if(s){const r=x.get(e.format);t.map(s,r)}};return e&&e.length>0&&(e.filter((e=>!j(e.format))).forEach(s),e.filter((e=>j(e.format))).forEach(s)),t}static _parseAdaptiveSource(e){const t=new V;if(e){const s=e.url,r=x.get(e.format);if(r&&(t.mimetype=r.mimeType),!s)return Y._logger.error(`failed to create play url from source, discarding source: (${e.fileId}), ${e.format}.`),null;if(t.url=s,t.id=e.fileId+","+e.format,e.hasDrmData()){const s=[];e.drm.forEach((e=>{s.push(new q(e.licenseURL,L.Scheme[e.scheme],e.certificate))})),t.drmData=s}}return t}static hasBlockAction(e){return e.playBackContextResult.hasBlockAction()}static getBlockAction(e){return e.playBackContextResult.getBlockAction()}static getErrorMessages(e){return e.playBackContextResult.getErrorMessages()}}class W extends u{constructor(e,t){super(e,t),this._logger=i("OTTProvider"),l.set(e.env),this._networkRetryConfig=Object.assign(this._networkRetryConfig,e.networkRetryParameters)}get env(){return l.get()}getMediaConfig(e){return e.ks&&(this.ks=e.ks,this._isAnonymous=!1),this._dataLoader=new R(this.partnerId,this.ks,this._networkRetryConfig),new Promise(((t,s)=>{const r=e.entryId;if(r){let a=this.ks;a||(a="{1:result:ks}",this._dataLoader.add(A,{partnerId:this.partnerId}));const i=e.contextType||w.Type.PLAYBACK,o=e.mediaType||M.Type.MEDIA,n=e.assetReferenceType||M.AssetReferenceType.MEDIA,c={mediaProtocol:e.protocol,assetFileIds:e.fileIds,context:i};e.streamerType&&(c.streamerType=e.streamerType),e.urlType&&(c.urlType=e.urlType),e.adapterData&&(c.adapterData=e.adapterData),this._dataLoader.add(b,{entryId:r,ks:a,type:o,playbackContext:c,assetReferenceType:n});const h={contextType:i,mediaType:o,formats:e.formats||[]};return this._dataLoader.fetchData().then((e=>{try{t(this._parseDataFromResponse(e,h))}catch(e){s(e)}}),(e=>{s(e)}))}s(new h(h.Severity.CRITICAL,h.Category.PROVIDER,h.Code.MISSING_MANDATORY_PARAMS,{message:"missing entry id"}))}))}_parseDataFromResponse(e,t){this._logger.debug("Data parsing started");const s={session:{isAnonymous:this._isAnonymous,partnerId:this.partnerId},sources:this._getDefaultSourcesObject(),plugins:{}};if(this.uiConfId&&(s.session.uiConfId=this.uiConfId),e){if(e.has(A.id)){const t=e.get(A.id);t&&t.response&&(s.session.ks=t.response)}else s.session.ks=this.ks;if(e.has(b.id)){const r=e.get(b.id);if(r&&r.response&&Object.keys(r.response).length){const e=r.response;if(Y.hasBlockAction(e))throw new h(h.Severity.CRITICAL,h.Category.SERVICE,h.Code.BLOCK_ACTION,{action:Y.getBlockAction(e),messages:Y.getErrorMessages(e)});const a=Y.getMediaEntry(e,t);Object.assign(s.sources,this._getSourcesObject(a)),this._verifyHasSources(s.sources);const i=Y.getBumper(e);i&&Object.assign(s.plugins,{bumper:i})}}}return this._logger.debug("Data parsing finished",s),s}getEntryListConfig(e){return e.ks&&(this.ks=e.ks,this._isAnonymous=!1),this._dataLoader=new R(this.partnerId,this.ks,this._networkRetryConfig),new Promise(((t,s)=>{const r=e.entries;if(r&&r.length){let e=this.ks;e||(e="{1:result:ks}",this._dataLoader.add(A,{partnerId:this.partnerId})),this._dataLoader.add(N,{entries:r,ks:e}),this._dataLoader.fetchData(!1).then((e=>{t(this._parseEntryListDataFromResponse(e,r))}),(e=>{s(e)}))}else s({success:!1,data:"Missing mandatory parameter"})}))}_parseEntryListDataFromResponse(e,t){this._logger.debug("Data parsing started");const s={id:"",metadata:{name:"",description:""},poster:"",items:[],playlistLastEntryId:""};if(e&&e.has(N.id)){const r=e.get(N.id);r&&r.response&&Y.getEntryList(r.response,t).items.forEach((e=>s.items.push({sources:this._getSourcesObject(e)})))}return this._logger.debug("Data parsing finished",s),s}_getDefaultSourcesObject(){return{hls:[],dash:[],progressive:[],image:[],id:"",duration:0,type:B.Type.UNKNOWN,poster:"",dvr:!1,vr:null,metadata:{name:"",description:"",tags:""}}}_getSourcesObject(e){const t=this._getDefaultSourcesObject(),s=e.sources.toJSON();return t.hls=s.hls,t.dash=s.dash,t.progressive=s.progressive,t.id=e.id,t.duration=e.duration,t.type=e.type,t.dvr=!!e.dvrStatus,t.poster=e.poster,e.metadata&&e.metadata.metas&&"string"==typeof e.metadata.metas.tags&&e.metadata.metas.tags.indexOf("360")>-1&&(t.vr={}),Object.assign(t.metadata,e.metadata),t}}const G="@playkit-js/playkit-js-providers-ott",J="2.41.0-canary.0-2452bbc",$=w.Type,X=M.Type;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 s(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var s=r.call(e,"string");if("object"!==n(s))return s;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,s(n.key),n)}}function a(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function u(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&&o(e,t)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(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 c(e)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function h(e,t,r){return(t=s(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,{ContextType:function(){return ne},MediaType:function(){return se},NAME:function(){return te},Provider:function(){return ee},VERSION:function(){return re}});var p={get: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(){}}}},d={};function y(e){return p.get(e)}var m=y,g=a((function e(t,n,s){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};r(this,e),this.severity=t,this.category=n,this.code=s,this.data=i,e._logger.error("Category:".concat(n," | Code:").concat(s," |"),i)}));h(g,"Severity",{RECOVERABLE:1,CRITICAL:2}),h(g,"Category",{NETWORK:1,SERVICE:2,PROVIDER:3}),h(g,"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,MISSING_MANDATORY_PARAMS:3e3,MISSING_PLAY_SOURCE:3001,METHOD_NOT_IMPLEMENTED:3002}),h(g,"_logger",m("Error"));var v=function(){function e(t,n){r(this,e),h(this,"_networkRetryConfig",{async:!0,timeout:0,maxAttempts:4}),function(e){e&&"function"==typeof e.getLogger&&(p.get=e.getLogger),e&&e.LogLevel&&(d=e.LogLevel)}(t.logger),this._partnerId=t.partnerId,this._widgetId=t.widgetId,this._uiConfId=t.uiConfId,this._isAnonymous=!t.ks,this._ks=t.ks||"",this._playerVersion=n,this._referrer=t.referrer}return a(e,[{key:"partnerId",get:function(){return this._partnerId}},{key:"widgetId",get:function(){return this._widgetId||this.defaultWidgetId}},{key:"defaultWidgetId",get:function(){return"_"+this._partnerId}},{key:"uiConfId",get:function(){return this._uiConfId}},{key:"ks",get:function(){return this._ks},set:function(e){this._ks=e}},{key:"playerVersion",get:function(){return this._playerVersion}},{key:"isAnonymous",get:function(){return this._isAnonymous}},{key:"getMediaConfig",value:function(e){return Promise.reject(new g(g.Severity.CRITICAL,g.Category.PROVIDER,g.Code.METHOD_NOT_IMPLEMENTED,{message:"getMediaConfig method must be implement by the derived class"}))}},{key:"getPlaylistConfig",value:function(e){return Promise.reject(new g(g.Severity.CRITICAL,g.Category.PROVIDER,g.Code.METHOD_NOT_IMPLEMENTED,{message:"The provider does not support loading playlist by id"}))}},{key:"getEntryListConfig",value:function(e){return Promise.reject(new g(g.Severity.CRITICAL,g.Category.PROVIDER,g.Code.METHOD_NOT_IMPLEMENTED,{message:"The provider does not support loading entry list"}))}},{key:"_verifyHasSources",value:function(e){if(0===e.hls.concat(e.dash,e.progressive,e.image,e.document).length)throw new g(g.Severity.CRITICAL,g.Category.SERVICE,g.Code.MISSING_PLAY_SOURCE,{action:"",messages:"No play source for entry id: ".concat(e.id)})}},{key:"LogLevel",get:function(){return d}},{key:"getLogLevel",value:function(e){return function(e){return y(e).getLevel()}(e)}},{key:"setLogLevel",value:function(e,t){!function(e,t){y(t).setLevel(e)}(e,t)}}]),e}(),_=function e(t){var r;return Array.isArray(t)?(r=t.length>0?t.slice(0):[]).forEach((function(t,s){("object"===n(t)||Array.isArray(t)&&t.length>0)&&(r[s]=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},R={serviceParams:{apiVersion:"7.8.1"}},T=function(){function e(){r(this,e)}return a(e,null,[{key:"set",value:function(e){e&&Object.assign(R,e)}},{key:"get",value:function(){return _(R)}}]),e}(),E=function(){function e(t){r(this,e),h(this,"_loadersResponseMap",new Map),h(this,"_loaders",new Map),this._networkRetryConfig=t}return a(e,[{key:"add",value:function(e,t,r){var n=this,s=new e(t);if(s.isValid()){this._loaders.set(e.id,s);var i=this._multiRequest.requests.length,a=s.requests;this._multiRequest.retryConfig=this._networkRetryConfig,a.forEach((function(e){e.params=e.params||{},e.params.ks=e.params.ks||r,n._multiRequest.add(e)}));var o=Array.from(new Array(a.length),(function(e,t){return t+i}));this._loadersResponseMap.set(e.id,o)}}},{key:"fetchData",value:function(e){var t=this;return new Promise((function(r,n){t._multiRequest.execute(e).then((function(e){t._multiResponse=e.response,t.prepareData(e.response).success?r(t._loaders):n(new g(g.Severity.CRITICAL,g.Category.NETWORK,g.Code.API_RESPONSE_MISMATCH,{headers:e.headers}))}),(function(e){n(e)}))}))}},{key:"prepareData",value:function(e){var t=this;return this._loaders.forEach((function(r,n){var s=t._loadersResponseMap.get(n);try{s&&s.length>0&&(r.response=e.results.slice(s[0],s[s.length-1]+1))}catch(e){return{success:!1,error:e}}})),{success:!0,data:this._loaders}}}]),e}(),O=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Map;r(this,e),h(this,"retryConfig",{async:!0,timeout:0,maxAttempts:4}),h(this,"_attemptCounter",1),this.headers=t}return a(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 g(g.Severity.CRITICAL,g.Category.NETWORK,g.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,g.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,g.Code.TIMEOUT,{timeout:(performance.now()-r)/1e3,statusText:t.statusText})},t.onerror=t.onabort=function(){e._handleError(t,g.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 g(g.Severity.CRITICAL,g.Category.NETWORK,t,r)}}]),e}(),I=a((function e(t){r(this,e),h(this,"hasError",!1),"KalturaAPIException"===t.objectType?(this.hasError=!0,this.error=new k(t.code,t.message)):t.error&&"KalturaAPIException"===t.error.objectType?(this.hasError=!0,this.error=new k(t.error.code,t.error.message)):this.data=t})),k=a((function e(t,n){r(this,e),this.code=t,this.message=n}));var A=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(){var e;r(this,i);for(var t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return h(c(e=s.call.apply(s,[this].concat(n))),"requests",[]),e}return a(i,[{key:"add",value:function(e){this.requests.push(e);var t={},r={service:e.service,action:e.action};return Object.assign(t,h({},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 g(g.Severity.CRITICAL,g.Category.PROVIDER,g.Code.FAILED_PARSING_REQUEST,{error:e,params:t.params}))}t.doHttpRequest().then((function(s){var i=new C(s,e);i.success?r({headers:t.responseHeaders,response:i}):n(new g(g.Severity.CRITICAL,g.Category.NETWORK,g.Code.MULTIREQUEST_API_ERROR,{url:t.url,headers:t.responseHeaders,results:i.results}))}),(function(e){n(e)}))}))}}]),i}(O);h(A,"_logger",m("MultiRequestBuilder"));var C=a((function e(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];r(this,e),h(this,"results",[]);var s=t.result?t.result:t,i=(Array.isArray(s)?s:[s]).map((function(e){return new I(e)})),a=i.filter((function(e){return e.hasError}));a.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&&a.length||a.length===this.results.length?this.success=!1:(this.results=this.results.filter((function(e){return!e.hasError})),this.success=!0)}));h(C,"_logger",m("MultiRequestResult"));var S=function(){function e(){r(this,e)}return a(e,null,[{key:"getMultiRequest",value:function(e,t){var r=T.get(),n=r.serviceParams;e&&Object.assign(n,{ks:e}),t&&Object.assign(n,{partnerId:t});var s=new Map;s.set("Content-Type","application/json");var i=new A(s);return i.method="POST",i.service="multirequest",i.url=i.getUrl(r.serviceUrl),i.params=n,i}}]),e}();var P=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=arguments.length>2?arguments[2]:void 0;return r(this,i),(t=s.call(this,a))._multiRequest=S.getMultiRequest(n,e),t}return a(i)}(E);var D=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(){return r(this,i),s.apply(this,arguments)}return a(i,null,[{key:"anonymousLogin",value:function(e,t,r){var n=new Map;n.set("Content-Type","application/json");var s=new O(n);s.service="ottuser",s.action="anonymousLogin",s.method="POST",s.url=s.getUrl(e);var i={partnerId:t};return r&&Object.assign(i,{udid:r}),s.params=i,s}}]),i}(S),b=function(){function e(t){r(this,e),h(this,"_response",{}),this.requests=this.buildRequests(t),this._partnerId=t.partnerId}return a(e,[{key:"requests",get:function(){return this._requests},set:function(e){this._requests=e}},{key:"response",get:function(){return this._response.ks},set:function(e){this._response.ks=e[0].data.ks}},{key:"buildRequests",value:function(e){var t=T.get(),r=[];return r.push(D.anonymousLogin(t.serviceUrl,e.partnerId,e.udid)),r}},{key:"isValid",value:function(){return!!this._partnerId}}],[{key:"id",get:function(){return"session"}}]),e}();var w="asset",L=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(){return r(this,i),s.apply(this,arguments)}return a(i,null,[{key:"getPlaybackContext",value:function(e,t,r,n,s){var i=new Map;i.set("Content-Type","application/json");var a=new O(i);a.service=w,a.action="getPlaybackContext",a.method="POST",a.url=a.getUrl(e);var o={objectType:"KalturaPlaybackContextOptions"};return Object.assign(o,s),a.params={assetId:r,assetType:n,contextDataParams:o,ks:t},a}},{key:"get",value:function(e,t,r,n){var s=new Map;s.set("Content-Type","application/json");var i=new O(s);return i.service=w,i.action="get",i.method="POST",i.url=i.getUrl(e),i.params={id:r,assetReferenceType:n,ks:t},i}}]),i}(S),M=a((function e(t){r(this,e),this.message=t.message,this.code=t.code})),N=a((function e(t){r(this,e),this.type=t.type}));h(N,"Type",{BLOCK:"BLOCK",START_DATE_OFFSET:"START_DATE_OFFSET",END_DATE_OFFSET:"END_DATE_OFFSET",USER_BLOCK:"USER_BLOCK",ALLOW_PLAYBACK:"ALLOW_PLAYBACK",BLOCK_PLAYBACK:"BLOCK_PLAYBACK",APPLY_DISCOUNT_MODULE:"APPLY_DISCOUNT_MODULE"});var j=a((function e(t){r(this,e),this.scheme=t.scheme,this.licenseURL=t.licenseURL,this.certificate=t.certificate}));h(j,"Scheme",{"drm.PLAYREADY_CENC":"com.microsoft.playready","drm.WIDEVINE_CENC":"com.widevine.alpha","fairplay.FAIRPLAY":"com.apple.fairplay",WIDEVINE_CENC:"com.widevine.alpha",PLAYREADY_CENC:"com.microsoft.playready",FAIRPLAY:"com.apple.fairplay"});var x=function(){function e(t){var n=this;r(this,e),h(this,"drm",[]),this.format=t.format,this.adsPolicy=t.adsPolicy,this.adsParam=t.adsParam,this.duration=t.duration,this.url=t.url,this.type=t.type,this.fileId=t.id,this.protocols=t.protocols,t.drm&&t.drm.map((function(e){return n.drm.push(new j(e))}))}return a(e,[{key:"hasDrmData",value:function(){return this.drm&&this.drm.length>0}},{key:"getProtocol",value:function(e){var t="";if(this.protocols&&this.protocols.length>0)this.protocols.split(",").forEach((function(r){r===e&&(t=r)}));else if("http"===e)return e;return t}}]),e}(),B=a((function e(t){r(this,e),this.streamertype=t.streamertype,this.url=t.url}));h(B,"StreamerType",{HLS:"hls",DASH:"dash",PROGRESSIVE:"progressive"});var U=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(e){var t;if(r(this,i),h(c(t=s.call(this,e)),"sources",[]),h(c(t),"actions",[]),h(c(t),"messages",[]),h(c(t),"plugins",[]),!t.hasError){var n=e.messages;n&&n.map((function(e){return t.messages.push(new M(e))}));var a=e.actions;a&&a.map((function(e){return t.actions.push(new N(e))}));var o=e.sources;o&&o.map((function(e){return t.sources.push(new x(e))}));var u=e.plugins;u&&u.map((function(e){return t.plugins.push(new B(e))}))}return t}return a(i,[{key:"hasBlockAction",value:function(){return void 0!==this.getBlockAction()}},{key:"getBlockAction",value:function(){return this.actions.find((function(e){return e.type===N.Type.BLOCK}))}},{key:"getErrorMessages",value:function(){return this.messages}}]),i}(I);h(U,"Type",{DOWNLOAD:"DOWNLOAD",TRAILER:"TRAILER",CATCHUP:"CATCHUP",START_OVER:"START_OVER",PLAYBACK:"PLAYBACK"});var q=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(e){var t;return r(this,i),h(c(t=s.call(this,e)),"name",""),h(c(t),"description",""),h(c(t),"tags",[]),h(c(t),"metas",[]),h(c(t),"pictures",[]),t.hasError||(t.id=e.id,t.name=e.name,t.description=e.description,t.createDate=e.createDate,t.endDate=e.endDate,t.plays=e.plays,t.views=e.views,t.metas=t._formatTagsMetas(e.metas),t.tags=t._formatTagsMetas(e.tags),t.pictures=e.images),t}return a(i,[{key:"_formatTagsMetas",value:function(e){var t=[];return Object.keys(e).forEach((function(r){if(e[r].objects){var n="";e[r].objects.forEach((function(e){n+=e.value+"|"})),t.push({key:r,value:n})}else t.push({key:r,value:e[r].value})})),t}}]),i}(I);h(q,"Type",{MEDIA:"media",RECORDING:"recording",EPG:"epg"}),h(q,"AssetReferenceType",{MEDIA:"media",EPG_INTERNAL:"epg_internal",EPG_EXTERNAL:"epg_external",NPVR:"nPVR"});var V=function(){function e(t){r(this,e),h(this,"_response",{}),this.requests=this.buildRequests(t),this._entryId=t.entryId}return a(e,[{key:"requests",get:function(){return this._requests},set:function(e){this._requests=e}},{key:"response",get:function(){return this._response},set:function(e){this._response.mediaDataResult=new q(e[0].data),this._response.playBackContextResult=new U(e[1].data)}},{key:"buildRequests",value:function(e){var t=T.get(),r=[];return r.push(L.get(t.serviceUrl,e.ks,e.entryId,e.assetReferenceType)),r.push(L.getPlaybackContext(t.serviceUrl,e.ks,e.entryId,e.type,e.playbackContext)),r}},{key:"isValid",value:function(){return!!this._entryId}}],[{key:"id",get:function(){return"asset"}}]),e}(),H=function(){function e(t){r(this,e),h(this,"_response",{playlistItems:{entries:[]}}),this.requests=this.buildRequests(t),this._entries=t.entries}return a(e,[{key:"requests",get:function(){return this._requests},set:function(e){this._requests=e}},{key:"response",get:function(){return this._response},set:function(e){var t=this;e.forEach((function(e){t._response.playlistItems.entries.push({mediaDataResult:new q(e.data)})}))}},{key:"buildRequests",value:function(e){var t=T.get(),r=[];return e.entries.forEach((function(n){var s=n.assetReferenceType||q.AssetReferenceType.MEDIA;r.push(L.get(t.serviceUrl,e.ks,n.entryId||n,s))})),r}},{key:"isValid",value:function(){return!(!this._entries||!this._entries.length)}}],[{key:"id",get:function(){return"asset_list"}}]),e}(),K={DASH:{name:"dash",mimeType:"application/dash+xml",pathExt:"mpd"},HLS:{name:"hls",mimeType:"application/x-mpegURL",pathExt:"m3u8"},WVM:{name:"wvm",mimeType:"video/wvm",pathExt:"wvm"},MP4:{name:"mp4",mimeType:"video/mp4",pathExt:"mp4"},MP3:{name:"mp3",mimeType:"audio/mpeg",pathExt:"mp3"}},F=new Map([["mpegdash",K.DASH],["applehttp",K.HLS],["url",K.MP4]]);function Y(e){var t=F.get(e);return!!t&&t.name===K.MP4.name}var W=function(){function e(){r(this,e),this.progressive=[],this.dash=[],this.hls=[],this.image=[],this.document=[]}return a(e,[{key:"map",value:function(e,t){if(t)switch(t.name){case K.MP4.name:this.progressive.push(e);break;case K.DASH.name:this.dash.push(e);break;case K.HLS.name:this.hls.push(e)}}},{key:"toJSON",value:function(){var e={progressive:[],dash:[],hls:[],image:[],document:[]};return this.progressive.forEach((function(t){return e.progressive.push(t.toJSON())})),this.hls.forEach((function(t){return e.hls.push(t.toJSON())})),this.dash.forEach((function(t){return e.dash.push(t.toJSON())})),e.image=this.image,e.document=this.document,e}}]),e}(),G=function(){function e(){r(this,e),this.metadata=new Map,this.sources=new W,this.type=e.Type.UNKNOWN}return a(e,[{key:"toJSON",value:function(){return{id:this.id,name:this.name,sources:this.sources.toJSON(),duration:this.duration,dvrStatus:this.dvrStatus,status:this.status,metadata:this.metadata,type:this.type,poster:this.poster,assetReferenceType:this.assetReferenceType,downloadUrl:this.downloadUrl}}}]),e}();h(G,"Type",{VOD:"Vod",LIVE:"Live",IMAGE:"Image",AUDIO:"Audio",UNKNOWN:"Unknown",DOCUMENT:"Document"}),h(G,"DvrStatus",{ON:1,OFF:0});var J=function(){function e(t,n,s){r(this,e),this.licenseUrl=t,this.scheme=n,s&&(this.certificate=s)}return a(e,[{key:"toJSON",value:function(){var e={licenseUrl:this.licenseUrl,scheme:this.scheme};return this.certificate&&(e.certificate=this.certificate),e}}]),e}(),X=function(){function e(){r(this,e)}return a(e,[{key:"toJSON",value:function(){var e={id:this.id,url:this.url,mimetype:this.mimetype};return this.bandwidth&&(e.bandwidth=this.bandwidth),this.width&&(e.width=this.width),this.height&&(e.height=this.height),this.label&&(e.label=this.label),this.drmData&&this.drmData.length>0&&(e.drmData=[],this.drmData.forEach((function(t){Array.isArray(e.drmData)&&e.drmData.push(t.toJSON())}))),e}}]),e}(),Q=a((function e(){r(this,e),this.items=[]})),z=a((function e(t){r(this,e),this.url=t.url,this.clickThroughUrl=t.clickThroughUrl})),Z=h(h(h({},q.Type.MEDIA,h(h({},U.Type.TRAILER,(function(){return{type:G.Type.VOD}})),U.Type.PLAYBACK,(function(e){return"KalturaLiveAsset"===e.objectType?{type:G.Type.LIVE,dvrStatus:e.enableTrickPlay?G.DvrStatus.ON:G.DvrStatus.OFF}:parseInt(e.externalIds)>0?{type:G.Type.LIVE,dvrStatus:G.DvrStatus.OFF}:{type:G.Type.VOD}}))),q.Type.EPG,h(h({},U.Type.CATCHUP,(function(){return{type:G.Type.VOD}})),U.Type.START_OVER,(function(){return{type:G.Type.LIVE,dvrStatus:G.DvrStatus.ON}}))),q.Type.RECORDING,h({},U.Type.PLAYBACK,(function(){return{type:G.Type.VOD}}))),$=function(){function e(){r(this,e)}return a(e,null,[{key:"getMediaEntry",value:function(t,r){var n=new G;e._fillBaseData(n,t,r);var s=t.playBackContextResult,i=t.mediaDataResult,a=s.sources,o=e._filterSourcesByFormats(a,r.formats);n.sources=e._getParsedSources(o);var u=e._getMediaType(i.data,r.mediaType,r.contextType);return n.type=u.type,n.dvrStatus=u.dvrStatus,n.duration=Math.max.apply(Math,a.map((function(e){return e.duration}))),n}},{key:"getEntryList",value:function(t,r){var n=new Q;return t.playlistItems.entries.forEach((function(t){var s=new G,i=r.find((function(e){return e.entryId===t.mediaDataResult.id}));e._fillBaseData(s,t,i),n.items.push(s)})),n}},{key:"getBumper",value:function(e){var t=e.playBackContextResult.plugins.find((function(e){return e.streamertype===B.StreamerType.PROGRESSIVE}));if(t)return new z(t)}},{key:"_fillBaseData",value:function(t,r,n){var s=r.mediaDataResult,i=e.reconstructMetadata(s);return i.description=s.description,i.name=s.name,s.createDate&&(i.createdAt=s.createDate),s.endDate&&(i.endDate=s.endDate),s.data.entryId&&(i.entryId=s.data.entryId),s.data.epgId&&(i.epgId=s.data.epgId),s.data.recordingId&&(i.recordingId=s.data.recordingId),n&&n.mediaType&&(i.mediaType=n.mediaType),n&&n.contextType&&(i.contextType=n.contextType),t.metadata=i,t.poster=e._getPoster(s.pictures),t.id=s.id,t}},{key:"reconstructMetadata",value:function(t){return{metas:e.addToMetaObject(t.metas),tags:e.addToMetaObject(t.tags)}}},{key:"addToMetaObject",value:function(e){var t={};return e&&e.forEach((function(e){t[e.key]=e.value})),t}},{key:"_getPoster",value:function(e){if(e&&e.length>0){var t=e[0].url;return/.*\/thumbnail\/.*(?:width|height)\/\d+\/(?:height|width)\/\d+/.test(t)?t:e.map((function(e){return{url:e.url,width:e.width,height:e.height}}))}return""}},{key:"_getMediaType",value:function(e,t,r){var n={type:G.Type.UNKNOWN};return Z[t]&&Z[t][r]&&(n=Z[t][r](e)),n}},{key:"_filterSourcesByFormats",value:function(e,t){return t.length>0&&(e=e.filter((function(e){return t.includes(e.type)}))),e}},{key:"_getParsedSources",value:function(t){var r=new W,n=function(t){var n=e._parseAdaptiveSource(t);if(n){var s=F.get(t.format);r.map(n,s)}};return t&&t.length>0&&(t.filter((function(e){return!Y(e.format)})).forEach(n),t.filter((function(e){return Y(e.format)})).forEach(n)),r}},{key:"_parseAdaptiveSource",value:function(t){var r=new X;if(t){var n=t.url,s=F.get(t.format);if(s&&(r.mimetype=s.mimeType),!n)return e._logger.error("failed to create play url from source, discarding source: (".concat(t.fileId,"), ").concat(t.format,".")),null;if(r.url=n,r.id=t.fileId+","+t.format,t.hasDrmData()){var i=[];t.drm.forEach((function(e){i.push(new J(e.licenseURL,j.Scheme[e.scheme],e.certificate))})),r.drmData=i}}return r}},{key:"hasBlockAction",value:function(e){return e.playBackContextResult.hasBlockAction()}},{key:"getBlockAction",value:function(e){return e.playBackContextResult.getBlockAction()}},{key:"getErrorMessages",value:function(e){return e.playBackContextResult.getErrorMessages()}}]),e}();h($,"_logger",m("OTTProviderParser"));var ee=function(e){u(i,e);var t,n,s=(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=l(t);if(n){var s=l(this).constructor;e=Reflect.construct(r,arguments,s)}else e=r.apply(this,arguments);return f(this,e)});function i(e,t){var n;return r(this,i),(n=s.call(this,e,t))._logger=m("OTTProvider"),T.set(e.env),n._networkRetryConfig=Object.assign(n._networkRetryConfig,e.networkRetryParameters),n}return a(i,[{key:"env",get:function(){return T.get()}},{key:"getMediaConfig",value:function(e){var t=this;return e.ks&&(this.ks=e.ks,this._isAnonymous=!1),this._dataLoader=new P(this.partnerId,this.ks,this._networkRetryConfig),new Promise((function(r,n){var s=e.entryId;if(s){var i=t.ks;i||(i="{1:result:ks}",t._dataLoader.add(b,{partnerId:t.partnerId}));var a=e.contextType||U.Type.PLAYBACK,o=e.mediaType||q.Type.MEDIA,u=e.assetReferenceType||q.AssetReferenceType.MEDIA,c={mediaProtocol:e.protocol,assetFileIds:e.fileIds,context:a};e.streamerType&&(c.streamerType=e.streamerType),e.urlType&&(c.urlType=e.urlType),e.adapterData&&(c.adapterData=e.adapterData),t._dataLoader.add(V,{entryId:s,ks:i,type:o,playbackContext:c,assetReferenceType:u});var f={contextType:a,mediaType:o,formats:e.formats||[]};return t._dataLoader.fetchData().then((function(e){try{r(t._parseDataFromResponse(e,f))}catch(e){n(e)}}),(function(e){n(e)}))}n(new g(g.Severity.CRITICAL,g.Category.PROVIDER,g.Code.MISSING_MANDATORY_PARAMS,{message:"missing entry id"}))}))}},{key:"_parseDataFromResponse",value:function(e,t){this._logger.debug("Data parsing started");var r={session:{isAnonymous:this._isAnonymous,partnerId:this.partnerId},sources:this._getDefaultSourcesObject(),plugins:{}};if(this.uiConfId&&(r.session.uiConfId=this.uiConfId),e){if(e.has(b.id)){var n=e.get(b.id);n&&n.response&&(r.session.ks=n.response)}else r.session.ks=this.ks;if(e.has(V.id)){var s=e.get(V.id);if(s&&s.response&&Object.keys(s.response).length){var i=s.response;if($.hasBlockAction(i))throw new g(g.Severity.CRITICAL,g.Category.SERVICE,g.Code.BLOCK_ACTION,{action:$.getBlockAction(i),messages:$.getErrorMessages(i)});var a=$.getMediaEntry(i,t);Object.assign(r.sources,this._getSourcesObject(a)),this._verifyHasSources(r.sources);var o=$.getBumper(i);o&&Object.assign(r.plugins,{bumper:o})}}}return this._logger.debug("Data parsing finished",r),r}},{key:"getEntryListConfig",value:function(e){var t=this;return e.ks&&(this.ks=e.ks,this._isAnonymous=!1),this._dataLoader=new P(this.partnerId,this.ks,this._networkRetryConfig),new Promise((function(r,n){var s=e.entries;if(s&&s.length){var i=t.ks;i||(i="{1:result:ks}",t._dataLoader.add(b,{partnerId:t.partnerId})),t._dataLoader.add(H,{entries:s,ks:i}),t._dataLoader.fetchData(!1).then((function(e){r(t._parseEntryListDataFromResponse(e,s))}),(function(e){n(e)}))}else n({success:!1,data:"Missing mandatory parameter"})}))}},{key:"_parseEntryListDataFromResponse",value:function(e,t){var r=this;this._logger.debug("Data parsing started");var n={id:"",metadata:{name:"",description:""},poster:"",items:[],playlistLastEntryId:""};if(e&&e.has(H.id)){var s=e.get(H.id);s&&s.response&&$.getEntryList(s.response,t).items.forEach((function(e){return n.items.push({sources:r._getSourcesObject(e)})}))}return this._logger.debug("Data parsing finished",n),n}},{key:"_getDefaultSourcesObject",value:function(){return{hls:[],dash:[],progressive:[],image:[],document:[],id:"",duration:0,type:G.Type.UNKNOWN,poster:"",dvr:!1,vr:null,metadata:{name:"",description:"",tags:""}}}},{key:"_getSourcesObject",value:function(e){var t=this._getDefaultSourcesObject(),r=e.sources.toJSON();return t.hls=r.hls,t.dash=r.dash,t.progressive=r.progressive,t.id=e.id,t.duration=e.duration,t.type=e.type,t.dvr=!!e.dvrStatus,t.poster=e.poster,e.metadata&&e.metadata.metas&&"string"==typeof e.metadata.metas.tags&&e.metadata.metas.tags.indexOf("360")>-1&&(t.vr={}),Object.assign(t.metadata,e.metadata),t}}]),i}(v),te="@playkit-js/playkit-js-providers-ott",re="2.41.0-canary.0-3d6d02a",ne=U.Type,se=q.Type;return t}()}));
2
2
  //# sourceMappingURL=playkit-ott-provider.js.map