(function(){var g={}; var _ = _ || {}
var f=function(window){var ky="Registering listeners",ly="clpp.vimond.VimondPlugin",my=function(a,b,c,d,e){this.G=a;this.H=b;this.I=c;this.m=d;this.C=e;this.a=new _.gi;this.l=!0;this.f=this.j=this.A=!1;this.B=null;this.h=new _.Xh(this.Rh.bind(this));this.g=new _.J("clpp.vimond.VimondDispatcher");this.o=this.w=0;this.m&&this.a&&(this.g.debug(ky),this.a.on(this.m,_.bg,this.ll.bind(this)),this.a.on(this.m,_.rg,this.ml.bind(this)),this.a.on(this.m,_.hc,this.jl.bind(this)),this.a.on(this.m,_.ic,this.kl.bind(this)))},ny=function(a,
b){a.m.trigger(new _.K(_.Og,{detail:b}))},oy=function(a,b,c){b&&(a.A=!0,a.h.stop());a.m.onError(new _.N(b?_.O:1,9,9201,c))},py=function(a,b,c,d,e){this.l=a;this.o=c;this.h=b;this.a=d;this.j=e;this.g=new _.J("clpp.vimond.VimondService");this.f=0},qy=function(a){this.m=a;this.a=new _.gi;this.g=new _.J("clpp.vimond.VimondAdapter");this.f=this.h=!1;this.m&&this.a&&(this.g.debug(ky),this.a.on(this.m,_.Kf,this.o.bind(this)),this.a.on(this.m,_.hc,this.j.bind(this)),this.a.on(this.m,_.ic,this.l.bind(this)))},
ry=function(a,b){var c=a.m.getState();if(1===b)return["str-start",_.rf];if(a.h)return[_.ge,_.bf];if(c===_.Aq)return[_.ge,null];if(c===_.Eq)return[_.ie,_.bf];var d=_.bf;if(c===_.yq||c===_.Hq||a.f)d=_.rf;return["period",d]},sy=function(){this.a=!1;this.g=new _.J(ly);this.j=this.h=this.f=null},ty=function(){};_.r=my.prototype;_.r.ml=function(){this.f||(this.f=1<Math.abs(this.w-this.m.getPosition()));this.w=this.m.getPosition()};_.r.jl=function(){this.g.debug("Ad break started");this.j=!0};
_.r.kl=function(){this.g.debug("Ad break stopped");this.j=!1};
_.r.ll=function(a){var b=this,c,d,e,f,g;return _.H(function(h){if(1==h.a){c=a.detail;d=_.Cq;e=c.currentState;f=c.previousState;b.g.debug("State changed, prev: "+f+" curr: "+e);if(b.A||b.j)return h["return"]();if(e===b.B&&!b.f)return b.g.debug("Ignore transition"),h["return"]();if(b.l&&e!==d.PLAYING)return h["return"]();if(b.f&&[d.PAUSED,d.BUFFERING].includes(e))return b.g.debug("Seeking"),h["return"]();b.f&&e===d.PLAYING&&(b.g.debug("Seeked"),b.f=!1);g=[d.PLAYING,d.PAUSED,d.ERROR,d.ENDED];if(!g.includes(e))return h.D(0);
b.B=e;return _.x(h,b.Rh(),3)}e===d.ENDED&&b.h.stop();_.y(h)})};
_.r.Rh=function(){var a=this,b,c,d,e,f,g;return _.H(function(h){if(1==h.a){var l=Math.floor(Date.now()/1E3);0<a.o&&a.g.debug("Last event was "+(l-a.o)+" seconds ago");a.o=l;a.h.stop();a.h.ga(a.l?10:a.G);a.l=!1;_.C(h,2);return _.x(h,a.C.fireEvent(),4)}if(2!=h.a)return b=h.f,ny(a,b),_.uh(h,0);d=c=_.E(h);e=d.code;f=d.data;g=[1002,1003];g.includes(e)?(a.g.debug("Unreachable service"),ny(a,f),oy(a,a.H,f)):1001===e?(a.g.debug("Generic service error"),ny(a,f),oy(a,a.I,f)):a.g.error(c.toString());_.y(h)})};py.prototype.fireEvent=function(){this.f++;var a=_.L.ta(this.o);a.client.buildName=_.xa;a.client.buildVersion=_.ia;var b=a.client,c=this.a.m.getDrmInfo();b.drm=c?c.keySystem:"";a.client.pageUrl=document.location.href;a.client.streamUrl=this.a.m.getLoadedSource().url;a.client.userAgent=navigator.userAgent;a.client.videoFormat=this.a.m.getLoadedSource().type||"";b=a.client;c=this.a.m.getLoadedSource();c=((new _.Mk(c.url)).scheme||"").replace(":","");b.videoProtocol=c;b=ry(this.a,this.f);a.client.playerEvent=
b[0]||"";a.client.playerState=b[1]||"";a.progress.vod&&(a.progress.vod.position=this.a.getPosition());if(b=a.progress.live){c=this.a;var d=c.m.getPresentationStartTime()||0;c=Math.floor(d+c.m.getPosition());c=(new Date(1E3*c)).toISOString();b.position=c;d=this.a;c=d.m.getPosition();d=d.m.getSeekRange().end;b.onLiveEdge=30>Math.abs(d-c);typeof b.liveResumePossible!==_.Zc&&(b.liveResumePossible=!0)}a.progress.eventNumber=this.f;a.timestamp=(new Date).toISOString();this.g.debug("Fire an event");b=_.ck(this.l);
b.method=_.sb;b.contentType="application/json";b.headers.Authorization="Bearer "+this.h;b.body=_.Q.Fd(JSON.stringify(a));return this.j.fetch(b).S};py.prototype.Xg=function(a){this.h=a};qy.prototype.getPosition=function(){return Math.floor(this.m.getPosition())};qy.prototype.o=function(){this.h=!0};qy.prototype.j=function(){this.f=!0};qy.prototype.l=function(){this.f=!1};_.w(sy,_.bw);_.r=sy.prototype;_.r.onPlayerCreated=function(){};
_.r.onContentWillLoad=function(a){var b=a.getConfiguration();(this.a=!_.L.R(b.vimond)&&typeof b.vimond===_.Re)?a.namespace()===_.sd&&(this.a=!1,this.g.info("Vimond does not report when casting.")):this.g.debug("Vimond plugin is loaded but not configured. Will do nothing.");if(this.a){b=a.getConfiguration().vimond;for(var c=_.u(["authToken","playerEventRequest"]),d=c.next();!d.done;d=c.next())if(d=d.value,!b[d]){this.g.warn(d+" key is missing");a.onError(new _.N(1,9,9200));return}this.g.debug(_.ya);
c=b.failIfUnreachable;typeof c!==_.Zc&&(c=!0);d=b.failOnError;typeof d!==_.Zc&&(d=!0);this.f=new qy(a);this.h=new py(b.playerEventRequest.uri,b.authToken,b.playerEventRequest.body,this.f,a.getNetworkEngine());this.j=new my(b.playerEventRequest.eventInterval,c,d,a,this.h)}};_.r.onPlayerWillRelease=function(){if(this.a){if(this.f){var a=this.f;a.g.debug(_.Rb);_.ki(a.a)}this.j&&(a=this.j,a.g.debug(_.Rb),_.ki(a.a),a.h.stop());this.j=this.h=this.f=null}};_.r.onPlayerWillDestroy=function(){};_.r.id=function(){return"vimond"};
_.r.Xg=function(a){this.a&&this.h&&this.h.Xg(a)};_.I(ly,sy);sy.prototype.updateAuthToken=sy.prototype.Xg;sy.Id="vimond";ty.prototype.create=function(){return new sy};_.Yt(new ty);};
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));}
})();