(function(){var g={}; var _ = _ || {}
var f=function(window){var YB="A persistent DRM session already exists for: ",ZB="No DRM configuration.",$B="clpp.persistent",aC="clpp.persistent.SimpleSessionStorage",bC=function(a,b){for(var c=[],d=_.u(a),e=d.next();!e.done;e=d.next())c.push(b(e.value));return c},cC=function(a){a=a.h.keys();a=bC(a,function(b){return b.sessionId});return Array.from(a)},dC=function(a,b){var c,d,e;return _.H(function(f){if(1==f.a)return _.x(f,_.Ip(a,b),2);c=f.f;if(!c)return a.g.debug("Ignoring attempt to remove missing session",b),f["return"]();
d=[];(e=a.h.get(c))&&a.C&&(e.yc=new _.kk,d.push(e.yc));a.g.debug("Attempting to remove session",b);d.push(c.remove());return f["return"](Promise.all(d))})},fC=function(a,b){a.L=eC;a.N=[];a.H=!0;return _.kp(a,b)},hC=function(a,b,c,d,e,f){a.L=gC;var g=new Map,h=_.Np(b);g.set(h,{audioCapabilities:e,videoCapabilities:f,distinctiveIdentifier:_.Ze,persistentState:_.Mf,sessionTypes:[_.df],label:h,drmInfos:[{keySystem:b,licenseServerUri:c,distinctiveIdentifierRequired:!1,persistentStateRequired:!0,audioRobustness:"",
videoRobustness:"",serverCertificate:d,initData:null,keyIds:null}]});return _.up(a,g)},iC=function(){this.g=new _.J(aC)},jC=function(a){a=JSON.parse(a);var b=JSON.parse(a.sessionIds),c=a.audioCapabilities||[],d=a.videoCapabilities||[],e=a.serverCertificate||[],f=a.drmConfig||{};return{sessionIds:b,keySystem:a.keySystem,licenseServerUri:decodeURIComponent(a.licenseServerUri||""),serverCertificate:e?new Uint8Array(e):null,audioCapabilities:c,videoCapabilities:d,drmConfig:f}},kC=function(a,b){var c=
_.Ym(a),d=_.vm({drm:a});d.drm=a;var e=new _.gp({Db:b,onError:function(){},xg:function(){},wg:function(){},onEvent:function(){},getConfiguration:function(){return d},ud:function(){return null}});e.f=c;return e},nC=function(a,b,c){var d,e,f,g,h,l,m,n,p;return _.H(function(q){switch(q.a){case 1:d=lC;e=mC;if(!a)return e.debug(ZB),q["return"]();f=a.offlineId;return 0===f.length?q["return"]():_.x(q,d.get(f),2);case 2:if(g=q.f)return e.debug(YB,f),q["return"]();h=kC(a,c);_.C(q,3,4);return _.x(q,fC(h,b),
6);case 6:return _.x(q,_.Bp(h),7);case 7:return _.x(q,_.Cp(h),8);case 8:return l=h.getDrmInfo(),m=b.map(function(t){return{contentType:_.ol(t.video.mimeType,t.video.codecs),robustness:l.videoRobustness}}),n=cC(h),g={sessionIds:n,keySystem:l.keySystem,licenseServerUri:l.licenseServerUri,serverCertificate:l.serverCertificate,audioCapabilities:[],videoCapabilities:m,drmConfig:a},_.x(q,d.store(f,g),4);case 4:return _.vh(q),_.x(q,h.destroy(),10);case 10:_.wh(q);break;case 3:throw p=_.E(q),e.error("Error while persisting DRM session "+
f),new _.N(1,6,6200,null,p);}})},oC=function(){this.g=new _.J($B)},eC=1,gC=2;_.r=iC.prototype;
_.r.store=function(a,b){var c;return _.H(function(d){var e=JSON.stringify(b.sessionIds),f=b.serverCertificate?Array.from(b.serverCertificate):null;f=JSON.stringify(f);var g=JSON.stringify(b.audioCapabilities),h=JSON.stringify(b.videoCapabilities);c=JSON.stringify({sessionIds:e,keySystem:b.keySystem,licenseServerUri:encodeURIComponent(b.licenseServerUri),serverCertificate:f,audioCapabilities:g,videoCapabilities:h,drmConfig:JSON.stringify(b.drmConfig)});window.localStorage.setItem(encodeURIComponent(a),
btoa(c));_.y(d)})};_.r.get=function(a){var b=this,c;return _.H(function(d){if(c=window.localStorage.getItem(encodeURIComponent(a)))try{return d["return"](jC(atob(c)))}catch(e){b.g.warn("Error while loading offline items for "+a+" from storage: ",e)}return d["return"](null)})};_.r["delete"]=function(a){return _.H(function(b){window.localStorage.removeItem(encodeURIComponent(a));_.y(b)})};_.r.clear=function(){return _.H(function(a){window.localStorage.clear();_.y(a)})};_.r.getName=function(){return aC};_.I("clpp.persistent.useStorage",function(a){var b=["store","get","delete","clear","getName"];var c=[];_.L.R(a)||(_.L.Ub(a.store)||c.push("store"),_.L.Ub(a.get)||c.push("get"),_.L.Ub(a["delete"])||c.push("delete"),_.L.Ub(a.clear)||c.push("clear"),_.L.Ub(a.getName)||c.push("getName"),b=c);if(0<b.length)throw mC.warn("Invalid session storage implementation"),new _.N(1,6,6202,{missingMethods:b});lC=a});
_.I("clpp.persistent.fetchLicense",function(a,b,c){for(var d=[],e=2;e<arguments.length;++e)d[e-2]=arguments[e];var f,g,h,l,m,n,p,q,t,v,z,A,D,G,B,F,M,R,ka;return _.H(function(U){switch(U.a){case 1:f=lC;g=mC;h=function(qa,Ba){return new _.N(1,6,6200,qa,Ba)};l=_.Lq(a).shift();if(!l)throw h("No source specified.");if(!b)throw h(ZB);m=b.offlineId;if(typeof m!==_.eg||!m.length)throw h("Missing offline id.");return _.x(U,f.get(m),2);case 2:if(n=U.f)return g.debug(YB,m),U["return"]();p=_.vm();q=new _.vk;
t=[];v=_.u(d);for(z=v.next();!z.done;z=v.next())A=z.value,D=new A,_.zm(D.id())||(D.f(),_.Bm(D),t.push(D));G=null;_.C(U,3,4);return _.x(U,_.av(l.url,q,p.manifest.attemptParameters,l.type||null),6);case 6:return G=U.f,G.configure(p.manifest),_.x(U,G.start(l.url,{configurationId:"",networkingEngine:q,onContentSteeringInfoFound:function(){return null},filterAllPeriods:function(){},filterNewPeriod:function(){},onEvent:function(){},onError:function(){}}),7);case 7:B=U.f;if(!B.periods.length)throw h(null,
new _.N(_.O,4,4014));F=_.Su(B.periods);return _.x(U,nC(b,F,q),4);case 4:for(_.vh(U);t.length;)M=t.shift(),M.a(),_.ym["delete"](M.id());R=[];G&&R.push(G.stop());R.push(q.destroy());return _.x(U,Promise.all(R),9);case 9:_.wh(U);break;case 3:ka=_.E(U);if(ka instanceof _.N&&6200===ka.code)throw ka;throw h(null,ka);}})});
_.I("clpp.persistent.removeLicense",function(a){var b,c,d,e,f,g,h;return _.H(function(l){switch(l.a){case 1:b=lC;c=mC;if(!_.L.ia(a)||0===a.length)return c.warn("Invalid offlineId"),l["return"]();e=d=null;_.C(l,2,3);return _.x(l,b.get(a),5);case 5:f=l.f;if(!f)return c.debug("No persistent DRM session found"),l["return"]();f.drmConfig.delayLicenseRequestUntilPlayed=!0;e=new _.vk;d=kC(f.drmConfig,e);return _.x(l,hC(d,f.keySystem,f.licenseServerUri,f.serverCertificate,f.audioCapabilities,f.videoCapabilities),
6);case 6:return _.x(l,_.Bp(d),7);case 7:return _.x(l,Promise.all(f.sessionIds.map(function(m){return _.H(function(n){if(1==n.a)return _.x(n,dC(d,m),2);c.debug("successfully removed session with id",m);_.y(n)})})),8);case 8:return _.x(l,b["delete"](a),3);case 3:return _.vh(l),g=[],d&&g.push(d.destroy()),e&&g.push(e.destroy()),_.x(l,Promise.all(g),10);case 10:_.wh(l);break;case 2:throw h=_.E(l),c.error("Failed to remove session"),new _.N(1,6,6201,null,h);}})});
_.I("clpp.persistent.getSessionStorage",function(){return lC});var lC=new iC,mC=new _.J($B);_.w(oC,_.Bu);oC.prototype.id=function(){return _.cf};oC.prototype.l=function(a,b){var c=this,d,e,f;return _.H(function(g){if(1==g.a){d=a.getConfiguration().drm;if(!d)return c.g.debug("No DRM configuration found for loaded source."),g["return"]();c.g.debug("Persisting DRM session ID: "+d.offlineId);e=a.getNetworkEngine();_.C(g,2);return _.x(g,nC(d,b,e),4)}if(2!=g.a)return a.trigger(new _.K(_.ae,{offlineId:d.offlineId})),_.uh(g,0);f=_.E(g);a.onError(f);_.y(g)})};
oC.prototype.j=function(a){var b=this,c,d;return _.H(function(e){if(1==e.a)return b.g.debug("Getting EME session IDs for "+a),c=lC,_.C(e,2),_.x(e,c.get(a),4);if(2!=e.a){if(d=e.f)return e["return"](d.sessionIds||[]);b.g.debug("No offline session found for "+a);return e["return"]([])}_.E(e);b.g.warn("Error while loading session info from storage");return e["return"]([])})};_.I("clpp.persistent.PersistentLicenseComponent",oC);};
if(typeof(module)!="undefined"&&module.exports){var x=require("./cl.core.js");_ = x._;(f.call(g,this));module.exports=g;}
else if (typeof(define)!="undefined"&&define.amd) {define(["./cl.core"], function(c){_=c._;(f.call(g,this));return g;});}
else{_=this.clpp._;(f.call(g,this));}
})();