import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var gx="Registering listeners",hx="clpp.vimond.VimondPlugin",ix=function(a,b){a.m.trigger(new _.F(_.vg,{detail:b}))},jx=function(a,b,c){b&&(a.A=!0,a.f.stop());a.m.onError(new _.I(b?_.G:1,9,9201,c))},kx=function(a,b){const c=a.m.getState();if(1===b)return["str-start",_.bf];if(a.h)return[_.Rd,_.Ne];if(c===_.Lo)return[_.Rd,null];if(c===_.Mo)return[_.q,_.Ne];b=_.Ne;if(c===_.Po||c===_.Wo||a.f)b=_.bf;return["period",b]},lx=class{constructor(a,b,c,d,e){this.J=a;this.K=b;this.L=c;this.m=d;this.C=
e;this.a=new _.Nt;this.j=!0;this.Z=this.h=this.A=!1;this.B=null;this.f=new _.rk(this.w.bind(this));this.g=new _.S("clpp.vimond.VimondDispatcher");this.l=this.o=0;this.m&&this.a&&(this.g.debug(gx),this.a.on(this.m,_.Kf,this.H.bind(this)),this.a.on(this.m,_.Zf,this.I.bind(this)),this.a.on(this.m,_.Rb,this.F.bind(this)),this.a.on(this.m,_.Sb,this.G.bind(this)))}I(){this.Z||(this.Z=1<Math.abs(this.o-this.m.getPosition()));this.o=this.m.getPosition()}F(){this.g.debug("Ad break started");this.h=!0}G(){this.g.debug("Ad break stopped");
this.h=!1}H(a){const b=this;return _.x(function*(){const c=a.detail,d=c.currentState;b.g.debug(`State changed, prev: ${c.previousState} curr: ${d}`);b.A||b.h||(d!==b.B||b.Z?b.j&&d!==_.Wo||(b.Z&&[_.Vo,_.Po].includes(d)?b.g.debug("Seeking"):(b.Z&&d===_.Wo&&(b.g.debug("Seeked"),b.Z=!1),[_.Wo,_.Vo,_.Mo,_.Lo].includes(d)&&(b.B=d,yield b.w(),d===_.Lo&&b.f.stop()))):b.g.debug("Ignore transition"))})}w(){const a=this;return _.x(function*(){var b=Math.floor(Date.now()/1E3);0<a.l&&a.g.debug(`Last event was ${b-
a.l} seconds ago`);a.l=b;a.f.stop();a.f.ka(a.j?10:a.J);a.j=!1;try{var c=yield a.C.fireEvent();ix(a,c)}catch(d){b=d.code,c=d.data,[1002,1003].includes(b)?(a.g.debug("Unreachable service"),ix(a,c),jx(a,a.K,c)):1001===b?(a.g.debug("Generic service error"),ix(a,c),jx(a,a.L,c)):a.g.error(d.toString())}})}};var mx=class{constructor(a,b,c,d,e){this.l=a;this.o=c;this.h=b;this.a=d;this.j=e;this.g=new _.S("clpp.vimond.VimondService");this.f=0}fireEvent(){this.f++;const a=_.Wg(this.o);a.client.buildName=_.qa;a.client.buildVersion=_.ea;var b=a.client;var c=(c=this.a.m.getDrmInfo())?c.keySystem:"";b.drm=c;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 _.mm(c.url)).scheme||"").replace(":","");b.videoProtocol=c;b=kx(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;c=30>Math.abs(d-c);b.onLiveEdge=c;typeof b.liveResumePossible!==_.Lc&&(b.liveResumePossible=
!0)}a.progress.eventNumber=this.f;a.timestamp=(new Date).toISOString();this.g.debug("Fire an event");b=_.mj(this.l);b.method=_.cb;b.contentType="application/json";b.headers.Authorization=`Bearer ${this.h}`;b.body=_.$i(JSON.stringify(a));return this.j.fetch(b).T}qf(a){this.h=a}};var nx=class{constructor(a){this.m=a;this.a=new _.Nt;this.g=new _.S("clpp.vimond.VimondAdapter");this.f=this.h=!1;this.m&&this.a&&(this.g.debug(gx),this.a.on(this.m,_.sf,this.o.bind(this)),this.a.on(this.m,_.Rb,this.j.bind(this)),this.a.on(this.m,_.Sb,this.l.bind(this)))}getPosition(){return Math.floor(this.m.getPosition())}o(){this.h=!0}j(){this.f=!0}l(){this.f=!1}};var ox=class extends _.Pv{constructor(){super();this.a=!1;this.g=new _.S(hx);this.j=this.h=this.f=null}onPlayerCreated(){}onContentWillLoad(a){var b=a.getConfiguration();(this.a=!_.B(b.vimond)&&typeof b.vimond===_.Ce)?a.namespace()===_.dd&&(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 of["authToken","playerEventRequest"])if(!b[c]){this.g.warn(`${c} key is missing`);
a.onError(new _.I(1,9,9200));return}this.g.debug(_.ra);c=b.failIfUnreachable;typeof c!==_.Lc&&(c=!0);var d=b.failOnError;typeof d!==_.Lc&&(d=!0);this.f=new nx(a);this.h=new mx(b.playerEventRequest.uri,b.authToken,b.playerEventRequest.body,this.f,a.getNetworkEngine());this.j=new lx(b.playerEventRequest.eventInterval,c,d,a,this.h)}}onPlayerWillRelease(){if(this.a){if(this.f){var a=this.f;a.g.debug(_.wb);_.Dh(a.a)}this.j&&(a=this.j,a.g.debug(_.wb),_.Dh(a.a),a.f.stop());this.j=this.h=this.f=null}}onPlayerWillDestroy(){}id(){return"vimond"}qf(a){this.a&&
this.h&&this.h.qf(a)}};_.z(hx,ox);ox.prototype.updateAuthToken=ox.prototype.qf;ox.Id="vimond";_.Ir(new class{create(){return new ox}});};f.call(g, window);