import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var Qv="Unhandled state",Rv="accountCode key is missing in Youbora config",Sv="ad break start",Tv="ad buffering ended",Uv="ad buffering started",Vv="ad click through url: ",Wv="ad timeline changed",Xv="clpp.npaw.NpawPlugin",Yv="clpp.npaw.YouboraPlugin",Zv="content.isLive",$v="content.title",aw="is container visible",bw="youbora",cw=function(a){return a.startsWith(_.td)?"Widevine":a.startsWith(_.pd)?"FairPlay":a.match(/^com\.(microsoft|chromecast)\.playready/)?"PlayReady":a.startsWith(_.Le)?
"ClearKey":a.startsWith(_.od)?"Primetime":a},dw=function(a){a.a&&(a.g.info("Removing NPAW Plugins",a.a),a.a.removeAdsAdapter(),a.a.removeAdapter())},ew=function(a,b){if(b.namespace()===_.dd)return a.g.info("NPAW does not report when casting."),!1;const c=b.getConfiguration().youbora;return _.bh(c)?c.accountCode?_.B(window.NpawPlugin)||_.B(window.NpawPluginAdapters)?(a.g.warn("NPAW SDK not found."),b.onError(new _.I(1,9,9100)),!1):!0:(a.g.warn(Rv),b.onError(new _.I(1,9,9101)),!1):(a.g.warn("NPAW plugin is loaded but not configured. Will do nothing."),
!1)},fw=function(a,b){if(b.namespace()===_.dd)return a.g.info("Youbora does not report when casting."),!1;const c=b.getConfiguration().youbora;if(!_.bh(c))return a.g.debug("Youbora plugin is loaded but not configured. Will do nothing."),!1;if(!c.accountCode)return a.g.warn(Rv),b.onError(new _.I(1,9,9101)),!1;if(_.B(window.youbora))return a.g.warn("Youbora SDK not found."),b.onError(new _.I(1,9,9100)),!1;"6.8.59"!==youbora.VERSION&&(a.g.warn("Youbora SDK version is not supported. The supported version is 6.8.59, found "+
`version ${youbora.VERSION}. Some or all features of YouboraPlugin `+"may not work correctly."),b.onError(new _.I(1,9,9102)));return!0},gw=a=>(a=a.getConfiguration().youbora)&&a.errorFilter?a.errorFilter:b=>({code:`${b.code}`,message:b.message,severity:b.severity}),hw=(a,b,c,d)=>{b=gw(b)(a);if(!b)return c.debug("Error not sent to Youbora",a.code,a.message),null;a=10003===a.code?"ad error":_.q;b.severity===_.G?(d.fireFatalError(b.code,b.message,b.metadata),c.debug(`Reporting "fatal ${a}" to Youbora`,
b.code,b)):(d.fireError(b.code,b.message,b.metadata),c.debug(`Reporting "${a}" to Youbora`,b.code,b));return b};var iw=a=>{class b extends youbora.Adapter{constructor(c){super(c);this.m=c;this.a=new _.Nt;this.g=new _.S("clpp.npaw.YouboraAdapter");this.h=this.o=!1;this.registerListeners()}getPlayhead(){return this.getIsLive()?-1:this.m.getPosition()}getDuration(){return this.m.getDuration()}getRendition(){let c,d,e;var f=this.m.getTrackManager();f&&(f=f.na())&&(c=f.width,d=f.height,e=f.bandwidth);c&&d&&e||(f=this.j(),c=c||f.width,d=d||f.height,e=e||f.streamBandwidth);return youbora.Util.buildRenditionString(c,
d,e)}getIsLive(){return this.m.isLive()}getResource(){const c=this.m.getLoadedSource();return c&&c.url}getBitrate(){return this.j().streamBandwidth}getThroughput(){return this.j().estimatedBandwidth}getPlayrate(){return this.m.getPlaybackRate()}getFramesPerSecond(){var c=this.m.getTrackManager();return c&&(c=c.Ea())?c.frameRate:null}getPlayerName(){return _.qa}getVersion(){return"6.25.2-castlabsadapter-js"}getPlayerVersion(){return _.ea}registerListeners(){this.m&&this.a&&(this.g.debug("registering listeners"),
youbora.Util.logAllEvents(this.m),this.a.on(this.m,_.Kf,this.I.bind(this)),this.a.on(this.m,_.q,this.F.bind(this)),this.a.on(this.m,_.jg,this.H.bind(this)),this.a.on(this.m,_.ig,this.G.bind(this)),this.a.on(this.m,_.oc,this.B.bind(this)),this.a.on(this.m,_.Qc,this.C.bind(this)))}unregisterListeners(){this.g.debug(_.wb);_.Dh(this.a)}dispose(){super.dispose()}j(){return this.m.getStats()||_.Io()}w(){return!!this.m.getConfiguration().autoplay}I(c){c=c.detail;this.l("state change",c);if(c)switch(c.currentState){case _.Uo:this.w()&&
this.f();break;case _.Wo:this.f();this.A();this.fireResume();this.fireBufferEnd();break;case _.Vo:this.w()&&this.f();this.A();this.fireBufferEnd();this.firePause();break;case _.To:this.fireBufferEnd();this.fireStop();break;case _.Lo:this.fireBufferEnd();this.o&&this.plugin.getAdsAdapter()?this.firePause():this.fireStop();break;case _.Po:this.fireBufferBegin();break;default:this.g.debug(Qv,c)}}f(){this.plugin.isInitiated||(this.h=!1,this.fireInit())}A(){var c=this.m.getDrmInfo();c&&(c=cw(c.keySystem))&&
this.plugin.setOptions({"content.drm":c});this.fireJoin()}F(c){!(c=c.detail)||this.h||10003===c.code&&this.plugin.getAdsAdapter()||(c=hw(c,this.m,this.g,this))&&c.severity===_.G&&(this.h=!0)}H(){this.m.isEnded()||(this.l(_.Cf),this.f(),this.fireSeekBegin())}G(){this.l(_.Bf);this.fireSeekEnd()}B(c){this.g.debug("adsTimeline",c);this.o=(c=c.adsTimeline)&&c.Jb()}C(c){this.g.debug("Casting",c);this.fireCasted()}l(c,...d){this.g.debug(`Reporting "${c}" event to Youbora`,...d)}}return new b(a)};var jw=a=>{class b extends youbora.Adapter{constructor(c){super(c);this.m=c;this.j=this.a=null;this.f=new _.Nt;this.g=new _.S("clpp.npaw.YouboraAdsAdapter");this.registerListeners();this.l=!1}getDuration(){return this.a&&this.a.getDuration()}getRendition(){let c=null;this.a&&(c=youbora.Util.buildRenditionString(this.a.fb(),this.a.eb(),this.a.Oa()));return c}getBitrate(){return this.a&&this.a.Oa()}getPlayhead(){const c=this.m.getAdsManager();return c&&c.getPosition()}getResource(){return this.a&&this.a.getMediaUrl()}getTitle(){return this.a&&
this.a.getTitle()}getProvider(){return this.a&&this.a.getAdvertiserName()}getCreativeId(){return this.a&&this.a.getCreativeId()}getPosition(){const c=youbora.Constants.AdPosition;let d=null;if(this.a)switch(this.a.Pa()){case 0:d=c.Preroll;break;case 2:d=c.Postroll;break;case 1:d=c.Midroll}this.g.debug("Ad position",d);return d}getIsSkippable(){return this.a&&-1!==this.a.getSkipTimeOffset()}getAudioEnabled(){const c=this.m.getAdsManager();return c&&0<c.getVolume()}getExpectedBreaks(){return this.j&&
this.j.getCuePoints().length}getGivenBreaks(){return this.getExpectedBreaks()}getExpectedAds(){return this.a&&this.a.gb()}getGivenAds(){return this.getExpectedAds()}getBreaksTime(){return this.j&&this.j.getCuePoints().map(c=>-1===c?this.m.getDuration():c)}getIsFullscreen(){return this.m.getSurface().isFullscreen()}getIsVisible(){var c=this.m.getSurface().getContainer();c=youbora.Util.calculateAdViewability(c);this.g.debug(aw,c);return c}getPlayerName(){return _.qa}getVersion(){return"6.25.2-castlabsadsadapter-js"}getPlayerVersion(){return _.ea}registerListeners(){this.m&&
this.f&&(this.f.on(this.m,_.oc,this.M.bind(this)),this.f.on(this.m,_.jc,this.L.bind(this)),this.f.on(this.m,_.cc,this.I.bind(this)),this.f.on(this.m,_.ec,this.J.bind(this)),this.f.on(this.m,_.Vb,this.G.bind(this)),this.f.on(this.m,_.Wb,this.o.bind(this,1)),this.f.on(this.m,_.bc,this.o.bind(this,2)),this.f.on(this.m,_.mc,this.o.bind(this,3)),this.f.on(this.m,_.Ub,this.F.bind(this)),this.f.on(this.m,_.fc,this.K.bind(this)),this.f.on(this.m,_.q,this.H.bind(this)),this.f.on(this.m,_.Rb,this.A.bind(this)),
this.f.on(this.m,_.Sb,this.B.bind(this)),this.f.on(this.m,_.Tb,this.C.bind(this)),this.f.on(this.m,_.dc,this.w.bind(this)))}unregisterListeners(){_.Dh(this.f)}dispose(){super.dispose()}M(c){this.g.debug(Wv,c);this.j=c.adsTimeline}L(c){this.a=c.ad;this.h("ad start",this.a);this.fireStart();this.fireJoin()}G(){this.h("ad ended");this.fireStop()}I(){this.h("ad pause");this.w();this.firePause()}J(){this.h("ad resume");this.w();this.fireResume()}C(){this.l=!0;this.h(Uv);this.fireBufferBegin()}w(){this.l&&
(this.h(Tv),this.l=!1,this.fireBufferEnd())}o(c){this.h("ad quartile",c);this.fireQuartile(c)}F(){this.h("ad clicked");const c=this.a&&this.a.qb();this.g.debug(Vv,c);this.fireClick(c)}K(){this.h("ad skipped");this.fireSkip()}A(c){this.a=c.ad;this.h(Sv,this.a);this.fireBreakStart()}B(){this.h("ad break stop");this.fireBreakStop();if(this.getPosition()===youbora.Constants.AdPosition.Postroll){const c=this.plugin.getAdapter();c&&c.fireStop()}}H(c){(c=c.detail)&&10003===c.code&&hw(c,this.m,this.g,this)}h(c,
...d){this.g.debug(`Reporting "${c}" event to Youbora`,...d)}}return new b(a)};var lw=()=>{class a extends NpawPluginAdapters.video.Shaka{constructor(){super();this.f=this.h=!1;this.a=null}getPlayhead(){return this.getIsLive()?-1:this.player.getPosition()}getDuration(){return this.player.getDuration()}getRendition(){let b=null,c=null,d=null;var e=this.player.getTrackManager();e&&(e=e.na())&&(b=e.width,c=e.height,d=e.bandwidth);b&&c&&d||(e=this.j(),b=b||e.width,c=c||e.height,d=d||e.streamBandwidth);return this.getNpawUtils().buildRenditionString(b,c,d)}getIsLive(){return this.player.isLive()}getResource(){const b=
this.player.getLoadedSource();return b&&b.url}getBitrate(){return this.j().streamBandwidth}getThroughput(){return this.j().estimatedBandwidth}getPlayrate(){return this.player.getPlaybackRate()}getFramesPerSecond(){var b=this.player.getTrackManager();return b&&(b=b.Ea())?b.frameRate:null}getPlayerName(){return _.qa}getVersion(){return"castlabs-adapter-6.25.2-js"}getPlayerVersion(){return _.ea}registerListeners(){const b=this.w();this.player&&b&&(b.on(this.player,_.Kf,this.I.bind(this)),b.on(this.player,
_.q,this.F.bind(this)),b.on(this.player,_.Cf,this.H.bind(this)),b.on(this.player,_.Bf,this.G.bind(this)),b.on(this.player,_.oc,this.B.bind(this)),b.on(this.player,_.Qc,this.C.bind(this)))}unregisterListeners(){kw.debug(_.wb);_.Dh(this.w())}dispose(){this.unregisterListeners();this.f=this.h=!1;this.a=null}j(){return this.player.getStats()||_.Io()}o(){return!!this.player.getConfiguration().autoplay}I(b){b=b.detail;this.l("state change",b);if(b)switch(b.currentState){case _.Uo:this.o()&&this.fireStart();
break;case _.Wo:this.fireStart();this.A();this.fireResume();this.fireBufferEnd();break;case _.Vo:this.o()&&this.fireStart();this.A();this.fireBufferEnd();this.firePause();break;case _.To:this.fireBufferEnd();this.fireStop();break;case _.Lo:this.fireBufferEnd();this.h&&this.plugin.getAdsAdapter()?this.firePause():this.fireStop();break;case _.Po:this.fireBufferBegin();break;default:kw.debug(Qv,b)}}A(){this.fireJoin()}F(b){(b=b.detail)&&!this.f&&this.player&&10003!==b.code&&(b=hw(b,this.player,kw,this))&&
b.severity===_.G&&(this.f=!0)}H(){this.player.isEnded()||(this.l(_.Cf),this.fireSeekBegin())}w(){this.a||(this.a=new _.Nt);return this.a}G(){this.l(_.Bf);this.fireSeekEnd()}B(b){kw.debug("adsTimeline",b);this.h=(b=b.adsTimeline)&&b.Jb()}C(b){kw.debug("Casting",b);this.fireCasted()}l(b,...c){kw.debug(`Reporting "${b}" event to NPAW`,...c)}}return a},kw=new _.S("clpp.npaw.NpawAdapter");var nw=()=>{class a extends NpawPluginAdapters.ads.Ima{constructor(){super();this.j=this.h=this.l=this.a=null;this.o=!1}getDuration(){return this.a?this.a.getDuration():null}getRendition(){let b=null;this.a&&(b=this.getNpawUtils().buildRenditionString(this.a.fb(),this.a.eb(),this.a.Oa()));return b}getBitrate(){let b=null;this.a&&(b=this.a.Oa());return b}getPlayhead(){let b=null;const c=this.player.getAdsManager();c&&(b=c.getPosition());return b}getResource(){let b=null;this.a&&(b=this.a.getMediaUrl());
return b}getTitle(){let b=null;this.a&&(b=this.a.getTitle());return b}getProvider(){let b=null;this.a&&(b=this.a.getAdvertiserName());return b}getCreativeId(){let b=null;this.a&&(b=this.a.getCreativeId());return b}dispose(){this.unregisterListeners();this.j=this.h=this.a=null}getPosition(){const b=this.getNpawReference().Constants.AdPosition;let c=null;if(this.a)switch(this.a.Pa()){case 0:c=b.Preroll;break;case 2:c=b.Postroll;break;case 1:c=b.Midroll}mw.debug("Ad position",c);return c}getIsSkippable(){return this.a&&
-1!==this.a.getSkipTimeOffset()}getAudioEnabled(){const b=this.player.getAdsManager();return b&&0<b.getVolume()}getExpectedBreaks(){return this.h&&this.h.getCuePoints().length}getGivenBreaks(){return this.getExpectedBreaks()}getExpectedAds(){return this.a&&this.a.gb()}getGivenAds(){return this.getExpectedAds()}getBreaksTime(){return this.h&&this.h.getCuePoints().map(b=>-1===b?this.player.getDuration():b)}getIsFullscreen(){return this.player.getSurface().isFullscreen()}getIsVisible(){var b=this.player.getSurface().getContainer();
b=this.getNpawUtils().calculateAdViewability(b);mw.debug(aw,b);return b}getPlayerName(){return _.qa}getVersion(){return"castlabs-ads-adapter-6.25.2-js"}getPlayerVersion(){return _.ea}B(){this.j||(this.j=new _.Nt);return this.j}registerListeners(){const b=this.B();this.player&&b&&(b.on(this.player,_.oc,this.R.bind(this)),b.on(this.player,_.jc,this.P.bind(this)),b.on(this.player,_.cc,this.K.bind(this)),b.on(this.player,_.ec,this.L.bind(this)),b.on(this.player,_.Vb,this.I.bind(this)),b.on(this.player,
_.Wb,this.w.bind(this,1)),b.on(this.player,_.bc,this.w.bind(this,2)),b.on(this.player,_.mc,this.w.bind(this,3)),b.on(this.player,_.Ub,this.H.bind(this)),b.on(this.player,_.fc,this.M.bind(this)),b.on(this.player,_.q,this.J.bind(this)),b.on(this.player,_.Rb,this.C.bind(this)),b.on(this.player,_.Sb,this.F.bind(this)),b.on(this.player,_.Tb,this.G.bind(this)),b.on(this.player,_.dc,this.S.bind(this)))}unregisterListeners(){_.Dh(this.B())}R(b){mw.debug(Wv,b);this.h=b.adsTimeline}P(b){this.a=b.ad;this.f("ad start",
this.a);this.fireStart();this.fireJoin()}I(){this.f("ad ended");this.fireStop({adPlayhead:this.l})}K(){this.f("ad pause");this.A();this.firePause()}L(){this.f("ad resume");this.A();this.fireResume()}G(){this.o=!0;this.f(Uv);this.fireBufferBegin()}S(){this.l=this.getPlayhead();this.A()}A(){this.o&&(this.f(Tv),this.o=!1,this.fireBufferEnd())}w(b){this.f("ad quartile",b);this.fireQuartile(b)}H(){this.f("ad clicked");const b=this.a&&this.a.qb();mw.debug(Vv,b);this.fireClick(b)}M(){this.f("ad skipped");
this.fireSkip()}C(b){this.a=b.ad;this.f(Sv,this.a);this.fireBreakStart()}F(){this.f("ad break stop");this.fireBreakStop({adPlayhead:this.l});this.getPosition()===this.getNpawReference().Constants.AdPosition.Postroll&&this.fireStop({adPlayhead:this.l})}J(b){(b=b.detail)&&10003===b.code&&hw(b,this.player,mw,this)}f(b,...c){mw.debug(`Reporting "${b}" event to NPAW`,...c)}}return a},mw=new _.S("clpp.npaw.NpawAdsAdapter");var ow=class extends _.Pv{constructor(){super();this.a=null;this.g=new _.S(Xv);this.m=null}ff(a){dw(this);if(this.a=a)this.a.registerAdapterFromClass(this.m,lw()),this.a.registerAdsAdapterFromClass(this.m,nw())}Ch(){return this.a}getAdapter(){return this.a&&this.a.getAdapter()}getAdsAdapter(){return this.a&&this.a.getAdsAdapter()}onPlayerCreated(a){this.m=a;ew(this,a)&&(a=a.getConfiguration().youbora,this.ff(new NpawPlugin(a.accountCode)))}onContentWillLoad(a,b){if(ew(this,a)){a=a.getConfiguration();
var c=a.youbora;void 0===c[Zv]&&(c[Zv]=b.isLive);void 0===c[$v]&&(c[$v]=b.name);void 0===c.viewerId&&(c.viewerId=a.viewerId);this.a||this.ff(new NpawPlugin(c.accountCode));this.a.setAnalyticsOptions(c)}}onContentLoaded(a){const b={};(a=a.getDrmInfo())&&(a=cw(a.keySystem))&&(b["content.drm"]=a);this.g.info(_.Ee,b);this.a.setAnalyticsOptions(b)}onPlayerWillRelease(){}onPlayerWillDestroy(){dw(this);this.a.destroy()}id(){return bw}};_.z(Xv,ow);ow.prototype.getAdsAdapter=ow.prototype.getAdsAdapter;
ow.prototype.getAdapter=ow.prototype.getAdapter;ow.prototype.getNpawPlugin=ow.prototype.Ch;ow.prototype.setNpawPlugin=ow.prototype.ff;ow.Id=bw;new _.S(Xv);var pw=class extends _.Pv{constructor(){super();this.a=null;this.g=new _.S(Yv);this.m=null}gf(a){this.a&&(this.a.removeAdsAdapter(),this.a.removeAdapter());if(this.a=a)this.a.setAdapter(iw(this.m)),this.a.setAdsAdapter(jw(this.m))}getAdapter(){return this.a&&this.a.getAdapter()}getAdsAdapter(){return this.a&&this.a.getAdsAdapter()}onPlayerCreated(a){this.m=a;fw(this,a)&&(a=a.getConfiguration().youbora,this.gf(new youbora.Plugin(a)))}onContentWillLoad(a,b){if(fw(this,a)){a=a.getConfiguration();var c=
a.youbora;void 0===c[Zv]&&(c[Zv]=b.isLive);void 0===c[$v]&&(c[$v]=b.name);void 0===c.viewerId&&(c.viewerId=a.viewerId);this.a||this.gf(new youbora.Plugin(c));this.a.setOptions(c)}}onPlayerWillRelease(){}onPlayerWillDestroy(){}id(){return bw}};_.z(Yv,pw);pw.prototype.getAdsAdapter=pw.prototype.getAdsAdapter;pw.prototype.getAdapter=pw.prototype.getAdapter;pw.prototype.setYouboraPlugin=pw.prototype.gf;pw.Id=bw;_.Ir(new class{create(a){return a.youbora&&a.youbora.v7?new ow:new pw}});};f.call(g, window);