@playkit-js/playkit-js-providers 2.40.2-canary.0-c7a43ae → 2.41.0-canary.0-2452bbc
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/dist/playkit-analytics-service.js +1 -1
- package/dist/playkit-analytics-service.js.map +1 -1
- package/dist/playkit-bookmark-service.js +1 -1
- package/dist/playkit-bookmark-service.js.map +1 -1
- package/dist/playkit-ott-provider.js +1 -1
- package/dist/playkit-ott-provider.js.map +1 -1
- package/dist/playkit-ovp-provider.js +1 -1
- package/dist/playkit-ovp-provider.js.map +1 -1
- package/dist/playkit-stats-service.js +1 -1
- package/dist/playkit-stats-service.js.map +1 -1
- package/package.json +9 -9
|
@@ -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]}}(self,(()=>(()=>{"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={};function s(e){return s="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},s(e)}function r(e,t,r){return(t=function(e){var t=function(e,t){if("object"!==s(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,"string");if("object"!==s(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===s(t)?t:String(t)}(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:()=>J,MediaType:()=>$,NAME:()=>W,Provider:()=>Y,VERSION:()=>G});const a={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 i={};function o(e){return a.get(e)}const n=o;class c{constructor(e,t,s,r={}){this.severity=e,this.category=t,this.code=s,this.data=r,c._logger.error(`Category:${t} | Code:${s} |`,r)}}r(c,"Severity",{RECOVERABLE:1,CRITICAL:2}),r(c,"Category",{NETWORK:1,SERVICE:2,PROVIDER:3}),r(c,"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}),r(c,"_logger",n("Error"));class h{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){r(this,"_networkRetryConfig",{async:!0,timeout:0,maxAttempts:4}),function(e){e&&"function"==typeof e.getLogger&&(a.get=e.getLogger),e&&e.LogLevel&&(i=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 c(c.Severity.CRITICAL,c.Category.PROVIDER,c.Code.METHOD_NOT_IMPLEMENTED,{message:"getMediaConfig method must be implement by the derived class"}))}getPlaylistConfig(e){return Promise.reject(new c(c.Severity.CRITICAL,c.Category.PROVIDER,c.Code.METHOD_NOT_IMPLEMENTED,{message:"The provider does not support loading playlist by id"}))}getEntryListConfig(e){return Promise.reject(new c(c.Severity.CRITICAL,c.Category.PROVIDER,c.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 c(c.Severity.CRITICAL,c.Category.SERVICE,c.Code.MISSING_PLAY_SOURCE,{action:"",messages:`No play source for entry id: ${e.id}`})}get LogLevel(){return i}getLogLevel(e){return function(e){return o(e).getLevel()}(e)}setLogLevel(e,t){!function(e,t){o(t).setLevel(e)}(e,t)}}const u=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]=u(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]=u(t[e]))}))):t=e,t},p={serviceParams:{apiVersion:"7.8.1"}};class d{static set(e){e&&Object.assign(p,e)}static get(){return u(p)}}class l{constructor(e){r(this,"_loadersResponseMap",new Map),r(this,"_loaders",new Map),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 c(c.Severity.CRITICAL,c.Category.NETWORK,c.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{constructor(e=new Map){r(this,"retryConfig",{async:!0,timeout:0,maxAttempts:4}),r(this,"_attemptCounter",1),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 c(c.Severity.CRITICAL,c.Category.NETWORK,c.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,c.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,c.Code.TIMEOUT,{timeout:(performance.now()-t)/1e3,statusText:e.statusText})},e.onerror=e.onabort=()=>{this._handleError(e,c.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 c(c.Severity.CRITICAL,c.Category.NETWORK,t,s)}}class g{constructor(e){r(this,"hasError",!1),"KalturaAPIException"===e.objectType?(this.hasError=!0,this.error=new y(e.code,e.message)):e.error&&"KalturaAPIException"===e.error.objectType?(this.hasError=!0,this.error=new y(e.error.code,e.error.message)):this.data=e}}class y{constructor(e,t){this.code=e,this.message=t}}class _ extends m{constructor(...e){super(...e),r(this,"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){_._logger.error(`${e.message}`),s(new c(c.Severity.CRITICAL,c.Category.PROVIDER,c.Code.FAILED_PARSING_REQUEST,{error:e,params:this.params}))}this.doHttpRequest().then((r=>{const a=new f(r,e);a.success?t({headers:this.responseHeaders,response:a}):s(new c(c.Severity.CRITICAL,c.Category.NETWORK,c.Code.MULTIREQUEST_API_ERROR,{url:this.url,headers:this.responseHeaders,results:a.results}))}),(e=>{s(e)}))}))}}r(_,"_logger",n("MultiRequestBuilder"));class f{constructor(e,t=!0){r(this,"results",[]);const s=e.result?e.result:e,a=(Array.isArray(s)?s:[s]).map((e=>new g(e))),i=a.filter((e=>e.hasError));i.forEach((e=>{f._logger.error(`Service returned an error with error code: ${e.error.code} and message: ${e.error.message}.`)})),this.results=a,t&&i.length||i.length===this.results.length?this.success=!1:(this.results=this.results.filter((e=>!e.hasError)),this.success=!0)}}r(f,"_logger",n("MultiRequestResult"));class T{static getMultiRequest(e,t){const s=d.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 _(a);return i.method="POST",i.service="multirequest",i.url=i.getUrl(s.serviceUrl),i.params=r,i}}class E extends l{constructor(e,t="",s){super(s),this._multiRequest=T.getMultiRequest(t,e)}}class R extends T{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 I{static get id(){return"session"}constructor(e){r(this,"_response",{}),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=d.get(),s=[];return s.push(R.anonymousLogin(t.serviceUrl,e.partnerId,e.udid)),s}isValid(){return!!this._partnerId}}const A="asset";class C extends T{static getPlaybackContext(e,t,s,r,a){const i=new Map;i.set("Content-Type","application/json");const o=new m(i);o.service=A,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=A,i.action="get",i.method="POST",i.url=i.getUrl(e),i.params={id:s,assetReferenceType:r,ks:t},i}}class O{constructor(e){this.message=e.message,this.code=e.code}}class S{constructor(e){this.type=e.type}}r(S,"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"});class v{constructor(e){this.scheme=e.scheme,this.licenseURL=e.licenseURL,this.certificate=e.certificate}}r(v,"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"});class D{constructor(e){r(this,"drm",[]),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 v(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 L{constructor(e){this.streamertype=e.streamertype,this.url=e.url}}r(L,"StreamerType",{HLS:"hls",DASH:"dash",PROGRESSIVE:"progressive"});class P extends g{constructor(e){if(super(e),r(this,"sources",[]),r(this,"actions",[]),r(this,"messages",[]),r(this,"plugins",[]),!this.hasError){const t=e.messages;t&&t.map((e=>this.messages.push(new O(e))));const s=e.actions;s&&s.map((e=>this.actions.push(new S(e))));const r=e.sources;r&&r.map((e=>this.sources.push(new D(e))));const a=e.plugins;a&&a.map((e=>this.plugins.push(new L(e))))}}hasBlockAction(){return void 0!==this.getBlockAction()}getBlockAction(){return this.actions.find((e=>e.type===S.Type.BLOCK))}getErrorMessages(){return this.messages}}r(P,"Type",{DOWNLOAD:"DOWNLOAD",TRAILER:"TRAILER",CATCHUP:"CATCHUP",START_OVER:"START_OVER",PLAYBACK:"PLAYBACK"});class w extends g{constructor(e){super(e),r(this,"name",""),r(this,"description",""),r(this,"tags",[]),r(this,"metas",[]),r(this,"pictures",[]),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}}r(w,"Type",{MEDIA:"media",RECORDING:"recording",EPG:"epg"}),r(w,"AssetReferenceType",{MEDIA:"media",EPG_INTERNAL:"epg_internal",EPG_EXTERNAL:"epg_external",NPVR:"nPVR"});class b{static get id(){return"asset"}constructor(e){r(this,"_response",{}),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 w(e[0].data),this._response.playBackContextResult=new P(e[1].data)}get response(){return this._response}buildRequests(e){const t=d.get(),s=[];return s.push(C.get(t.serviceUrl,e.ks,e.entryId,e.assetReferenceType)),s.push(C.getPlaybackContext(t.serviceUrl,e.ks,e.entryId,e.type,e.playbackContext)),s}isValid(){return!!this._entryId}}class M{static get id(){return"asset_list"}constructor(e){r(this,"_response",{playlistItems:{entries:[]}}),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 w(e.data)})}))}get response(){return this._response}buildRequests(e){const t=d.get(),s=[];return e.entries.forEach((r=>{const a=r.assetReferenceType||w.AssetReferenceType.MEDIA;s.push(C.get(t.serviceUrl,e.ks,r.entryId||r,a))})),s}isValid(){return!(!this._entries||!this._entries.length)}}const N={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"}},k=new Map([["mpegdash",N.DASH],["applehttp",N.HLS],["url",N.MP4]]);function x(e){const t=k.get(e);return!!t&&t.name===N.MP4.name}class j{constructor(){this.progressive=[],this.dash=[],this.hls=[],this.image=[]}map(e,t){if(t)switch(t.name){case N.MP4.name:this.progressive.push(e);break;case N.DASH.name:this.dash.push(e);break;case N.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 U{constructor(){this.metadata=new Map,this.sources=new j,this.type=U.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}}}r(U,"Type",{VOD:"Vod",LIVE:"Live",IMAGE:"Image",AUDIO:"Audio",UNKNOWN:"Unknown"}),r(U,"DvrStatus",{ON:1,OFF:0});class B{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 q{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 V{constructor(){this.items=[]}}class H{constructor(e){this.url=e.url,this.clickThroughUrl=e.clickThroughUrl}}const K={[w.Type.MEDIA]:{[P.Type.TRAILER]:()=>({type:U.Type.VOD}),[P.Type.PLAYBACK]:e=>"KalturaLiveAsset"===e.objectType?{type:U.Type.LIVE,dvrStatus:e.enableTrickPlay?U.DvrStatus.ON:U.DvrStatus.OFF}:parseInt(e.externalIds)>0?{type:U.Type.LIVE,dvrStatus:U.DvrStatus.OFF}:{type:U.Type.VOD}},[w.Type.EPG]:{[P.Type.CATCHUP]:()=>({type:U.Type.VOD}),[P.Type.START_OVER]:()=>({type:U.Type.LIVE,dvrStatus:U.DvrStatus.ON})},[w.Type.RECORDING]:{[P.Type.PLAYBACK]:()=>({type:U.Type.VOD})}};class F{static getMediaEntry(e,t){const s=new U;F._fillBaseData(s,e,t);const r=e.playBackContextResult,a=e.mediaDataResult,i=r.sources,o=F._filterSourcesByFormats(i,t.formats);s.sources=F._getParsedSources(o);const n=F._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 V;return e.playlistItems.entries.forEach((e=>{const r=new U,a=t.find((t=>t.entryId===e.mediaDataResult.id));F._fillBaseData(r,e,a),s.items.push(r)})),s}static getBumper(e){const t=e.playBackContextResult.plugins.find((e=>e.streamertype===L.StreamerType.PROGRESSIVE));if(t)return new H(t)}static _fillBaseData(e,t,s){const r=t.mediaDataResult,a=F.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=F._getPoster(r.pictures),e.id=r.id,e}static reconstructMetadata(e){return{metas:F.addToMetaObject(e.metas),tags:F.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:U.Type.UNKNOWN};return K[t]&&K[t][s]&&(r=K[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 j,s=e=>{const s=F._parseAdaptiveSource(e);if(s){const r=k.get(e.format);t.map(s,r)}};return e&&e.length>0&&(e.filter((e=>!x(e.format))).forEach(s),e.filter((e=>x(e.format))).forEach(s)),t}static _parseAdaptiveSource(e){const t=new q;if(e){const s=e.url,r=k.get(e.format);if(r&&(t.mimetype=r.mimeType),!s)return F._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 B(e.licenseURL,v.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()}}r(F,"_logger",n("OTTProviderParser"));class Y extends h{constructor(e,t){super(e,t),this._logger=n("OTTProvider"),d.set(e.env),this._networkRetryConfig=Object.assign(this._networkRetryConfig,e.networkRetryParameters)}get env(){return d.get()}getMediaConfig(e){return e.ks&&(this.ks=e.ks,this._isAnonymous=!1),this._dataLoader=new E(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(I,{partnerId:this.partnerId}));const i=e.contextType||P.Type.PLAYBACK,o=e.mediaType||w.Type.MEDIA,n=e.assetReferenceType||w.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 c(c.Severity.CRITICAL,c.Category.PROVIDER,c.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(I.id)){const t=e.get(I.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(F.hasBlockAction(e))throw new c(c.Severity.CRITICAL,c.Category.SERVICE,c.Code.BLOCK_ACTION,{action:F.getBlockAction(e),messages:F.getErrorMessages(e)});const a=F.getMediaEntry(e,t);Object.assign(s.sources,this._getSourcesObject(a)),this._verifyHasSources(s.sources);const i=F.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 E(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(I,{partnerId:this.partnerId})),this._dataLoader.add(M,{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(M.id)){const r=e.get(M.id);r&&r.response&&F.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:U.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 W="@playkit-js/playkit-js-providers-ott",G="2.40.2-canary.0-c7a43ae",J=P.Type,$=w.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 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})()));
|
|
2
2
|
//# sourceMappingURL=playkit-ott-provider.js.map
|