(function(){var g={}; var _ = _ || {}
var f=function(window){var OA="apiUrl config is missing",PA="prestoplay-web",QA=function(a,b){a.j=a.j.filter(function(c){return c!==b})},RA=function(a){var b=0>a;a=Math.abs(a);var c=a>>>0;a=Math.floor((a-c)/4294967296);a>>>=0;b&&(a=~a>>>0,c=(~c>>>0)+1,4294967295<c&&(c=0,a++,4294967295<a&&(a=0)));return[c,a]},SA=function(){this.a=[]},VA=function(a,b,c){TA(a,b,c,function(d,e){UA(d,e)})},UA=function(a,b){if(0<=b)WA(a,b);else{for(var c=b,d=0;9>d;d++)a.a.push(c&127|128),c>>=7;a.a.push(1)}},YA=function(a,b,c){TA(a,b,c,function(d,
e){if(0<=e){var f=_.u(RA(e)),g=f.next().value;f=f.next().value;XA(d,g,f)}else f=_.u(RA(e)),g=f.next().value,f=f.next().value,XA(d,g,f)})},$A=function(a,b,c){ZA(a,b,c,function(d,e){for(var f=0;f<e.length;f++){var g=e.charCodeAt(f);if(128>g)d.a.push(g);else if(2048>g)d.a.push(g>>6|192),d.a.push(g&63|128);else if(65536>g)if(55296<=g&&56319>=g&&f+1<e.length){var h=e.charCodeAt(f+1);56320<=h&&57343>=h&&(g=1024*(g-55296)+h-56320+65536,d.a.push(g>>18|240),d.a.push(g>>12&63|128),d.a.push(g>>6&63|128),d.a.push(g&
63|128),f++)}else d.a.push(g>>12|224),d.a.push(g>>6&63|128),d.a.push(g&63|128)}})},bB=function(a,b,c){ZA(a,b,c,function(d,e){aB(d,e.a())})},cB=function(a,b,c){ZA(a,b,c,function(d,e){aB(d,e)})},aB=function(a,b){a.a.push.apply(a.a,b)},TA=function(a,b,c,d){if(!(null===c||void 0===c||typeof c===_.k&&0===c||typeof c===_.eg&&0===c.length||Array.isArray(c)&&0===c.length))if(Array.isArray(c)){WA(a,b<<3|2);b=new SA;for(var e=0;e<c.length;e++)d(b,c[e]);UA(a,b.length());aB(a,b.end())}else WA(a,b<<3|0),d(a,c)},
ZA=function(a,b,c,d){if(!(null===c||void 0===c||typeof c===_.k&&0===c||typeof c===_.eg&&0===c.length||Array.isArray(c)&&0===c.length))if(Array.isArray(c))for(var e=0;e<c.length;e++){WA(a,b<<3|2);var f=new SA;d(f,c[e]);UA(a,f.length());aB(a,f.end())}else WA(a,b<<3|2),b=new SA,d(b,c),UA(a,b.length()),aB(a,b.end())},WA=function(a,b){for(;127<b;)a.a.push(b&127|128),b>>>=7;a.a.push(b)},XA=function(a,b,c){for(;0<c||127<b;)a.a.push(b&127|128),b=(b>>>7|c<<25)>>>0,c>>>=7;a.a.push(b)},dB=function(a,b,c,d){this.downloadId=
a;this.h=b;this.duration=c;this.j=d;this.f=[]},eB=function(a,b){this.f=a;this.url=b;this.downloadId=null;this.headers=[];this.size=this.duration=null},fB=function(a,b){this.h=a;this.f=b},gB=function(a){this.cause=a;this.f=this.message=this.severity=this.errorCode=null},hB=function(a,b){this.key=a;this.value=b},iB=function(){this.cause=this.severity=this.code=null},jB=function(){this.data=null},kB=function(){this.data=null;var a=new Uint8Array(16);crypto.getRandomValues(a);a[6]=a[6]&15|64;a[8]=a[8]&
63|128;this.data=a},lB=function(){this.headers=[]},mB=function(){},nB=function(a){this.j=a;this.f=this.h=this.time=this.sessionId=null},oB=function(){this.f=null;this.events=[]},pB=function(){this.f=this.h=null},qB=function(){this.f=this.h=null},rB=function(a){var b=new qB;b.h=Math.floor(a/1E3);b.f=a%1E3*1E6;return b},uB=function(a,b,c,d,e){var f=new Uint8Array([]),g=this;var h=void 0===h?2500:h;this.o=f;this.l=e;this.w=new kB;this.A=new kB;this.a=[];this.h=setInterval(function(){return sB(g)},h);
this.f=null;this.j=!1;tB(this,a,b,c,d)},vB=function(a){return _.H(function(b){switch(b.a){case 1:a.h&&(clearInterval(a.h),a.h=null);if(!a.f){b.D(2);break}return _.x(b,a.f,2);case 2:if(!(0<a.a.length)){b.D(4);break}return _.x(b,sB(a),5);case 5:a.a=[];case 4:a.j=!0,_.y(b)}})},tB=function(a,b,c,d,e){var f=new lB;f.headers=[new hB("CL-BROWSER-NAME",b),new hB("CL-BROWSER-VERSION",c),new hB("CL-OS-FAMILY",d),new hB("CL-OS-VERSION",e),new hB("CL-SDK-NAME",PA),new hB("CL-SDK-NAME",PA),new hB("CL-SDK-VERSION",
_.ia)];wB(a,f)},sB=function(a){var b,c,d,e;return _.H(function(f){if(1==f.a){if(a.j||a.f)return f["return"]();0===a.a.length&&wB(a,new mB);b=function(){};a.f=new Promise(function(g){b=g});_.th(f);c=new oB;c.f=a.o;c.events.push.apply(c.events,_.gh(a.a));d=_.gh(a.a).concat();return _.x(f,fetch(a.l,{method:_.sb,headers:{"Content-Type":"application/proto"},body:new Uint8Array(c.a())}),4)}if(2!=f.a)if(e=f.f,e.ok)a.a=a.a.filter(function(g){return!d.includes(g)});else throw Error("An error occurred while sending telemetry events to the API, status\x3d'"+
(e.status+"' statusText\x3d'"+e.statusText+"'"));_.vh(f);b();a.f=null;return _.wh(f)})},wB=function(a,b){if(!a.j){var c=new nB(a.w);c.sessionId=a.A;var d=Date.now(),e=new pB;e.h=Math.floor(d/1E3);e.f=d%1E3*1E6;c.time=e;c.h=b.getId();c.f=new Uint8Array(b.a());a.a.push(c)}},xB=function(){this.reason=this.currentState=this.previousState=null},yB=function(){this.m=null;this.f=this.l=!1;this.a=new _.gi;this.h=null;this.g=new _.J("clpp.sessions.SessionsPlugin");this.o=this.hn.bind(this);this.j=this.gn.bind(this)},
GB=function(a){switch(a){case _.tq:return zB;case _.Fq:return AB;case _.yq:return BB;case _.Hq:return CB;case _.Gq:return DB;case _.Aq:return EB;case _.Eq:return FB;default:return null}},OB=function(a,b){switch(a){case 1:return HB;case 2:return b===_.Jg?IB:b===_.Pc?JB:b===_.pj?KB:b===_.se?LB:MB;case 3:return NB;default:return MB}},PB=function(a){var b;_.H(function(c){if(1==c.a)return a.g.info("Destroy the session and stop sending events."),_.ki(a.a),a.f=!1,b=a.m.getNetworkEngine(),b.Bf(a.o),b.ye(a.j),
QA(b,a.j),a.h?_.x(c,vB(a.h),3):c.D(0);a.h=null;_.y(c)})},QB=function(a,b){a.g.debug("Sending event",b);wB(a.h,b)},RB=function(){};SA.prototype.length=function(){return this.a.length};SA.prototype.end=function(){var a=this.a;this.a=[];return a};dB.prototype.a=function(){var a=new SA;bB(a,1,this.downloadId);VA(a,2,this.h);bB(a,3,this.duration);VA(a,4,this.j);bB(a,5,this.f);return a.end()};dB.prototype.getId=function(){return 4};eB.prototype.a=function(){var a=new SA;VA(a,1,this.f);bB(a,2,this.downloadId);$A(a,3,this.url);bB(a,4,this.headers);$A(a,5,null);bB(a,6,null);bB(a,7,this.duration);YA(a,8,this.size);return a.end()};eB.prototype.getId=function(){return 2};fB.prototype.a=function(){var a=new SA;VA(a,1,this.h);cB(a,2,this.f);return a.end()};gB.prototype.a=function(){var a=new SA;VA(a,1,this.errorCode);VA(a,2,this.severity);$A(a,3,this.message);$A(a,4,this.f);bB(a,5,this.cause);return a.end()};gB.prototype.getId=function(){return 7};hB.prototype.a=function(){var a=new SA;$A(a,1,this.key);$A(a,2,this.value);return a.end()};iB.prototype.a=function(){var a=new SA;VA(a,1,this.code);VA(a,2,this.severity);bB(a,3,this.cause);return a.end()};iB.prototype.getId=function(){return 12};jB.prototype.a=function(){var a=new SA;cB(a,1,this.data);return a.end()};_.w(kB,jB);kB.prototype.toString=function(){for(var a=[],b=0;256>b;++b)a.push((b+256).toString(16).slice(1));return a[this.data[0]]+a[this.data[1]]+a[this.data[2]]+a[this.data[3]]+"-"+a[this.data[4]]+a[this.data[5]]+"-"+a[this.data[6]]+a[this.data[7]]+"-"+a[this.data[8]]+a[this.data[9]]+"-"+a[this.data[10]]+a[this.data[11]]+a[this.data[12]]+a[this.data[13]]+a[this.data[14]]+a[this.data[15]]};lB.prototype.a=function(){var a=new SA;bB(a,1,this.headers);return a.end()};lB.prototype.getId=function(){return 1};mB.prototype.a=function(){return(new SA).end()};mB.prototype.getId=function(){return 6};nB.prototype.a=function(){var a=new SA;bB(a,1,this.j);bB(a,2,this.sessionId);bB(a,3,this.time);YA(a,4,null);$A(a,5,null);VA(a,6,this.h);cB(a,7,this.f);return a.end()};oB.prototype.a=function(){var a=new SA;cB(a,1,this.f);bB(a,2,this.events);return a.end()};pB.prototype.a=function(){var a=new SA;YA(a,1,this.h);VA(a,2,this.f);return a.end()};qB.prototype.a=function(){var a=new SA;YA(a,1,this.h);VA(a,2,this.f);return a.end()};xB.prototype.a=function(){var a=new SA;VA(a,1,this.previousState);VA(a,2,this.currentState);VA(a,3,this.reason);bB(a,4,null);bB(a,5,null);bB(a,6,null);return a.end()};xB.prototype.getId=function(){return 5};_.w(yB,_.bw);_.r=yB.prototype;_.r.onPlayerCreated=function(a){this.m=a};
_.r.onContentWillLoad=function(a){var b=a.getConfiguration().sessions;(b=!(!b||typeof b!==_.Re))||this.g.debug("Sessions plugin is loaded but not configured. Will do nothing.");if(this.l=b)b=a.getConfiguration().sessions,b.apiUrl?(this.g.debug(_.ya),this.g.info("Create a session and start sending events."),a=_.sk(),this.h=new uB(a.browser,a.browserVersion.name,a.os,a.osVersion.name,b.apiUrl),this.a.on(this.m,_.bg,this.Vk.bind(this)),this.a.on(this.m,_.Uf,this.Uk.bind(this)),this.a.on(this.m,_.Tf,
this.Tk.bind(this)),this.a.on(this.m,_.ie,this.Sk.bind(this)),a=this.m.getNetworkEngine(),a.Qe(this.o),a.fd(this.j),a.j.push(this.j)):(this.g.warn(OA),a.onError(new _.N(1,9,15E3,OA)))};_.r.onPlayerWillRelease=function(){PB(this)};_.r.id=function(){return"sessions"};_.r.Vk=function(a){if(!this.f){a=a.detail;var b=a.currentState,c=new xB;c.previousState=GB(a.previousState);c.currentState=GB(b);QB(this,c)}};
_.r.Uk=function(){if(!this.f){var a=new xB;a.previousState=GB(this.m.getState());a.currentState=SB;QB(this,a);this.f=!0}};_.r.Tk=function(){if(this.f){var a=new xB;a.previousState=SB;a.currentState=GB(this.m.getState());QB(this,a);this.f=!1}};_.r.Sk=function(a){a=a.detail;var b=new iB;b=new gB(new fB(b.getId(),new Uint8Array(b.a())));b.errorCode=a.code;b.message=a.message;b.f=a.stack;b.severity=a.severity===_.O?TB:UB;QB(this,b)};
_.r.hn=function(a){var b=new kB;a.downloadId=b;var c=new eB(OB(a.type,a.contentType),a.uris[0]);c.downloadId=b;c.headers=Object.keys(a.headers).map(function(d){return new hB(d,a.headers[d])});QB(this,c)};_.r.gn=function(a){var b=a.request.downloadId;b?(b=new dB(b,a.data.byteLength,rB(a.timeMs||0),a.status||-1),b.f=Object.keys(a.headers).map(function(c){return new hB(c,a.headers[c])}),QB(this,b)):this.g.warn("Download ID is missing on download completed event.")};RB.prototype.create=function(){return new yB};
_.Yt(new RB);var UB=1,TB=2;var zB=0,AB=2,FB=3,SB=5,BB=6,CB=8,DB=10,EB=11;var HB=0,IB=1,JB=2,KB=3,LB=4,NB=5,MB=9;};
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));}
})();