(function(){var g={}; var _ = _ || {}
var f=function(window){var uC=function(a){switch(a.type){case 1:return rC;case 2:return sC;case 3:return tC}},wC=function(a){var b=Object.keys(a).find(function(c){return vC.includes(c.toLowerCase())});return void 0!==b?a[b]:void 0},xC=function(a,b){this.m=a;this.o=this.f=null;this.B=("000000"+(Math.random()*Math.pow(36,6)<<0).toString(36)).slice(-6);this.a=new _.gi;this.g=b;this.A=this.l=this.h=!1;this.w=null;this.j=a.getNetworkEngine();this.G=this.Qk.bind(this);this.C=this.Pk.bind(this)},zC=function(a){var b={debug:!0,
data:yC(a)};a.f&&a.f.muxOptionsOverride&&_.L.xd(a.f.muxOptionsOverride)&&(b=_.L.ta(b,a.f.muxOptionsOverride));b=_.L.ta(b,{getPlayheadTime:function(){return 1E3*a.m.getPosition()},getStateData:function(){a.g.debug("getStateData()");var c=a.m.getLoadedSource(),d=a.m.getTrackManager(),e=a.m.getSurface(),f={player_is_paused:a.m.isPaused(),player_is_fullscreen:e.isFullscreen(),video_source_duration:1E3*a.m.getDuration(),player_autoplay_on:!!a.m.getConfiguration().autoplay};if(c){var g=new _.Mk(c.url);
f.video_source_url=_.Nk(g);f.video_source_mime_type=c.type;c.name&&(f.video_title=c.name)}if(c=e.getContainer())f.player_width=c.offsetWidth,f.player_height=c.offsetHeight;(c=a.m.getSurface().getMedia())?c={videoWidth:c.videoWidth,videoHeight:c.videoHeight}:(c=a.m.getTrackManager().ma(),c={videoWidth:c.width,videoHeight:c.height});e=c;c=e.videoWidth;e=e.videoHeight;a.g.debug("Video dimensions: "+c+"x"+e);c&&e&&(f.video_source_height=c,f.video_source_width=e);(d=d.qa())&&d.language&&(f.player_language_code=
d.language);return f}});a.g.debug("Mux SDK options",b);return b},yC=function(a){var b={env_key:a.f.envKey,video_title:a.o&&a.o.name||"",player_name:_.xa,player_software_name:_.xa,player_software_version:_.ia,player_mux_plugin_name:"CastlabsPlayer built-in Mux Plugin",player_mux_plugin_version:_.ia};(a=a.m.getConfiguration().viewerId)&&(b.viewer_user_id=a);return b},AC=function(a){a.a.on(a.m,_.rg,function(){var b={player_playhead_time:1E3*a.m.getPosition()};a.emit(_.rg,b)});a.a.on(a.m,_.ff,function(){return a.emit(_.ff)});
a.a.on(a.m,_.Yc,a.Mk.bind(a));a.a.on(a.m,_.bg,a.Ok.bind(a));a.a.on(a.m,_.Cg,function(){return a.emit(_.Uf)});a.a.on(a.m,_.Bg,function(){return a.emit(_.Tf)});a.a.on(a.m,_.ie,a.Nk.bind(a));a.a.on(a.m,_.hc,function(){return a.emit("adbreakstart")});a.a.on(a.m,_.ic,function(){return a.emit("adbreakend")});a.a.on(a.m,_.xc,function(){a.emit("adplay");a.emit("adplaying")});a.a.on(a.m,_.tc,function(){return a.emit("adpause")});a.a.on(a.m,_.vc,function(){a.emit("adplay");a.emit("adplaying")});a.a.on(a.m,
_.zc,function(){return a.emit("adended")});a.a.on(a.m,_.mc,function(){return a.emit("adfirstquartile")});a.a.on(a.m,_.sc,function(){return a.emit("admidpoint")});a.a.on(a.m,_.Ac,function(){return a.emit("adthirdquartile")});a.j.fd(a.G);a.j.Qe(a.C);a.a.on(a.m,_.ie,function(b){var c=b.detail;if(c&&1===c.category&&(b=(b=c.data)&&b.request,void 0!==b&&!0===(1===b.type||2===b.type||3===b.type)))if(7001===c.code){c=b.requestStartTimestamp;var d=new _.Mk(b.uris[b.uriIndex]);b={request_start:c,request_type:uC(b),
request_hostname:d.a};a.g.debug("onRequestCanceled()","Track event: requestcanceled",b);a.emit("requestcanceled",b)}else{d=b.requestStartTimestamp;var e=new _.Mk(b.uris[b.uriIndex]),f=c.data;b={request_start:d,request_type:uC(b),request_hostname:e.a,request_error:""+uC(b)+"LoadError",request_error_code:void 0===f?-1:void 0!==f.response?f.response.status:void 0!==f.status?f.status:-1,request_error_text:c.toString()};a.g.debug("onRequestFailed()","Track event: requestfailed",b);a.emit("requestfailed",
b)}})},BC=function(a){_.ki(a.a);a.j.ye(a.G);a.j.Bf(a.C)},CC=function(){this.f=this.m=null;this.a=!1;this.g=new _.J("clpp.muxdata")},DC=function(a){return!_.L.R(a)&&typeof a.init===_.oe&&typeof a.emit===_.oe},EC=function(a,b){a.trigger(new _.K(_.ie,{detail:b}))},FC=function(){},rC="manifest",sC="media",tC="encryption",vC=["x-request-id","cf-ray","x-amz-cf-id","x-akamai-request-id"];_.r=xC.prototype;_.r.initialize=function(a,b,c){this.f=a;this.o=b;this.w=c;if(!this.h){try{this.h=!0,this.w.init(this.B,zC(this))}catch(d){throw this.h=!1,BC(this),new _.N(1,9,9302,null,d);}this.emit("playerready")}this.l&&!this.A&&(a=yC(this),this.emit("videochange",a),this.l=!1);AC(this)};_.r.release=function(){this.g.debug("release()");this.l?this.g.debug(_.na):(BC(this),this.l=!0,this.o=this.f=null)};_.r.destroy=function(){this.g.debug(_.Nd);this.A?this.g.debug(_.ma):(this.A=!0,this.emit("destroy"))};
_.r.emit=function(a,b){if(null===this.w)throw new _.N(1,9,9301);this.w.emit(this.B,a,b)};_.r.Mk=function(a){this.g.debug(_.Se);var b=a.detail;a=this.m.getTrackManager();b&&b.bandwidth&&(b=b.bandwidth,(a=a.Sa())&&a.bandwidth&&(b+=a.bandwidth),this.emit("renditionchange",{video_source_bitrate:b}))};_.r.Ok=function(a){this.g.debug(_.Xe);switch(a.detail.currentState){case _.Fq:this.m.getConfiguration().autoplay&&this.emit(_.ff);break;case _.Hq:this.emit(_.rf);break;case _.Gq:this.emit(_.bf);break;case _.Aq:this.emit(_.he)}};
_.r.Nk=function(a){this.g.debug(_.Ue);if(this.h&&(a=a.detail||null))if(10003===a.code)this.emit("aderror");else if(a.severity===_.O){var b=a.message||"Player error";if(1===a.category||6100===a.code||6007===a.code)b="Download error",6100===a.code?b="Certificate request error":6007===a.code&&(b="License request error"),b=b+" castlabs-error-data:"+JSON.stringify(a.data);this.emit(_.ie,{player_error_code:a.code,player_error_message:b})}};
_.r.Qk=function(a){var b=a.request;if(b=void 0!==b&&!0===(1===b.type||2===b.type||3===b.type))b=a.status,b=void 0!==b&&200<=b&&299>=b;if(b){b=a.request;var c=a.headers,d=b.bytesLoaded,e=b.requestStartTimestamp,f=b.startTime,g=b.endTime,h=e+a.responseStartMs;a=e+a.timeMs;f=f&&g?g-f:void 0;g=new _.Mk(b.uris[b.uriIndex]);a={request_start:e,request_type:uC(b),request_hostname:g.a,request_id:wC(c),request_bytes_loaded:d,request_response_start:h,request_response_end:a,request_response_headers:c,request_media_duration:f,
request_url:_.Nk(g)};this.g.debug("onRequestCompleted()","Track event: requestcompleted",a);this.emit("requestcompleted",a)}};_.r.Pk=function(a){a.requestStartTimestamp=Date.now()};_.w(CC,_.bw);_.r=CC.prototype;_.r.onPlayerCreated=function(a){this.m=a;this.f=new xC(a,this.g)};
_.r.onContentWillLoad=function(a,b){var c=a.getConfiguration();c=_.L.kb(c.muxdata);try{var d=[];typeof c===_.Re&&(c.envKey||d.push("envKey"));if(0<d.length)throw new _.N(1,9,9300,{missingKeys:d});var e=a.getConfiguration();d=null;if(this.a=!_.L.R(e.muxdata)&&typeof e.muxdata===_.Re){var f=e.muxdata;d=DC(f.muxLib)?f.muxLib:window.mux;if(!DC(d)){this.g.warn("Mux SDK is not loaded. Will do nothing.");this.a=!1;var g=new _.N(1,9,9301);EC(a,g)}}else this.g.debug("Mux plugin is loaded but not configured. Will do nothing.");
var h=d;null!==h&&this.f.initialize(c,b,h)}catch(l){this.a=!1,EC(a,l)}};_.r.onContentLoaded=function(){};_.r.onPlayerWillDestroy=function(){this.a&&(this.f.destroy(),this.m=this.f=null)};_.r.onPlayerWillRelease=function(){this.a&&this.f.release()};_.r.id=function(){return"mux"};_.r.emit=function(a,b){try{this.f.emit(a,b)}catch(c){throw null!==this.m&&EC(this.m,c),c;}};_.I("clpp.muxdata.MuxDataPlugin",CC);CC.prototype.emit=CC.prototype.emit;CC.Id="mux";FC.prototype.create=function(){return new CC};
_.Yt(new FC);};
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));}
})();