import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var hV="Ad Error",iV="onAdBreakStarted()",jV="onAdBreakStopped()",kV=function(a){var b=_.Tk();let c=Conviva.Constants.DeviceType.DESKTOP,d=Conviva.Constants.DeviceCategory.WEB;const e=b.os;b=b.osVersion.name;let f="";_.Fk()&&(f="Apple");_.Ek()?(f="Google",c=Conviva.Constants.DeviceType.SETTOP,d=Conviva.Constants.DeviceCategory.CHROMECAST):_.Gk()?(c=Conviva.Constants.DeviceType.MOBILE,/(android)/i.test(navigator.userAgent)?d=Conviva.Constants.DeviceCategory.ANDROID_DEVICE:_.Fk()&&(d=Conviva.Constants.DeviceCategory.APPLE_DEVICE)):
_.yk()||_.vk()||_.uk("Hisense")?(c=Conviva.Constants.DeviceType.SMARTTV,d=Conviva.Constants.DeviceCategory.SMART_TV,_.yk()?(b="",f="LG",d=Conviva.Constants.DeviceCategory.LG_TV):_.vk()?(f="Samsung",d=Conviva.Constants.DeviceCategory.SAMSUNG_TV):_.uk("Hisense")&&(b="",f="Hisense")):_.uk("Xbox One")&&(f="Microsoft",c=Conviva.Constants.DeviceType.CONSOLE,d=Conviva.Constants.DeviceCategory.XBOX);const g=a.deviceMetadata||{},h=(k,l)=>{k in g||!l||(g[k]=l)};h(Conviva.Constants.DeviceMetadata.TYPE,a.deviceType||
c);h(Conviva.Constants.DeviceMetadata.OS_NAME,e);h(Conviva.Constants.DeviceMetadata.OS_VERSION,b);h(Conviva.Constants.DeviceMetadata.CATEGORY,a.deviceCategory||d);h(Conviva.Constants.DeviceMetadata.BRAND,a.deviceBrand||f);return g},lV=function(a){return a?Conviva.Constants.StreamType.LIVE:Conviva.Constants.StreamType.VOD},mV=function(a){return 0===a?"Pre-roll":-1===a?"Post-roll":"Mid-roll"},oV=function(a,b,c,d){const e={};e[Conviva.Constants.PLAYER_NAME]=c;e[Conviva.Constants.VIEWER_ID]=b;e[Conviva.Constants.IS_LIVE]=
lV(!!d);e[Conviva.Constants.ASSET_NAME]=hV;a&&(e[Conviva.Constants.ASSET_NAME]=a.getTitle(),e[Conviva.Constants.STREAM_URL]=a.getMediaUrl(),e[Conviva.Constants.DURATION]=a.getDuration(),e["c3.ad.id"]=nV(a.getId()),e["c3.ad.creativeId"]=nV(a.getCreativeId()),e["c3.ad.system"]=nV(a.getAdSystem()),e["c3.ad.mediaFileApiFramework"]=nV(a.getApiFramework()),e["c3.ad.advertiser"]=nV(a.getAdvertiserName()),e["c3.ad.position"]=mV(a.getPodIndex()),e["c3.ad.technology"]=0===a.ub()?Conviva.Constants.AdType.CLIENT_SIDE:
Conviva.Constants.AdType.SERVER_SIDE,e["c3.ad.adManagerName"]=nV(a.ob()),e["c3.ad.adManagerVersion"]=nV(a.pb()),e["c3.ad.advertiserCategory"]=nV(null),e["c3.ad.advertiserId"]=nV(null),e["c3.ad.breakId"]=nV(null),e["c3.ad.campaignName"]=nV(null),e["c3.ad.category"]=nV(null),e["c3.ad.classification"]=nV(null),e["c3.ad.creativeName"]=nV(null),e["c3.ad.sequence"]=nV(a.sb()),e["c3.ad.sessionStartEvent"]=nV(null),e["c3.ad.unitName"]=nV(null),e["c3.ad.dayPart"]=nV(null),b=a.getWrapperAdIds().slice(-1)[0]||
a.getId(),c=a.getWrapperAdSystems().slice(-1)[0]||a.getAdSystem(),a=a.getWrapperCreativeIds().slice(-1)[0]||a.getCreativeId(),e["c3.ad.firstAdId"]=nV(b),e["c3.ad.firstAdSystem"]=nV(c),e["c3.ad.firstCreativeId"]=nV(a));return e},nV=function(a){return a?""+a:"NA"},sV=function(a){a.f.on(a.m,_.Rb,a.C.bind(a));a.f.on(a.m,_.Sb,a.F.bind(a));a.f.on(a.m,_.jc,a.L.bind(a));a.f.on(a.m,_.dc,a.l.bind(a));a.f.on(a.m,_.cc,a.l.bind(a));a.f.on(a.m,_.ec,a.l.bind(a));a.f.on(a.m,_.Tb,a.l.bind(a));a.f.on(a.m,_.lc,a.M.bind(a));
a.f.on(a.m,_.fc,a.K.bind(a));a.f.on(a.m,_.Ub,a.G.bind(a));a.f.on(a.m,_.$b,a.I.bind(a));a.f.on(a.m,_.ac,a.J.bind(a));a.f.on(a.m,_.Wb,a.H.bind(a));a.f.on(a.m,_.bc,a.S.bind(a));a.f.on(a.m,_.mc,a.P.bind(a));a.f.on(a.m,_.q,b=>{var c=b.detail;if(10003===c.code&&(a.g.debug("onAdError()"),!a.h)){b=Conviva.Constants.ErrorSeverity;switch(c.data.errorType){case 0:c="Ad Load Error";break;case 1:c="Ad Play Error";break;default:c=hV}null===a.a&&pV(a,null);a.a.reportAdError(c,b.FATAL);a.h=!0;a.g.debug("Ad Playback Failure");
qV(a,rV,c)}})},qV=function(a,b,c=hV){if(a.a){a.a.reportAdMetric(Conviva.Constants.Playback.PLAYER_STATE,Conviva.Constants.PlayerState.STOPPED);switch(b){case rV:a.a.reportAdFailed(c,oV(null,a.B,a.A));break;case tV:a.a.reportAdSkipped();break;default:a.a.reportAdEnded()}a.a.release();a.a=null;a.j=!1}},pV=function(a,b){if(!a.o){a.h=!1;try{if(a.a=Conviva.Analytics.buildAdAnalytics(a.R()),b){const c=oV(b,a.B,a.A,a.m.isLive()),d=String(b.pb()),e={};e[Conviva.Constants.FRAMEWORK_NAME]=b.ob();e[Conviva.Constants.FRAMEWORK_VERSION]=
d;a.a.setAdPlayerInfo(e);a.a.reportAdStarted(c)}}catch(c){a.g.error("Could not create ad analytics session",c)}}},uV=function(a,b){const c={};c[Conviva.Constants.LOG_LEVEL]=Conviva.Constants.LogLevel.DEBUG;b.serviceUrl&&(a.g.warn("Touchstone URL is set. Do not set this in production!"),c[Conviva.Constants.GATEWAY_URL]=b.serviceUrl.replace(/\/$/,""));Conviva.Analytics.init(b.customerKey,null,c);Conviva.Analytics.setDeviceMetadata(kV(b));b.connectionType&&Conviva.Analytics.reportDeviceMetric(Conviva.Constants.Network.CONNECTION_TYPE,
b.connectionType);a.a=Conviva.Analytics.buildVideoAnalytics();a.o=!1;b={};b[Conviva.Constants.FRAMEWORK_NAME]=_.qa;b[Conviva.Constants.FRAMEWORK_VERSION]=_.ea;a.a.setPlayerInfo(b)},vV=function(a){return a.m.getConfiguration().autoplay||!1},xV=function(a){if(!a.l)if(a.C)a.g.warn("Current session still active. No-op.");else{var b=a.m.getLoadedSource()||a.K,c=a.m.getConfiguration().conviva||null,d=c&&c.viewerId||"N/A",e=c&&c.defaultResource||"N/A";a.g.debug(a.m.getConfiguration().source);var f={},g=
new _.mm(b.url);b&&(f[Conviva.Constants.ASSET_NAME]=b.name||"N/A",f[Conviva.Constants.STREAM_URL]=_.Kj(g));f[Conviva.Constants.PLAYER_NAME]=c.playerName||_.qa;f[Conviva.Constants.VIEWER_ID]=d;f[Conviva.Constants.DEFAULT_RESOURCE]=e;if(c&&!_.B(c.customTags))for(const h in c.customTags)f[h]=c.customTags[h];a.a.reportPlaybackRequested(f);a.a.setCallback(()=>{a.g.debug("reportMiscellaneousMetrics()");if(wV(a)){var h=1E3*a.m.getPosition();a.a.reportPlaybackMetric(Conviva.Constants.Playback.PLAY_HEAD_TIME,
h);if(h=a.m.getStats()){h=h.decodedFrames;const k=h-a.H;a.H=h;isFinite(k)&&(a.g.debug("Current FPS",k),a.a.reportPlaybackMetric(Conviva.Constants.Playback.RENDERED_FRAMERATE,k))}}});a.C=!0;a.h=!0;a.I=!1;0<a.j.length&&(a.g.debug("Report deferred events"),a.j.forEach(h=>{h.Wf(h.args)}));a.j=[]}},yV=function(a){if(!a.l&&a.a){const b=lV(a.m.isLive()),c={};c[Conviva.Constants.IS_LIVE]=b;c[Conviva.Constants.DURATION]=a.m.getDuration();a.a.setContentInfo(c)}},wV=function(a){return null!==a.a&&a.C},zV=function(a){a.g.debug("terminateSession()");
a.a&&(a.a.reportPlaybackMetric(Conviva.Constants.Playback.PLAYER_STATE,Conviva.Constants.PlayerState.STOPPED),a.a.reportPlaybackEnded(),a.a.release(),Conviva.Analytics.release(),a.o=!0,a.C=!1,a.A=!1,a.h=!1,a.w=null,a.B=!1,a.P=0,a.J=!1,a.j=[],a.H=0)},BV=function(a,b){const c=b.getConfiguration();a.a=!_.B(c.conviva)&&typeof c.conviva===_.Ce;a.a?"undefined"===typeof window.Conviva?(a.g.warn("Conviva SDK is not loaded. Will do nothing."),a.a=!1,a=new _.I(1,9,9E3),AV(b,a)):b.namespace()===_.dd&&(a.a=!1,
a.g.debug("Conviva does not report when casting.")):a.g.debug("Conviva plugin is loaded but not configured. Will do nothing.")},CV=function(a){const b=[];typeof a===_.Ce&&(a.customerKey||b.push("customerKey"),a.viewerId||b.push("viewerId"));if(0<b.length)throw new _.I(1,9,9001,{missingKeys:b});},AV=function(a,b){a.trigger(new _.F(_.q,{detail:b}))};var EV=class{constructor(a,b){this.m=a;this.R=b;this.B="";this.A=_.qa;this.g=new _.S("clpp.conviva.ad");this.f=new _.Nt;this.a=null;this.h=this.o=this.w=this.j=!1}initialize(a){this.g.debug("Initialize Ad Insights");this.h=this.w=!1;this.B=a.viewerId;this.A=a.playerName||_.qa;sV(this)}release(){this.g.debug("Release Ad Insights");this.w?this.g.debug(_.ia):(_.Dh(this.f),this.a&&qV(this,DV),this.f.release(),this.w=!0,this.j=this.h=!1)}destroy(){this.g.debug(_.Ad);this.o?this.g.debug(_.ha):this.o=!0}C(){this.g.debug(iV)}F(){this.g.debug(jV)}L(a){this.g.debug("onAdStarted()");
a=a.ad;this.j||(this.g.warn("Ad load event was not triggered. This will have incidence on VSF"),pV(this,a));this.j=!1;this.a.reportAdMetric(Conviva.Constants.Playback.PLAYER_STATE,Conviva.Constants.PlayerState.PLAYING);this.a.reportAdMetric(Conviva.Constants.Playback.RESOLUTION,a.fb(),a.eb());this.a.reportAdMetric(Conviva.Constants.Playback.BITRATE,a.Oa())}l(a){this.g.debug("onAdStateChanged()");if(this.a){const b=c=>{this.a.reportAdMetric(Conviva.Constants.Playback.PLAYER_STATE,c)};switch(a.type){case _.dc:case _.ec:b(Conviva.Constants.PlayerState.PLAYING);
break;case _.cc:b(Conviva.Constants.PlayerState.PAUSED);break;case _.Tb:b(Conviva.Constants.PlayerState.BUFFERING)}}}M(){this.g.debug("onAdStopped()");this.a&&!this.h&&qV(this,DV)}K(){this.g.debug("onAdSkipped()");this.a&&qV(this,tV)}G(){this.g.debug("onAdClicked()");this.a&&this.a.reportAdPlayerEvent("AdClicked")}I(){this.g.debug("onAdImpression()");if(this.a){const a=Conviva.Constants.Events;this.a.reportAdPlayerEvent(a.AD_IMPRESSION_START);this.a.reportAdPlayerEvent(a.AD_IMPRESSION_END)}}J(a){this.g.debug("onAdLoaded()");
const b=a.ad,c=()=>{this.j=!0;pV(this,b)};if(-1!==b.getPodIndex()||this.m.getPosition()>=this.m.getDuration()-5)c();else this.f.on(this.m,_.Zf,()=>{this.m.getPosition()>=this.m.getDuration()-5&&(this.f.off(this.m,_.Zf),c())})}H(){this.g.debug("onAdFirstQuartile()");this.a&&this.a.reportAdPlayerEvent(Conviva.Constants.Events.AD_FIRST_QUARTILE)}S(){this.g.debug("onAdMidPoint()");this.a&&this.a.reportAdPlayerEvent(Conviva.Constants.Events.AD_MID_QUARTILE)}P(){this.g.debug("onAdThirdQuartile()");this.a&&
this.a.reportAdPlayerEvent(Conviva.Constants.Events.AD_THIRD_QUARTILE)}},tV=0,DV=1,rV=2;var FV=class{constructor(a,b){this.m=a;this.f=new _.Nt;this.a=null;this.o=!1;this.G=!0;this.B=this.h=this.A=this.C=this.l=!1;this.P=0;this.J=!1;this.w=null;this.I=!1;this.g=b;this.K=this.F=null;this.j=[];this.H=0}initialize(a,b,c){this.l||(this.g.debug("Initialize conviva"),this.G=!1,this.F=_.Xg(b),this.K=c,this.m=a,uV(this,this.F),this.f.on(this.m,_.Re,this.ia.bind(this)),this.f.on(this.m,_.Kf,this.ba.bind(this)),this.f.on(this.m,_.Kc,this.L.bind(this)),this.f.on(this.m,_.jg,this.X.bind(this)),this.f.on(this.m,
_.ig,this.V.bind(this)),this.f.on(this.m,_.Rb,this.R.bind(this)),this.f.on(this.m,_.Sb,this.S.bind(this)),this.f.on(this.m,_.oc,this.da.bind(this)),this.f.on(this.m,_.Jc,this.fa.bind(this)),this.f.on(this.m,_.q,this.M.bind(this)),vV(this)&&(this.g.debug("Start a new session: A new video starts in autoplay."),xV(this)))}release(){this.g.debug("Release conviva");this.G?this.g.debug(_.ia):(_.Dh(this.f),wV(this)||this.o||!vV(this)||this.a&&this.a.reportPlaybackFailed("Exit Before Video Start"),wV(this)&&
zV(this),this.a=null,this.G=!0)}destroy(){this.g.debug(_.Ad);this.l?this.g.debug(_.ha):this.l=!0}reportAppEvent(a,b){let c=!1;try{Conviva.Analytics.reportAppEvent(a,b),c=!0}catch(d){this.g.debug("Report app event error",d),c=!1}return c}ia(){this.g.debug("onPlayRequest()");wV(this)||vV(this)?wV(this)&&this.A&&!this.h&&(this.g.debug("Resuming VST monitoring ..."),wV(this)&&!this.h&&(this.a.reportPlaybackEvent(Conviva.Constants.Events.USER_WAIT_ENDED),this.h=!0),this.A=!1):(this.g.debug("Creating conviva session. On Play Requested / No autoplay"),
xV(this))}ba(a){this.g.debug(_.Ie);const b=c=>{if(this.o&&(this.g.debug("Creating conviva session (On Seek / Replay)"),uV(this,this.F),xV(this),yV(this),wV(this))){var d=this.m.getTrackManager();d=d.na()||d.rb();d.width&&d.height&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.RESOLUTION,d.width,d.height);d.bandwidth&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.BITRATE,d.bandwidth/1E3)}wV(this)&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.PLAYER_STATE,c)};switch(a.detail.currentState){case _.Wo:b(Conviva.Constants.PlayerState.PLAYING);
break;case _.Vo:b(Conviva.Constants.PlayerState.PAUSED);break;case _.Po:b(Conviva.Constants.PlayerState.BUFFERING);break;case _.Lo:this.g.debug("onVideoEnded()"),wV(this)&&(this.w&&this.w.Jb()?(this.g.debug("Waiting for postroll Ad before terminating session"),this.J=!0):zV(this))}}L(a){this.g.debug(_.De);if(wV(this)){if(a=a.detail,typeof a.width===_.t&&typeof a.height===_.t&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.RESOLUTION,a.width,a.height),a.bandwidth&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.BITRATE,
a.bandwidth/1E3),(a=a.rendition)&&a.track&&(a=a.track)&&a.frameRate){const b={};b[Conviva.Constants.ENCODED_FRAMERATE]=a.frameRate;this.a.setContentInfo(b)}}else this.j.push({Wf:this.L.bind(this),args:a})}X(){this.g.debug("onSeeking()");wV(this)&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.SEEK_STARTED)}V(){this.g.debug("onSeeked()");wV(this)&&this.a.reportPlaybackMetric(Conviva.Constants.Playback.SEEK_ENDED)}da(a){this.g.debug("onAdsTimelineChanged()");if(a=a.adsTimeline)this.w=a}R(a){this.g.debug(iV);
var b=a.ad;a=0===b.Pa();const c=mV(b.getPodIndex());wV(this)||vV(this)||!a||xV(this);if(wV(this)){a=0===b.ub()?Conviva.Constants.AdType.CLIENT_SIDE:Conviva.Constants.AdType.SERVER_SIDE;let d=0;const e={};1===b.gb()&&(d=b.getDuration());e[Conviva.Constants.POD_DURATION]=d;e[Conviva.Constants.POD_INDEX]=++this.P;e[Conviva.Constants.POD_POSITION]=c;b=Conviva.Constants.AdPlayer;b=a!==Conviva.Constants.AdType.CLIENT_SIDE||_.Ek()?b.CONTENT:b.SEPARATE;this.a.reportAdBreakStarted(a,b,e);this.B=!0}else this.g.debug("Bug: should already have a valid session")}S(){this.g.debug(jV);
wV(this)&&this.B&&(this.a.reportAdBreakEnded(),this.B=!1,this.J&&zV(this))}M(a){this.g.debug(_.Fe);if(this.o&&this.I)this.g.debug("Session ended in VPF; ignoring subsequent errors");else{var b=a.detail||null,c=b&&b.message||"Player error",d=Conviva.Constants.ErrorSeverity.WARNING;b&&b.severity&&b.severity===_.G&&(d=Conviva.Constants.ErrorSeverity.FATAL,wV(this)||xV(this));wV(this)?(this.g.debug("Report error",c,d),this.a.reportPlaybackError(c,d),d===Conviva.Constants.ErrorSeverity.FATAL&&(this.g.debug("Video Playback Failure"),
this.I=!0,zV(this))):this.j.push({Wf:this.M.bind(this),args:a})}}fa(){this.g.debug("onAutoPlayBlocked()");wV(this)&&(this.g.debug("Auto-play blocked. Pausing VST monitoring."),this.A=!0,wV(this)&&this.h&&(this.a.reportPlaybackEvent(Conviva.Constants.Events.USER_WAIT_STARTED),this.h=!1))}};var GV=class{constructor(){this.h=this.f=null;this.a=!1;this.g=new _.S("clpp.conviva")}onPlayerCreated(a){this.f=new FV(a,this.g)}onContentWillLoad(a,b){BV(this,a);if(this.a){var c=a.getConfiguration();c=_.Xg(c.conviva||{});try{CV(c);const d=c.enableAdInsights||!1;this.f.initialize(a,c,b);d&&(this.h=new EV(a,()=>this.f.a),this.h.initialize(c))}catch(d){d instanceof _.I?AV(a,d):AV(a,new _.I(1,9,9002,d,d))}}}onContentLoaded(){this.a&&yV(this.f)}onPlayerWillDestroy(){this.a&&(this.a=!1,this.f.destroy(),
this.f=null,this.h&&(this.h.destroy(),this.h=null))}onPlayerWillRelease(){this.a&&(this.f.release(),this.h&&this.h.release())}id(){return"conviva"}reportAppEvent(a,b){return this.f?this.f.reportAppEvent(a,b):!1}};_.z("clpp.conviva.ConvivaPlugin",GV);GV.prototype.reportAppEvent=GV.prototype.reportAppEvent;GV.Id="conviva";_.Ir(new class{create(){return new GV}});};f.call(g, window);