@vkontakte/videoplayer-statistics 1.0.30 → 1.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es2015.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- "use strict";var h=require("@vkontakte/videoplayer-shared/es2015.cjs.js"),d=require("@vkontakte/videoplayer-core/es2015.cjs.js"),ho=require("lodash/debounce.js");function w(e,r,t,n){function o(a){return a instanceof t?a:new t(function(i){i(a)})}return new(t||(t=Promise))(function(a,i){function v(c){try{s(n.next(c))}catch(l){i(l)}}function u(c){try{s(n.throw(c))}catch(l){i(l)}}function s(c){c.done?a(c.value):o(c.value).then(v,u)}s((n=n.apply(e,r||[])).next())})}var Hr=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},ue=function(e){return e&&e.Math==Math&&e},g=ue(typeof globalThis=="object"&&globalThis)||ue(typeof window=="object"&&window)||ue(typeof self=="object"&&self)||ue(typeof Hr=="object"&&Hr)||function(){return this}()||Function("return this")(),T=function(e){try{return!!e()}catch(r){return!0}},po=T,Ae=!po(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),yo=Ae,Xt=Function.prototype,qr=Xt.apply,Kr=Xt.call,Zt=typeof Reflect=="object"&&Reflect.apply||(yo?Kr.bind(qr):function(){return Kr.apply(qr,arguments)}),en=Ae,rn=Function.prototype,dr=rn.call,go=en&&rn.bind.bind(dr,dr),O=en?go:function(e){return function(){return dr.apply(e,arguments)}},tn=O,bo=tn({}.toString),$o=tn("".slice),Ne=function(e){return $o(bo(e),8,-1)},mo=Ne,Eo=O,nn=function(e){if(mo(e)==="Function")return Eo(e)},hr=typeof document=="object"&&document.all,So=typeof hr=="undefined"&&hr!==void 0,on={all:hr,IS_HTMLDDA:So},an=on,To=an.all,y=an.IS_HTMLDDA?function(e){return typeof e=="function"||e===To}:function(e){return typeof e=="function"},Ir={},Oo=T,J=!Oo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),_o=Ae,le=Function.prototype.call,_=_o?le.bind(le):function(){return le.apply(le,arguments)},sn={},cn={}.propertyIsEnumerable,un=Object.getOwnPropertyDescriptor,Po=un&&!cn.call({1:2},1);sn.f=Po?function(r){var t=un(this,r);return!!t&&t.enumerable}:cn;var ln=function(e,r){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:r}},Io=O,wo=T,Ro=Ne,xe=Object,Co=Io("".split),Ao=wo(function(){return!xe("z").propertyIsEnumerable(0)})?function(e){return Ro(e)=="String"?Co(e,""):xe(e)}:xe,De=function(e){return e==null},No=De,Do=TypeError,vn=function(e){if(No(e))throw Do("Can't call method on "+e);return e},jo=Ao,Lo=vn,Mo=function(e){return jo(Lo(e))},Qr=y,fn=on,Uo=fn.all,M=fn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:Qr(e)||e===Uo}:function(e){return typeof e=="object"?e!==null:Qr(e)},dn={},Ve=dn,He=g,ko=y,Wr=function(e){return ko(e)?e:void 0},C=function(e,r){return arguments.length<2?Wr(Ve[e])||Wr(He[e]):Ve[e]&&Ve[e][r]||He[e]&&He[e][r]},Bo=O,wr=Bo({}.isPrototypeOf),je=typeof navigator!="undefined"&&String(navigator.userAgent)||"",hn=g,qe=je,Gr=hn.process,zr=hn.Deno,Yr=Gr&&Gr.versions||zr&&zr.version,Jr=Yr&&Yr.v8,E,Se;Jr&&(E=Jr.split("."),Se=E[0]>0&&E[0]<4?1:+(E[0]+E[1]));!Se&&qe&&(E=qe.match(/Edge\/(\d+)/),(!E||E[1]>=74)&&(E=qe.match(/Chrome\/(\d+)/),E&&(Se=+E[1])));var pn=Se,Xr=pn,Fo=T,yn=!!Object.getOwnPropertySymbols&&!Fo(function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&Xr&&Xr<41}),xo=yn,gn=xo&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Vo=C,Ho=y,qo=wr,Ko=gn,Qo=Object,bn=Ko?function(e){return typeof e=="symbol"}:function(e){var r=Vo("Symbol");return Ho(r)&&qo(r.prototype,Qo(e))},Wo=String,Le=function(e){try{return Wo(e)}catch(r){return"Object"}},Go=y,zo=Le,Yo=TypeError,U=function(e){if(Go(e))return e;throw Yo(zo(e)+" is not a function")},Jo=U,Xo=De,Rr=function(e,r){var t=e[r];return Xo(t)?void 0:Jo(t)},Ke=_,Qe=y,We=M,Zo=TypeError,ea=function(e,r){var t,n;if(r==="string"&&Qe(t=e.toString)&&!We(n=Ke(t,e))||Qe(t=e.valueOf)&&!We(n=Ke(t,e))||r!=="string"&&Qe(t=e.toString)&&!We(n=Ke(t,e)))return n;throw Zo("Can't convert object to primitive value")},Te={},ra={get exports(){return Te},set exports(e){Te=e}},ie=!0,Zr=g,ta=Object.defineProperty,na=function(e,r){try{ta(Zr,e,{value:r,configurable:!0,writable:!0})}catch(t){Zr[e]=r}return r},oa=g,aa=na,et="__core-js_shared__",ia=oa[et]||aa(et,{}),Cr=ia,rt=Cr;(ra.exports=function(e,r){return rt[e]||(rt[e]=r!==void 0?r:{})})("versions",[]).push({version:"3.27.2",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.27.2/LICENSE",source:"https://github.com/zloirock/core-js"});var sa=vn,ca=Object,ua=function(e){return ca(sa(e))},la=O,va=ua,fa=la({}.hasOwnProperty),X=Object.hasOwn||function(r,t){return fa(va(r),t)},da=O,ha=0,pa=Math.random(),ya=da(1 .toString),$n=function(e){return"Symbol("+(e===void 0?"":e)+")_"+ya(++ha+pa,36)},ga=g,ba=Te,tt=X,$a=$n,ma=yn,Ea=gn,Q=ga.Symbol,Ge=ba("wks"),Sa=Ea?Q.for||Q:Q&&Q.withoutSetter||$a,P=function(e){return tt(Ge,e)||(Ge[e]=ma&&tt(Q,e)?Q[e]:Sa("Symbol."+e)),Ge[e]},Ta=_,nt=M,ot=bn,Oa=Rr,_a=ea,Pa=P,Ia=TypeError,wa=Pa("toPrimitive"),Ra=function(e,r){if(!nt(e)||ot(e))return e;var t=Oa(e,wa),n;if(t){if(r===void 0&&(r="default"),n=Ta(t,e,r),!nt(n)||ot(n))return n;throw Ia("Can't convert object to primitive value")}return r===void 0&&(r="number"),_a(e,r)},Ca=Ra,Aa=bn,mn=function(e){var r=Ca(e,"string");return Aa(r)?r:r+""},Na=g,at=M,pr=Na.document,Da=at(pr)&&at(pr.createElement),En=function(e){return Da?pr.createElement(e):{}},ja=J,La=T,Ma=En,Sn=!ja&&!La(function(){return Object.defineProperty(Ma("div"),"a",{get:function(){return 7}}).a!=7}),Ua=J,ka=_,Ba=sn,Fa=ln,xa=Mo,Va=mn,Ha=X,qa=Sn,it=Object.getOwnPropertyDescriptor;Ir.f=Ua?it:function(r,t){if(r=xa(r),t=Va(t),qa)try{return it(r,t)}catch(n){}if(Ha(r,t))return Fa(!ka(Ba.f,r,t),r[t])};var Ka=T,Qa=y,Wa=/#|\.prototype\./,se=function(e,r){var t=za[Ga(e)];return t==Ja?!0:t==Ya?!1:Qa(r)?Ka(r):!!r},Ga=se.normalize=function(e){return String(e).replace(Wa,".").toLowerCase()},za=se.data={},Ya=se.NATIVE="N",Ja=se.POLYFILL="P",Tn=se,st=nn,Xa=U,Za=Ae,ei=st(st.bind),Me=function(e,r){return Xa(e),r===void 0?e:Za?ei(e,r):function(){return e.apply(r,arguments)}},Ue={},ri=J,ti=T,ni=ri&&ti(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),oi=M,ai=String,ii=TypeError,k=function(e){if(oi(e))return e;throw ii(ai(e)+" is not an object")},si=J,ci=Sn,ui=ni,ve=k,ct=mn,li=TypeError,ze=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,Ye="enumerable",Je="configurable",Xe="writable";Ue.f=si?ui?function(r,t,n){if(ve(r),t=ct(t),ve(n),typeof r=="function"&&t==="prototype"&&"value"in n&&Xe in n&&!n[Xe]){var o=vi(r,t);o&&o[Xe]&&(r[t]=n.value,n={configurable:Je in n?n[Je]:o[Je],enumerable:Ye in n?n[Ye]:o[Ye],writable:!1})}return ze(r,t,n)}:ze:function(r,t,n){if(ve(r),t=ct(t),ve(n),ci)try{return ze(r,t,n)}catch(o){}if("get"in n||"set"in n)throw li("Accessors not supported");return"value"in n&&(r[t]=n.value),r};var fi=J,di=Ue,hi=ln,ke=fi?function(e,r,t){return di.f(e,r,hi(1,t))}:function(e,r,t){return e[r]=t,e},fe=g,pi=Zt,yi=nn,gi=y,bi=Ir.f,$i=Tn,x=dn,mi=Me,V=ke,ut=X,Ei=function(e){var r=function(t,n,o){if(this instanceof r){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,o)}return pi(e,this,arguments)};return r.prototype=e.prototype,r},B=function(e,r){var t=e.target,n=e.global,o=e.stat,a=e.proto,i=n?fe:o?fe[t]:(fe[t]||{}).prototype,v=n?x:x[t]||V(x,t,{})[t],u=v.prototype,s,c,l,p,f,m,A,I,F;for(p in r)s=$i(n?p:t+(o?".":"#")+p,e.forced),c=!s&&i&&ut(i,p),m=v[p],c&&(e.dontCallGetSet?(F=bi(i,p),A=F&&F.value):A=i[p]),f=c&&A?A:r[p],!(c&&typeof m==typeof f)&&(e.bind&&c?I=mi(f,fe):e.wrap&&c?I=Ei(f):a&&gi(f)?I=yi(f):I=f,(e.sham||f&&f.sham||m&&m.sham)&&V(I,"sham",!0),V(v,p,I),a&&(l=t+"Prototype",ut(x,l)||V(x,l,{}),V(x[l],p,f),e.real&&u&&(s||!u[p])&&V(u,p,f)))},Si=Ne,Be=typeof process!="undefined"&&Si(process)=="process",Ti=ke,Ar=function(e,r,t,n){return n&&n.enumerable?e[r]=t:Ti(e,r,t),e},Oi=y,_i=String,Pi=TypeError,Ii=function(e){if(typeof e=="object"||Oi(e))return e;throw Pi("Can't set "+_i(e)+" as a prototype")},wi=O,Ri=k,Ci=Ii,Ai=Object.setPrototypeOf||("__proto__"in{}?function(){var e=!1,r={},t;try{t=wi(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set),t(r,[]),e=r instanceof Array}catch(n){}return function(o,a){return Ri(o),Ci(a),e?t(o,a):o.__proto__=a,o}}():void 0),Ni=P,Di=Ni("toStringTag"),On={};On[Di]="z";var Nr=String(On)==="[object z]",ji=Nr,Li=y,$e=Ne,Mi=P,Ui=Mi("toStringTag"),ki=Object,Bi=$e(function(){return arguments}())=="Arguments",Fi=function(e,r){try{return e[r]}catch(t){}},Dr=ji?$e:function(e){var r,t,n;return e===void 0?"Undefined":e===null?"Null":typeof(t=Fi(r=ki(e),Ui))=="string"?t:Bi?$e(r):(n=$e(r))=="Object"&&Li(r.callee)?"Arguments":n},xi=Nr,Vi=Dr,Hi=xi?{}.toString:function(){return"[object "+Vi(this)+"]"},qi=Nr,Ki=Ue.f,Qi=ke,Wi=X,Gi=Hi,zi=P,lt=zi("toStringTag"),Yi=function(e,r,t,n){if(e){var o=t?e:e.prototype;Wi(o,lt)||Ki(o,lt,{configurable:!0,value:r}),n&&!qi&&Qi(o,"toString",Gi)}},Ji=C,Xi=Ue,Zi=P,es=J,vt=Zi("species"),rs=function(e){var r=Ji(e),t=Xi.f;es&&r&&!r[vt]&&t(r,vt,{configurable:!0,get:function(){return this}})},ts=wr,ns=TypeError,os=function(e,r){if(ts(r,e))return e;throw ns("Incorrect invocation")},as=O,is=y,yr=Cr,ss=as(Function.toString);is(yr.inspectSource)||(yr.inspectSource=function(e){return ss(e)});var _n=yr.inspectSource,cs=O,us=T,Pn=y,ls=Dr,vs=C,fs=_n,In=function(){},ds=[],wn=vs("Reflect","construct"),jr=/^\s*(?:class|function)\b/,hs=cs(jr.exec),ps=!jr.exec(In),re=function(r){if(!Pn(r))return!1;try{return wn(In,ds,r),!0}catch(t){return!1}},Rn=function(r){if(!Pn(r))return!1;switch(ls(r)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ps||!!hs(jr,fs(r))}catch(t){return!0}};Rn.sham=!0;var ys=!wn||us(function(){var e;return re(re.call)||!re(Object)||!re(function(){e=!0})||e})?Rn:re,gs=ys,bs=Le,$s=TypeError,ms=function(e){if(gs(e))return e;throw $s(bs(e)+" is not a constructor")},ft=k,Es=ms,Ss=De,Ts=P,Os=Ts("species"),Cn=function(e,r){var t=ft(e).constructor,n;return t===void 0||Ss(n=ft(t)[Os])?r:Es(n)},_s=C,Ps=_s("document","documentElement"),Is=O,ws=Is([].slice),Rs=TypeError,Cs=function(e,r){if(e<r)throw Rs("Not enough arguments");return e},As=je,An=/(?:ipad|iphone|ipod).*applewebkit/i.test(As),b=g,Ns=Zt,Ds=Me,dt=y,js=X,Nn=T,ht=Ps,Ls=ws,pt=En,Ms=Cs,Us=An,ks=Be,gr=b.setImmediate,br=b.clearImmediate,Bs=b.process,Ze=b.Dispatch,Fs=b.Function,yt=b.MessageChannel,xs=b.String,er=0,te={},gt="onreadystatechange",oe,N,rr,tr;Nn(function(){oe=b.location});var Lr=function(e){if(js(te,e)){var r=te[e];delete te[e],r()}},nr=function(e){return function(){Lr(e)}},bt=function(e){Lr(e.data)},$t=function(e){b.postMessage(xs(e),oe.protocol+"//"+oe.host)};(!gr||!br)&&(gr=function(r){Ms(arguments.length,1);var t=dt(r)?r:Fs(r),n=Ls(arguments,1);return te[++er]=function(){Ns(t,void 0,n)},N(er),er},br=function(r){delete te[r]},ks?N=function(e){Bs.nextTick(nr(e))}:Ze&&Ze.now?N=function(e){Ze.now(nr(e))}:yt&&!Us?(rr=new yt,tr=rr.port2,rr.port1.onmessage=bt,N=Ds(tr.postMessage,tr)):b.addEventListener&&dt(b.postMessage)&&!b.importScripts&&oe&&oe.protocol!=="file:"&&!Nn($t)?(N=$t,b.addEventListener("message",bt,!1)):gt in pt("script")?N=function(e){ht.appendChild(pt("script"))[gt]=function(){ht.removeChild(this),Lr(e)}}:N=function(e){setTimeout(nr(e),0)});var Dn={set:gr,clear:br},jn=function(){this.head=null,this.tail=null};jn.prototype={add:function(e){var r={item:e,next:null},t=this.tail;t?t.next=r:this.head=r,this.tail=r},get:function(){var e=this.head;if(e){var r=this.head=e.next;return r===null&&(this.tail=null),e.item}}};var Ln=jn,Vs=je,Hs=/ipad|iphone|ipod/i.test(Vs)&&typeof Pebble!="undefined",qs=je,Ks=/web0s(?!.*chrome)/i.test(qs),L=g,mt=Me,Qs=Ir.f,or=Dn.set,Ws=Ln,Gs=An,zs=Hs,Ys=Ks,ar=Be,Et=L.MutationObserver||L.WebKitMutationObserver,St=L.document,Tt=L.process,de=L.Promise,Ot=Qs(L,"queueMicrotask"),$r=Ot&&Ot.value,H,ir,sr,he,_t;if(!$r){var pe=new Ws,ye=function(){var e,r;for(ar&&(e=Tt.domain)&&e.exit();r=pe.get();)try{r()}catch(t){throw pe.head&&H(),t}e&&e.enter()};!Gs&&!ar&&!Ys&&Et&&St?(ir=!0,sr=St.createTextNode(""),new Et(ye).observe(sr,{characterData:!0}),H=function(){sr.data=ir=!ir}):!zs&&de&&de.resolve?(he=de.resolve(void 0),he.constructor=de,_t=mt(he.then,he),H=function(){_t(ye)}):ar?H=function(){Tt.nextTick(ye)}:(or=mt(or,L),H=function(){or(ye)}),$r=function(e){pe.head||H(),pe.add(e)}}var Js=$r,Xs=function(e,r){try{arguments.length==1?console.error(e):console.error(e,r)}catch(t){}},Mr=function(e){try{return{error:!1,value:e()}}catch(r){return{error:!0,value:r}}},Zs=g,ec=y,Pt=Zs.WeakMap,rc=ec(Pt)&&/native code/.test(String(Pt)),tc=Te,nc=$n,It=tc("keys"),oc=function(e){return It[e]||(It[e]=nc(e))},ac={},ic=rc,Mn=g,sc=M,cc=ke,cr=X,ur=Cr,uc=oc,lc=ac,wt="Object already initialized",mr=Mn.TypeError,vc=Mn.WeakMap,Oe,ae,_e,fc=function(e){return _e(e)?ae(e):Oe(e,{})},dc=function(e){return function(r){var t;if(!sc(r)||(t=ae(r)).type!==e)throw mr("Incompatible receiver, "+e+" required");return t}};if(ic||ur.state){var S=ur.state||(ur.state=new vc);S.get=S.get,S.has=S.has,S.set=S.set,Oe=function(e,r){if(S.has(e))throw mr(wt);return r.facade=e,S.set(e,r),r},ae=function(e){return S.get(e)||{}},_e=function(e){return S.has(e)}}else{var q=uc("state");lc[q]=!0,Oe=function(e,r){if(cr(e,q))throw mr(wt);return r.facade=e,cc(e,q,r),r},ae=function(e){return cr(e,q)?e[q]:{}},_e=function(e){return cr(e,q)}}var hc={set:Oe,get:ae,has:_e,enforce:fc,getterFor:dc},pc=g,Z=pc.Promise,Un=typeof Deno=="object"&&Deno&&typeof Deno.version=="object",yc=Un,gc=Be,bc=!yc&&!gc&&typeof window=="object"&&typeof document=="object",$c=g,ne=Z,mc=y,Ec=Tn,Sc=_n,Tc=P,Oc=bc,_c=Un,Pc=ie,lr=pn,Rt=ne&&ne.prototype,Ic=Tc("species"),Er=!1,kn=mc($c.PromiseRejectionEvent),wc=Ec("Promise",function(){var e=Sc(ne),r=e!==String(ne);if(!r&&lr===66||Pc&&!(Rt.catch&&Rt.finally))return!0;if(!lr||lr<51||!/native code/.test(e)){var t=new ne(function(a){a(1)}),n=function(a){a(function(){},function(){})},o=t.constructor={};if(o[Ic]=n,Er=t.then(function(){})instanceof n,!Er)return!0}return!r&&(Oc||_c)&&!kn}),ce={CONSTRUCTOR:wc,REJECTION_EVENT:kn,SUBCLASSING:Er},ee={},Ct=U,Rc=TypeError,Cc=function(e){var r,t;this.promise=new e(function(n,o){if(r!==void 0||t!==void 0)throw Rc("Bad Promise constructor");r=n,t=o}),this.resolve=Ct(r),this.reject=Ct(t)};ee.f=function(e){return new Cc(e)};var Ac=B,Nc=ie,Pe=Be,R=g,z=_,At=Ar,Nt=Ai,Dc=Yi,jc=rs,Lc=U,me=y,Mc=M,Uc=os,kc=Cn,Bn=Dn.set,Ur=Js,Bc=Xs,Fc=Mr,xc=Ln,Fn=hc,Ie=Z,kr=ce,xn=ee,Fe="Promise",Vn=kr.CONSTRUCTOR,Vc=kr.REJECTION_EVENT,Hc=kr.SUBCLASSING,vr=Fn.getterFor(Fe),qc=Fn.set,K=Ie&&Ie.prototype,D=Ie,ge=K,Hn=R.TypeError,Sr=R.document,Br=R.process,Tr=xn.f,Kc=Tr,Qc=!!(Sr&&Sr.createEvent&&R.dispatchEvent),qn="unhandledrejection",Wc="rejectionhandled",Dt=0,Kn=1,Gc=2,Fr=1,Qn=2,be,jt,zc,Lt,Wn=function(e){var r;return Mc(e)&&me(r=e.then)?r:!1},Gn=function(e,r){var t=r.value,n=r.state==Kn,o=n?e.ok:e.fail,a=e.resolve,i=e.reject,v=e.domain,u,s,c;try{o?(n||(r.rejection===Qn&&Jc(r),r.rejection=Fr),o===!0?u=t:(v&&v.enter(),u=o(t),v&&(v.exit(),c=!0)),u===e.promise?i(Hn("Promise-chain cycle")):(s=Wn(u))?z(s,u,a,i):a(u)):i(t)}catch(l){v&&!c&&v.exit(),i(l)}},zn=function(e,r){e.notified||(e.notified=!0,Ur(function(){for(var t=e.reactions,n;n=t.get();)Gn(n,e);e.notified=!1,r&&!e.rejection&&Yc(e)}))},Yn=function(e,r,t){var n,o;Qc?(n=Sr.createEvent("Event"),n.promise=r,n.reason=t,n.initEvent(e,!1,!0),R.dispatchEvent(n)):n={promise:r,reason:t},!Vc&&(o=R["on"+e])?o(n):e===qn&&Bc("Unhandled promise rejection",t)},Yc=function(e){z(Bn,R,function(){var r=e.facade,t=e.value,n=Mt(e),o;if(n&&(o=Fc(function(){Pe?Br.emit("unhandledRejection",t,r):Yn(qn,r,t)}),e.rejection=Pe||Mt(e)?Qn:Fr,o.error))throw o.value})},Mt=function(e){return e.rejection!==Fr&&!e.parent},Jc=function(e){z(Bn,R,function(){var r=e.facade;Pe?Br.emit("rejectionHandled",r):Yn(Wc,r,e.value)})},W=function(e,r,t){return function(n){e(r,n,t)}},G=function(e,r,t){e.done||(e.done=!0,t&&(e=t),e.value=r,e.state=Gc,zn(e,!0))},Or=function(e,r,t){if(!e.done){e.done=!0,t&&(e=t);try{if(e.facade===r)throw Hn("Promise can't be resolved itself");var n=Wn(r);n?Ur(function(){var o={done:!1};try{z(n,r,W(Or,o,e),W(G,o,e))}catch(a){G(o,a,e)}}):(e.value=r,e.state=Kn,zn(e,!1))}catch(o){G({done:!1},o,e)}}};if(Vn&&(D=function(r){Uc(this,ge),Lc(r),z(be,this);var t=vr(this);try{r(W(Or,t),W(G,t))}catch(n){G(t,n)}},ge=D.prototype,be=function(r){qc(this,{type:Fe,done:!1,notified:!1,parent:!1,reactions:new xc,rejection:!1,state:Dt,value:void 0})},be.prototype=At(ge,"then",function(r,t){var n=vr(this),o=Tr(kc(this,D));return n.parent=!0,o.ok=me(r)?r:!0,o.fail=me(t)&&t,o.domain=Pe?Br.domain:void 0,n.state==Dt?n.reactions.add(o):Ur(function(){Gn(o,n)}),o.promise}),jt=function(){var e=new be,r=vr(e);this.promise=e,this.resolve=W(Or,r),this.reject=W(G,r)},xn.f=Tr=function(e){return e===D||e===zc?new jt(e):Kc(e)},!Nc&&me(Ie)&&K!==Object.prototype)){Lt=K.then,Hc||At(K,"then",function(r,t){var n=this;return new D(function(o,a){z(Lt,n,o,a)}).then(r,t)},{unsafe:!0});try{delete K.constructor}catch(e){}Nt&&Nt(K,ge)}Ac({global:!0,constructor:!0,wrap:!0,forced:Vn},{Promise:D});Dc(D,Fe,!1,!0);jc(Fe);var Jn={},Xc=P,Zc=Jn,eu=Xc("iterator"),ru=Array.prototype,tu=function(e){return e!==void 0&&(Zc.Array===e||ru[eu]===e)},nu=Math.ceil,ou=Math.floor,au=Math.trunc||function(r){var t=+r;return(t>0?ou:nu)(t)},iu=au,su=function(e){var r=+e;return r!==r||r===0?0:iu(r)},cu=su,uu=Math.min,lu=function(e){return e>0?uu(cu(e),9007199254740991):0},vu=lu,fu=function(e){return vu(e.length)},du=Dr,Ut=Rr,hu=De,pu=Jn,yu=P,gu=yu("iterator"),Xn=function(e){if(!hu(e))return Ut(e,gu)||Ut(e,"@@iterator")||pu[du(e)]},bu=_,$u=U,mu=k,Eu=Le,Su=Xn,Tu=TypeError,Ou=function(e,r){var t=arguments.length<2?Su(e):r;if($u(t))return mu(bu(t,e));throw Tu(Eu(e)+" is not iterable")},_u=_,kt=k,Pu=Rr,Iu=function(e,r,t){var n,o;kt(e);try{if(n=Pu(e,"return"),!n){if(r==="throw")throw t;return t}n=_u(n,e)}catch(a){o=!0,n=a}if(r==="throw")throw t;if(o)throw n;return kt(n),t},wu=Me,Ru=_,Cu=k,Au=Le,Nu=tu,Du=fu,Bt=wr,ju=Ou,Lu=Xn,Ft=Iu,Mu=TypeError,Ee=function(e,r){this.stopped=e,this.result=r},xt=Ee.prototype,Zn=function(e,r,t){var n=t&&t.that,o=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),i=!!(t&&t.IS_ITERATOR),v=!!(t&&t.INTERRUPTED),u=wu(r,n),s,c,l,p,f,m,A,I=function($){return s&&Ft(s,"normal",$),new Ee(!0,$)},F=function($){return o?(Cu($),v?u($[0],$[1],I):u($[0],$[1])):v?u($,I):u($)};if(a)s=e.iterator;else if(i)s=e;else{if(c=Lu(e),!c)throw Mu(Au(e)+" is not iterable");if(Nu(c)){for(l=0,p=Du(e);p>l;l++)if(f=F(e[l]),f&&Bt(xt,f))return f;return new Ee(!1)}s=ju(e,c)}for(m=a?e.next:s.next;!(A=Ru(m,s)).done;){try{f=F(A.value)}catch($){Ft(s,"throw",$)}if(typeof f=="object"&&f&&Bt(xt,f))return f}return new Ee(!1)},Uu=P,eo=Uu("iterator"),ro=!1;try{var ku=0,Vt={next:function(){return{done:!!ku++}},return:function(){ro=!0}};Vt[eo]=function(){return this},Array.from(Vt,function(){throw 2})}catch(e){}var Bu=function(e,r){if(!r&&!ro)return!1;var t=!1;try{var n={};n[eo]=function(){return{next:function(){return{done:t=!0}}}},e(n)}catch(o){}return t},Fu=Z,xu=Bu,Vu=ce.CONSTRUCTOR,to=Vu||!xu(function(e){Fu.all(e).then(void 0,function(){})}),Hu=B,qu=_,Ku=U,Qu=ee,Wu=Mr,Gu=Zn,zu=to;Hu({target:"Promise",stat:!0,forced:zu},{all:function(r){var t=this,n=Qu.f(t),o=n.resolve,a=n.reject,i=Wu(function(){var v=Ku(t.resolve),u=[],s=0,c=1;Gu(r,function(l){var p=s++,f=!1;c++,qu(v,t,l).then(function(m){f||(f=!0,u[p]=m,--c||o(u))},a)}),--c||o(u)});return i.error&&a(i.value),n.promise}});var Yu=B,Ju=ie,Xu=ce.CONSTRUCTOR,_r=Z,Zu=C,el=y,rl=Ar,Ht=_r&&_r.prototype;Yu({target:"Promise",proto:!0,forced:Xu,real:!0},{catch:function(e){return this.then(void 0,e)}});if(!Ju&&el(_r)){var qt=Zu("Promise").prototype.catch;Ht.catch!==qt&&rl(Ht,"catch",qt,{unsafe:!0})}var tl=B,nl=_,ol=U,al=ee,il=Mr,sl=Zn,cl=to;tl({target:"Promise",stat:!0,forced:cl},{race:function(r){var t=this,n=al.f(t),o=n.reject,a=il(function(){var i=ol(t.resolve);sl(r,function(v){nl(i,t,v).then(n.resolve,o)})});return a.error&&o(a.value),n.promise}});var ul=B,ll=_,vl=ee,fl=ce.CONSTRUCTOR;ul({target:"Promise",stat:!0,forced:fl},{reject:function(r){var t=vl.f(this);return ll(t.reject,void 0,r),t.promise}});var dl=k,hl=M,pl=ee,no=function(e,r){if(dl(e),hl(r)&&r.constructor===e)return r;var t=pl.f(e),n=t.resolve;return n(r),t.promise},yl=B,gl=C,oo=ie,bl=Z,ao=ce.CONSTRUCTOR,$l=no,ml=gl("Promise"),El=oo&&!ao;yl({target:"Promise",stat:!0,forced:oo||ao},{resolve:function(r){return $l(El&&this===ml?bl:this,r)}});var Sl=B,Tl=ie,we=Z,Ol=T,io=C,so=y,_l=Cn,Kt=no,Pl=Ar,Pr=we&&we.prototype,Il=!!we&&Ol(function(){Pr.finally.call({then:function(){}},function(){})});Sl({target:"Promise",proto:!0,real:!0,forced:Il},{finally:function(e){var r=_l(this,io("Promise")),t=so(e);return this.then(t?function(n){return Kt(r,e()).then(function(){return n})}:e,t?function(n){return Kt(r,e()).then(function(){throw n})}:e)}});if(!Tl&&so(we)){var Qt=io("Promise").prototype.finally;Pr.finally!==Qt&&Pl(Pr,"finally",Qt,{unsafe:!0})}var wl=C,Rl=wl,Cl=Rl,Al=Cl("Promise","finally"),Nl=Al,Dl=Nl,jl=Dl,Ll=jl,fr=Ll;const xr="_one-stat_",Y=(()=>{try{const e=Date.now().toString(),r=window.localStorage;r.setItem(e,e);const t=r.getItem(e)===e;return r.removeItem(e),t?r:null}catch(e){return null}})();function Ml(e){const r=Y?Y.getItem(xr+e):null;if(r===null)return null;try{return JSON.parse(r)}catch(t){return null}}function Ul(e,r){try{Y&&Y.setItem(xr+e,JSON.stringify(r))}catch(t){}}function kl(e){Y&&Y.removeItem(xr+e)}var Wt={get(e){return Ml(e)||null},set(e,r){Ul(e,r)},remove(e){kl(e)}};function Bl(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=new Array(36);let t=0,n,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?r[o]="-":o===14?r[o]="4":(t<=2&&(t=33554432+Math.random()*16777216|0),n=t&15,t=t>>4,r[o]=e[o===19?n&3|8:n]);return r.join("")}exports.ApiEnv=void 0;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(e){e.Q144P="144",e.Q240P="240",e.Q360P="360",e.Q480P="480",e.Q720P="720",e.Q1080P="1080",e.Q1440P="1440",e.Q2160P="2160",e.Q4320P="4320",e.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(e){e.CHROMECAST="chromecast",e.APPLE_TV="appletv",e.PIP="pip",e.HEADPHONES="externalHeadphones",e.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.RTMP="rtmp",e.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var Re;(function(e){e.AUTO="auto",e.MANUAL=""})(Re||(Re={}));exports.ConnectionType=void 0;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var Ce;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(Ce||(Ce={}));const Gt="1.0.30",Fl="@vkontakte/videoplayer-statistics",xl="CIOPGQJGDIHBABABA",co={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},Vl={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var j;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(j||(j={}));class Hl{constructor(r){this.consequentAuthErrors=0,this.authorized$=new h.ValueSubject(!1),this.params=r;const t=Wt.get("uuid");t?this.uuid=String(t):(this.uuid=Bl(),Wt.set("uuid",this.uuid))}authorize(r){return w(this,void 0,void 0,function*(){return this.authToken=r!=null?r:yield this.refreshAuthToken(),this._authorizeWithBackoff()})}logBeacon(r){const t="log.externalLog",n=this.createLogParams(r),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(t,n,o)||this.logRequest(r)}logRequest(r){var t;return w(this,void 0,void 0,function*(){const n="log.externalLog",o=this.createLogParams(r),a=(t=this.sessionKey)!==null&&t!==void 0?t:yield this._authorizeWithBackoff();if(!a)return;const i=(v,u=this.params.requestRetryCount)=>w(this,void 0,void 0,function*(){try{return yield this.params.apiTransport.sendRequest(n,o,a)}catch(s){if(!s||!("error_code"in s)){this.params.error$.next({id:"logRequestUnknown",category:h.ErrorCategory.NETWORK,message:`Unknown ${n} error`,thrown:s});return}const c=s==null?void 0:s.error_code;switch(c){case j.PARAM_SESSION_EXPIRED:case j.PARAM_SESSION_KEY:case j.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;case j.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:h.ErrorCategory.EXTERNAL_API,message:`${n} error`,data:s});return}}}});return i(r)})}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return w(this,void 0,void 0,function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=fr(this.params.refreshAuthToken(),()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise})}createLogParams(r){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${Fl}:${Gt}`,platform:"WEB",items:r.map(t=>Object.assign(Object.assign({},t),{time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const r=h.getExponentialDelay(this.consequentAuthErrors,Vl);return new Promise(t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{fr(this._authorize().then(t).catch(n=>this.params.error$.next({id:"AuthorizeBackoff",category:h.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:n})),()=>this.backoffTimeoutId=0)},r))})}_authorize(){return w(this,void 0,void 0,function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const r="auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:Gt.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=fr(this.params.apiTransport.sendRequest(r,t).then(n=>{var o;return(!n||!n.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:h.ErrorCategory.EXTERNAL_API,message:"No session key",data:n}),this.sessionKey=(o=n==null?void 0:n.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(n=>w(this,void 0,void 0,function*(){this.sessionKey=void 0;const o=n==null?void 0:n.error_code;switch(o){case j.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:h.ErrorCategory.EXTERNAL_API,message:"authorize error",data:n}):this.params.error$.next({id:"AuthorizeUnknown",category:h.ErrorCategory.NETWORK,message:"authorize error",thrown:n})})),()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise})}}class zt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(r,t,n){r in this.listeners||(this.listeners[r]=[]),this.listeners[r].push({callback:t,options:n})}removeEventListener(r,t){if(!(r in this.listeners))return;const n=this.listeners[r];for(let o=0,a=n.length;o<a;o++)if(n[o].callback===t){n.splice(o,1);return}}dispatchEvent(r){if(!(r.type in this.listeners))return;const n=this.listeners[r.type].slice();for(let o=0,a=n.length;o<a;o++){const i=n[o];try{i.callback.call(this,r)}catch(v){Promise.resolve().then(()=>{throw v})}i.options&&i.options.once&&this.removeEventListener(r.type,i.callback)}return!r.defaultPrevented}}class uo extends zt{constructor(){super(),this.listeners||zt.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(r){r.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,r)),super.dispatchEvent(r)}}class ql{constructor(){Object.defineProperty(this,"signal",{value:new uo,writable:!0,configurable:!0})}abort(r){let t;try{t=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=r;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(o){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(ql.prototype[Symbol.toStringTag]="AbortController",uo.prototype[Symbol.toStringTag]="AbortSignal");function lo(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Kl(e){typeof e=="function"&&(e={fetch:e});const{fetch:r,Request:t=r.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=e;if(!lo({fetch:r,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:r,Request:a};let a=t;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(s,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const p=new t(s,c);return l&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),p},a.prototype=t.prototype);const i=r;return{fetch:(u,s)=>{const c=a&&a.prototype.isPrototypeOf(u)?u.signal:s?s.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(f){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const p=new Promise((f,m)=>{c.addEventListener("abort",()=>m(l),{once:!0})});return s&&s.signal&&delete s.signal,Promise.race([p,i(u,s)])}return i(u,s)},Request:a}}const Vr=lo({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),vo=Vr?Kl({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Yt=Vr?vo.fetch:window.fetch;Vr?vo.Request:window.Request;class Ql{constructor(r){this.params=r,this.apiKey=r.apiKey,this.apiEnv=r.apiEnv,this.apiBaseUrl=r.apiBaseUrl,this.timeSynchronisation=r.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var r;return w(this,void 0,void 0,function*(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=yield(yield Yt(t,{method:"GET",mode:"cors",cache:"no-cache"})).json(),a=(r=o==null?void 0:o.Answer[0])===null||r===void 0?void 0:r.data;if(!a)throw new Error("Wrong DNS response");return a}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:h.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),co[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}})}sendBeacon(r,t,n){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:r,queryParams:t,sessionKey:n}),a=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,a)}catch(i){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:h.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:i,data:{method:r,params:t}})}return!1}sendRequest(r,t,n){return w(this,void 0,void 0,function*(){const o=h.now(),a=i=>{if(i instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(i.message)){this.params.error$.next({id:"Network",category:h.ErrorCategory.NETWORK,message:"Request failed",thrown:i});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:h.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:i,data:{method:r,params:t,sessionKey:n,time:h.now()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Yt(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:r,queryParams:t,sessionKey:n})}).then(i=>{var v;const u=Number(i.headers.get("content-length"))===0,s=new Date((v=i.headers.get("date"))!==null&&v!==void 0?v:"").getTime(),c=h.now()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,c),!u)return i.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,a)},a)})}_prepareQueryParams(r){const t=new URLSearchParams({format:"JSON",method:r.method,application_key:this.apiKey});return r.sessionKey!==void 0&&t.append("session_key",r.sessionKey),Object.entries(r.queryParams).forEach(([n,o])=>t.append(n,typeof o=="string"?o:JSON.stringify(o))),t}}const fo=3e3,Wl=fo*5;class Gl{constructor(r){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=ho(()=>{var t;try{this.flush()}catch(n){this.error$.next({id:"LoggerError",category:h.ErrorCategory.WTF,message:(t=String(n))!==null&&t!==void 0?t:"Unknown logger error",thrown:n})}},fo,{maxWait:Wl}),this.api=r.api,this.error$=r.error$,this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()})}log(r){this.requestQueue.push(r),this.isPaused||this.debouncedFlush()}flush(r=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(r?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):r||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class zl{constructor(r){this.offset=void 0,this.offset=r}getOffset(){var r;return(r=this.offset)!==null&&r!==void 0?r:0}setOffset(r){this.offset=r}now(){var r;return Date.now()+((r=this.offset)!==null&&r!==void 0?r:0)}date(r=new Date){var t;return r.setTime(r.getTime()+((t=this.offset)!==null&&t!==void 0?t:0)),r}addServerTime(r,t){const n=Date.now(),o=r-n-t/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const Jt=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,"0"),Yl=e=>e&&{[d.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[d.VideoQuality.Q_144P]:exports.Quality.Q144P,[d.VideoQuality.Q_240P]:exports.Quality.Q240P,[d.VideoQuality.Q_360P]:exports.Quality.Q360P,[d.VideoQuality.Q_480P]:exports.Quality.Q480P,[d.VideoQuality.Q_720P]:exports.Quality.Q720P,[d.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[d.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[d.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[d.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[e],Jl=e=>e&&{[d.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[d.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[d.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[e],Xl=e=>{if(e!==void 0)switch(e){case d.VideoFormat.MPEG:return exports.ContentType.MP4;case d.VideoFormat.DASH:case d.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case d.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case d.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case d.VideoFormat.DASH_WEBM:case d.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case d.VideoFormat.HLS:case d.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case d.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case d.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return h.assertNever(e)}};class Zl{constructor(r,t){var n;this.subscription=new h.Subscription,this.timeSynchronisation=new zl,this.vsid=Jt(),this.fieldBlacklist=[],this.statContext=r,this.config=Object.assign(Object.assign({},(n=t.config)!==null&&n!==void 0?n:{}),{requestRetryCount:1});const o=new h.Subject;this.experimental={error$:o};const a=new Ql({apiKey:xl,apiBaseUrl:co[t.apiEnv],apiEnv:t.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new Hl({apiTransport:a,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new Gl({api:this.api,error$:o}),this.subscription.add(h.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(r){this.statContext=Object.assign(Object.assign({},this.statContext),r)}attachTo(r){let t;return new h.Subscription().add(r.events.started$.subscribe(()=>{this.logStarted({position:r.info.position$.getValue()})})).add(r.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:r.info.position$.getValue()})})).add(r.events.seeked$.subscribe(()=>{this.logSeek()})).add(r.events.willPause$.subscribe(()=>{this.logPause({position:r.info.position$.getValue()})})).add(r.events.willResume$.subscribe(()=>{this.logPlay()})).add(r.events.managedError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.fatalError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.inited$.subscribe(()=>{this.logInited()})).add(r.events.canplay$.subscribe(n=>{this.logReady({time:n})})).add(r.events.firstBytes$.subscribe(n=>{this.logFirstBytes({time:n})})).add(r.events.firstFrame$.subscribe(n=>{this.logFirstFrame({time:n})})).add(r.events.watchCoverageRecord$.subscribe(n=>{this.logWatchCoverageRecord(n)})).add(r.events.watchCoverageLive$.subscribe(n=>{this.logWatchCoverageLive(n)})).add(r.info.isStalled$.subscribe(n=>{n?t=h.now():(h.isNonNullable(t)&&this.logEmptyBuffer({duration:h.now()-t}),t=void 0)})).add(r.events.ended$.subscribe(()=>{const n=r.info.throughputEstimation$.getValue();h.isNonNullable(n)&&this.logDownloadSpeed({speed:n/8})})).add(r.info.hostname$.subscribe(n=>{this.updateContext({cdnHostname:n})})).add(r.info.httpConnectionType$.subscribe(n=>{this.updateContext({connectionType:Jl(n)})})).add(r.info.httpConnectionReused$.subscribe(n=>{this.updateContext({connectionReused:n})})).add(r.info.currentQuality$.subscribe(n=>{this.updateContext({quality:Yl(n)})})).add(r.info.currentFormat$.subscribe(n=>{this.updateContext({contentType:Xl(n)})})).add(r.info.chromecastState$.subscribe(n=>{this.updateContext({destination:n===d.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(r){return this.api.authorize(r)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=Jt()}setFieldBlacklist(r=[]){this.fieldBlacklist=r}logInited(){this.log({operation:"init"})}logReady(r){this.log({operation:"player_ready",param:String(r.time)})}logStarted(r){this.log({operation:"play",param:String(Math.round(r.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(r){this.log({operation:"pause",param:String(Math.round(r.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(r){this.log({operation:"first_bytes",param:String(r.time)})}logFirstFrame(r){this.log({operation:"first_frame",param:String(r.time)})}logError(r){this.log({operation:"error",param:r.errorType})}logWatchCoverageRecord(r){this.log({operation:"watch_coverage_record",param:`${r.start}-${r.end}`}),this.logger.flush(!0)}logWatchCoverageLive(r){const t=r.start+this.timeSynchronisation.getOffset(),n=r.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${t}-${n}`}),this.logger.flush(!0)}logEmptyBuffer(r){this.log({operation:"empty_buffer",param:String(r.duration)})}logDownloadSpeed(r){this.log({operation:"download_speed",param:String(r.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(r){this.log({operation:"adv",param:r})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(r){const t=this.createLogItem(r);this.logger.log(t)}createLogItem({operation:r,param:t}){const n=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?Ce.YES:this.statContext.connectionReused===!1?Ce.NO:void 0,stat_type:this.statContext.autoplay===!0?Re.AUTO:this.statContext.autoplay===!1?Re.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};t!==void 0&&(o.param=t);for(const a of this.fieldBlacklist)delete o[a];return{operation:r,timestamp:n,custom:o}}}exports.OneStat=Zl;
6
+ "use strict";var h=require("@vkontakte/videoplayer-shared/es2015.cjs.js"),d=require("@vkontakte/videoplayer-core/es2015.cjs.js"),ho=require("lodash/debounce.js");function w(e,r,t,n){function o(a){return a instanceof t?a:new t(function(i){i(a)})}return new(t||(t=Promise))(function(a,i){function v(c){try{s(n.next(c))}catch(l){i(l)}}function u(c){try{s(n.throw(c))}catch(l){i(l)}}function s(c){c.done?a(c.value):o(c.value).then(v,u)}s((n=n.apply(e,r||[])).next())})}var Hr=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},ue=function(e){return e&&e.Math==Math&&e},g=ue(typeof globalThis=="object"&&globalThis)||ue(typeof window=="object"&&window)||ue(typeof self=="object"&&self)||ue(typeof Hr=="object"&&Hr)||function(){return this}()||Function("return this")(),T=function(e){try{return!!e()}catch(r){return!0}},po=T,Ae=!po(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),yo=Ae,Xt=Function.prototype,qr=Xt.apply,Kr=Xt.call,Zt=typeof Reflect=="object"&&Reflect.apply||(yo?Kr.bind(qr):function(){return Kr.apply(qr,arguments)}),en=Ae,rn=Function.prototype,dr=rn.call,go=en&&rn.bind.bind(dr,dr),O=en?go:function(e){return function(){return dr.apply(e,arguments)}},tn=O,bo=tn({}.toString),$o=tn("".slice),Ne=function(e){return $o(bo(e),8,-1)},mo=Ne,Eo=O,nn=function(e){if(mo(e)==="Function")return Eo(e)},hr=typeof document=="object"&&document.all,So=typeof hr=="undefined"&&hr!==void 0,on={all:hr,IS_HTMLDDA:So},an=on,To=an.all,y=an.IS_HTMLDDA?function(e){return typeof e=="function"||e===To}:function(e){return typeof e=="function"},Ir={},Oo=T,J=!Oo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),_o=Ae,le=Function.prototype.call,_=_o?le.bind(le):function(){return le.apply(le,arguments)},sn={},cn={}.propertyIsEnumerable,un=Object.getOwnPropertyDescriptor,Po=un&&!cn.call({1:2},1);sn.f=Po?function(r){var t=un(this,r);return!!t&&t.enumerable}:cn;var ln=function(e,r){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:r}},Io=O,wo=T,Ro=Ne,xe=Object,Co=Io("".split),Ao=wo(function(){return!xe("z").propertyIsEnumerable(0)})?function(e){return Ro(e)=="String"?Co(e,""):xe(e)}:xe,De=function(e){return e==null},No=De,Do=TypeError,vn=function(e){if(No(e))throw Do("Can't call method on "+e);return e},jo=Ao,Lo=vn,Mo=function(e){return jo(Lo(e))},Qr=y,fn=on,Uo=fn.all,M=fn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:Qr(e)||e===Uo}:function(e){return typeof e=="object"?e!==null:Qr(e)},dn={},Ve=dn,He=g,ko=y,Wr=function(e){return ko(e)?e:void 0},C=function(e,r){return arguments.length<2?Wr(Ve[e])||Wr(He[e]):Ve[e]&&Ve[e][r]||He[e]&&He[e][r]},Bo=O,wr=Bo({}.isPrototypeOf),je=typeof navigator!="undefined"&&String(navigator.userAgent)||"",hn=g,qe=je,Gr=hn.process,zr=hn.Deno,Yr=Gr&&Gr.versions||zr&&zr.version,Jr=Yr&&Yr.v8,E,Se;Jr&&(E=Jr.split("."),Se=E[0]>0&&E[0]<4?1:+(E[0]+E[1]));!Se&&qe&&(E=qe.match(/Edge\/(\d+)/),(!E||E[1]>=74)&&(E=qe.match(/Chrome\/(\d+)/),E&&(Se=+E[1])));var pn=Se,Xr=pn,Fo=T,yn=!!Object.getOwnPropertySymbols&&!Fo(function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&Xr&&Xr<41}),xo=yn,gn=xo&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Vo=C,Ho=y,qo=wr,Ko=gn,Qo=Object,bn=Ko?function(e){return typeof e=="symbol"}:function(e){var r=Vo("Symbol");return Ho(r)&&qo(r.prototype,Qo(e))},Wo=String,Le=function(e){try{return Wo(e)}catch(r){return"Object"}},Go=y,zo=Le,Yo=TypeError,U=function(e){if(Go(e))return e;throw Yo(zo(e)+" is not a function")},Jo=U,Xo=De,Rr=function(e,r){var t=e[r];return Xo(t)?void 0:Jo(t)},Ke=_,Qe=y,We=M,Zo=TypeError,ea=function(e,r){var t,n;if(r==="string"&&Qe(t=e.toString)&&!We(n=Ke(t,e))||Qe(t=e.valueOf)&&!We(n=Ke(t,e))||r!=="string"&&Qe(t=e.toString)&&!We(n=Ke(t,e)))return n;throw Zo("Can't convert object to primitive value")},Te={},ra={get exports(){return Te},set exports(e){Te=e}},ie=!0,Zr=g,ta=Object.defineProperty,na=function(e,r){try{ta(Zr,e,{value:r,configurable:!0,writable:!0})}catch(t){Zr[e]=r}return r},oa=g,aa=na,et="__core-js_shared__",ia=oa[et]||aa(et,{}),Cr=ia,rt=Cr;(ra.exports=function(e,r){return rt[e]||(rt[e]=r!==void 0?r:{})})("versions",[]).push({version:"3.27.2",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.27.2/LICENSE",source:"https://github.com/zloirock/core-js"});var sa=vn,ca=Object,ua=function(e){return ca(sa(e))},la=O,va=ua,fa=la({}.hasOwnProperty),X=Object.hasOwn||function(r,t){return fa(va(r),t)},da=O,ha=0,pa=Math.random(),ya=da(1 .toString),$n=function(e){return"Symbol("+(e===void 0?"":e)+")_"+ya(++ha+pa,36)},ga=g,ba=Te,tt=X,$a=$n,ma=yn,Ea=gn,Q=ga.Symbol,Ge=ba("wks"),Sa=Ea?Q.for||Q:Q&&Q.withoutSetter||$a,P=function(e){return tt(Ge,e)||(Ge[e]=ma&&tt(Q,e)?Q[e]:Sa("Symbol."+e)),Ge[e]},Ta=_,nt=M,ot=bn,Oa=Rr,_a=ea,Pa=P,Ia=TypeError,wa=Pa("toPrimitive"),Ra=function(e,r){if(!nt(e)||ot(e))return e;var t=Oa(e,wa),n;if(t){if(r===void 0&&(r="default"),n=Ta(t,e,r),!nt(n)||ot(n))return n;throw Ia("Can't convert object to primitive value")}return r===void 0&&(r="number"),_a(e,r)},Ca=Ra,Aa=bn,mn=function(e){var r=Ca(e,"string");return Aa(r)?r:r+""},Na=g,at=M,pr=Na.document,Da=at(pr)&&at(pr.createElement),En=function(e){return Da?pr.createElement(e):{}},ja=J,La=T,Ma=En,Sn=!ja&&!La(function(){return Object.defineProperty(Ma("div"),"a",{get:function(){return 7}}).a!=7}),Ua=J,ka=_,Ba=sn,Fa=ln,xa=Mo,Va=mn,Ha=X,qa=Sn,it=Object.getOwnPropertyDescriptor;Ir.f=Ua?it:function(r,t){if(r=xa(r),t=Va(t),qa)try{return it(r,t)}catch(n){}if(Ha(r,t))return Fa(!ka(Ba.f,r,t),r[t])};var Ka=T,Qa=y,Wa=/#|\.prototype\./,se=function(e,r){var t=za[Ga(e)];return t==Ja?!0:t==Ya?!1:Qa(r)?Ka(r):!!r},Ga=se.normalize=function(e){return String(e).replace(Wa,".").toLowerCase()},za=se.data={},Ya=se.NATIVE="N",Ja=se.POLYFILL="P",Tn=se,st=nn,Xa=U,Za=Ae,ei=st(st.bind),Me=function(e,r){return Xa(e),r===void 0?e:Za?ei(e,r):function(){return e.apply(r,arguments)}},Ue={},ri=J,ti=T,ni=ri&&ti(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),oi=M,ai=String,ii=TypeError,k=function(e){if(oi(e))return e;throw ii(ai(e)+" is not an object")},si=J,ci=Sn,ui=ni,ve=k,ct=mn,li=TypeError,ze=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,Ye="enumerable",Je="configurable",Xe="writable";Ue.f=si?ui?function(r,t,n){if(ve(r),t=ct(t),ve(n),typeof r=="function"&&t==="prototype"&&"value"in n&&Xe in n&&!n[Xe]){var o=vi(r,t);o&&o[Xe]&&(r[t]=n.value,n={configurable:Je in n?n[Je]:o[Je],enumerable:Ye in n?n[Ye]:o[Ye],writable:!1})}return ze(r,t,n)}:ze:function(r,t,n){if(ve(r),t=ct(t),ve(n),ci)try{return ze(r,t,n)}catch(o){}if("get"in n||"set"in n)throw li("Accessors not supported");return"value"in n&&(r[t]=n.value),r};var fi=J,di=Ue,hi=ln,ke=fi?function(e,r,t){return di.f(e,r,hi(1,t))}:function(e,r,t){return e[r]=t,e},fe=g,pi=Zt,yi=nn,gi=y,bi=Ir.f,$i=Tn,x=dn,mi=Me,V=ke,ut=X,Ei=function(e){var r=function(t,n,o){if(this instanceof r){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,o)}return pi(e,this,arguments)};return r.prototype=e.prototype,r},B=function(e,r){var t=e.target,n=e.global,o=e.stat,a=e.proto,i=n?fe:o?fe[t]:(fe[t]||{}).prototype,v=n?x:x[t]||V(x,t,{})[t],u=v.prototype,s,c,l,p,f,m,A,I,F;for(p in r)s=$i(n?p:t+(o?".":"#")+p,e.forced),c=!s&&i&&ut(i,p),m=v[p],c&&(e.dontCallGetSet?(F=bi(i,p),A=F&&F.value):A=i[p]),f=c&&A?A:r[p],!(c&&typeof m==typeof f)&&(e.bind&&c?I=mi(f,fe):e.wrap&&c?I=Ei(f):a&&gi(f)?I=yi(f):I=f,(e.sham||f&&f.sham||m&&m.sham)&&V(I,"sham",!0),V(v,p,I),a&&(l=t+"Prototype",ut(x,l)||V(x,l,{}),V(x[l],p,f),e.real&&u&&(s||!u[p])&&V(u,p,f)))},Si=Ne,Be=typeof process!="undefined"&&Si(process)=="process",Ti=ke,Ar=function(e,r,t,n){return n&&n.enumerable?e[r]=t:Ti(e,r,t),e},Oi=y,_i=String,Pi=TypeError,Ii=function(e){if(typeof e=="object"||Oi(e))return e;throw Pi("Can't set "+_i(e)+" as a prototype")},wi=O,Ri=k,Ci=Ii,Ai=Object.setPrototypeOf||("__proto__"in{}?function(){var e=!1,r={},t;try{t=wi(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set),t(r,[]),e=r instanceof Array}catch(n){}return function(o,a){return Ri(o),Ci(a),e?t(o,a):o.__proto__=a,o}}():void 0),Ni=P,Di=Ni("toStringTag"),On={};On[Di]="z";var Nr=String(On)==="[object z]",ji=Nr,Li=y,$e=Ne,Mi=P,Ui=Mi("toStringTag"),ki=Object,Bi=$e(function(){return arguments}())=="Arguments",Fi=function(e,r){try{return e[r]}catch(t){}},Dr=ji?$e:function(e){var r,t,n;return e===void 0?"Undefined":e===null?"Null":typeof(t=Fi(r=ki(e),Ui))=="string"?t:Bi?$e(r):(n=$e(r))=="Object"&&Li(r.callee)?"Arguments":n},xi=Nr,Vi=Dr,Hi=xi?{}.toString:function(){return"[object "+Vi(this)+"]"},qi=Nr,Ki=Ue.f,Qi=ke,Wi=X,Gi=Hi,zi=P,lt=zi("toStringTag"),Yi=function(e,r,t,n){if(e){var o=t?e:e.prototype;Wi(o,lt)||Ki(o,lt,{configurable:!0,value:r}),n&&!qi&&Qi(o,"toString",Gi)}},Ji=C,Xi=Ue,Zi=P,es=J,vt=Zi("species"),rs=function(e){var r=Ji(e),t=Xi.f;es&&r&&!r[vt]&&t(r,vt,{configurable:!0,get:function(){return this}})},ts=wr,ns=TypeError,os=function(e,r){if(ts(r,e))return e;throw ns("Incorrect invocation")},as=O,is=y,yr=Cr,ss=as(Function.toString);is(yr.inspectSource)||(yr.inspectSource=function(e){return ss(e)});var _n=yr.inspectSource,cs=O,us=T,Pn=y,ls=Dr,vs=C,fs=_n,In=function(){},ds=[],wn=vs("Reflect","construct"),jr=/^\s*(?:class|function)\b/,hs=cs(jr.exec),ps=!jr.exec(In),re=function(r){if(!Pn(r))return!1;try{return wn(In,ds,r),!0}catch(t){return!1}},Rn=function(r){if(!Pn(r))return!1;switch(ls(r)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ps||!!hs(jr,fs(r))}catch(t){return!0}};Rn.sham=!0;var ys=!wn||us(function(){var e;return re(re.call)||!re(Object)||!re(function(){e=!0})||e})?Rn:re,gs=ys,bs=Le,$s=TypeError,ms=function(e){if(gs(e))return e;throw $s(bs(e)+" is not a constructor")},ft=k,Es=ms,Ss=De,Ts=P,Os=Ts("species"),Cn=function(e,r){var t=ft(e).constructor,n;return t===void 0||Ss(n=ft(t)[Os])?r:Es(n)},_s=C,Ps=_s("document","documentElement"),Is=O,ws=Is([].slice),Rs=TypeError,Cs=function(e,r){if(e<r)throw Rs("Not enough arguments");return e},As=je,An=/(?:ipad|iphone|ipod).*applewebkit/i.test(As),b=g,Ns=Zt,Ds=Me,dt=y,js=X,Nn=T,ht=Ps,Ls=ws,pt=En,Ms=Cs,Us=An,ks=Be,gr=b.setImmediate,br=b.clearImmediate,Bs=b.process,Ze=b.Dispatch,Fs=b.Function,yt=b.MessageChannel,xs=b.String,er=0,te={},gt="onreadystatechange",oe,N,rr,tr;Nn(function(){oe=b.location});var Lr=function(e){if(js(te,e)){var r=te[e];delete te[e],r()}},nr=function(e){return function(){Lr(e)}},bt=function(e){Lr(e.data)},$t=function(e){b.postMessage(xs(e),oe.protocol+"//"+oe.host)};(!gr||!br)&&(gr=function(r){Ms(arguments.length,1);var t=dt(r)?r:Fs(r),n=Ls(arguments,1);return te[++er]=function(){Ns(t,void 0,n)},N(er),er},br=function(r){delete te[r]},ks?N=function(e){Bs.nextTick(nr(e))}:Ze&&Ze.now?N=function(e){Ze.now(nr(e))}:yt&&!Us?(rr=new yt,tr=rr.port2,rr.port1.onmessage=bt,N=Ds(tr.postMessage,tr)):b.addEventListener&&dt(b.postMessage)&&!b.importScripts&&oe&&oe.protocol!=="file:"&&!Nn($t)?(N=$t,b.addEventListener("message",bt,!1)):gt in pt("script")?N=function(e){ht.appendChild(pt("script"))[gt]=function(){ht.removeChild(this),Lr(e)}}:N=function(e){setTimeout(nr(e),0)});var Dn={set:gr,clear:br},jn=function(){this.head=null,this.tail=null};jn.prototype={add:function(e){var r={item:e,next:null},t=this.tail;t?t.next=r:this.head=r,this.tail=r},get:function(){var e=this.head;if(e){var r=this.head=e.next;return r===null&&(this.tail=null),e.item}}};var Ln=jn,Vs=je,Hs=/ipad|iphone|ipod/i.test(Vs)&&typeof Pebble!="undefined",qs=je,Ks=/web0s(?!.*chrome)/i.test(qs),L=g,mt=Me,Qs=Ir.f,or=Dn.set,Ws=Ln,Gs=An,zs=Hs,Ys=Ks,ar=Be,Et=L.MutationObserver||L.WebKitMutationObserver,St=L.document,Tt=L.process,de=L.Promise,Ot=Qs(L,"queueMicrotask"),$r=Ot&&Ot.value,H,ir,sr,he,_t;if(!$r){var pe=new Ws,ye=function(){var e,r;for(ar&&(e=Tt.domain)&&e.exit();r=pe.get();)try{r()}catch(t){throw pe.head&&H(),t}e&&e.enter()};!Gs&&!ar&&!Ys&&Et&&St?(ir=!0,sr=St.createTextNode(""),new Et(ye).observe(sr,{characterData:!0}),H=function(){sr.data=ir=!ir}):!zs&&de&&de.resolve?(he=de.resolve(void 0),he.constructor=de,_t=mt(he.then,he),H=function(){_t(ye)}):ar?H=function(){Tt.nextTick(ye)}:(or=mt(or,L),H=function(){or(ye)}),$r=function(e){pe.head||H(),pe.add(e)}}var Js=$r,Xs=function(e,r){try{arguments.length==1?console.error(e):console.error(e,r)}catch(t){}},Mr=function(e){try{return{error:!1,value:e()}}catch(r){return{error:!0,value:r}}},Zs=g,ec=y,Pt=Zs.WeakMap,rc=ec(Pt)&&/native code/.test(String(Pt)),tc=Te,nc=$n,It=tc("keys"),oc=function(e){return It[e]||(It[e]=nc(e))},ac={},ic=rc,Mn=g,sc=M,cc=ke,cr=X,ur=Cr,uc=oc,lc=ac,wt="Object already initialized",mr=Mn.TypeError,vc=Mn.WeakMap,Oe,ae,_e,fc=function(e){return _e(e)?ae(e):Oe(e,{})},dc=function(e){return function(r){var t;if(!sc(r)||(t=ae(r)).type!==e)throw mr("Incompatible receiver, "+e+" required");return t}};if(ic||ur.state){var S=ur.state||(ur.state=new vc);S.get=S.get,S.has=S.has,S.set=S.set,Oe=function(e,r){if(S.has(e))throw mr(wt);return r.facade=e,S.set(e,r),r},ae=function(e){return S.get(e)||{}},_e=function(e){return S.has(e)}}else{var q=uc("state");lc[q]=!0,Oe=function(e,r){if(cr(e,q))throw mr(wt);return r.facade=e,cc(e,q,r),r},ae=function(e){return cr(e,q)?e[q]:{}},_e=function(e){return cr(e,q)}}var hc={set:Oe,get:ae,has:_e,enforce:fc,getterFor:dc},pc=g,Z=pc.Promise,Un=typeof Deno=="object"&&Deno&&typeof Deno.version=="object",yc=Un,gc=Be,bc=!yc&&!gc&&typeof window=="object"&&typeof document=="object",$c=g,ne=Z,mc=y,Ec=Tn,Sc=_n,Tc=P,Oc=bc,_c=Un,Pc=ie,lr=pn,Rt=ne&&ne.prototype,Ic=Tc("species"),Er=!1,kn=mc($c.PromiseRejectionEvent),wc=Ec("Promise",function(){var e=Sc(ne),r=e!==String(ne);if(!r&&lr===66||Pc&&!(Rt.catch&&Rt.finally))return!0;if(!lr||lr<51||!/native code/.test(e)){var t=new ne(function(a){a(1)}),n=function(a){a(function(){},function(){})},o=t.constructor={};if(o[Ic]=n,Er=t.then(function(){})instanceof n,!Er)return!0}return!r&&(Oc||_c)&&!kn}),ce={CONSTRUCTOR:wc,REJECTION_EVENT:kn,SUBCLASSING:Er},ee={},Ct=U,Rc=TypeError,Cc=function(e){var r,t;this.promise=new e(function(n,o){if(r!==void 0||t!==void 0)throw Rc("Bad Promise constructor");r=n,t=o}),this.resolve=Ct(r),this.reject=Ct(t)};ee.f=function(e){return new Cc(e)};var Ac=B,Nc=ie,Pe=Be,R=g,z=_,At=Ar,Nt=Ai,Dc=Yi,jc=rs,Lc=U,me=y,Mc=M,Uc=os,kc=Cn,Bn=Dn.set,Ur=Js,Bc=Xs,Fc=Mr,xc=Ln,Fn=hc,Ie=Z,kr=ce,xn=ee,Fe="Promise",Vn=kr.CONSTRUCTOR,Vc=kr.REJECTION_EVENT,Hc=kr.SUBCLASSING,vr=Fn.getterFor(Fe),qc=Fn.set,K=Ie&&Ie.prototype,D=Ie,ge=K,Hn=R.TypeError,Sr=R.document,Br=R.process,Tr=xn.f,Kc=Tr,Qc=!!(Sr&&Sr.createEvent&&R.dispatchEvent),qn="unhandledrejection",Wc="rejectionhandled",Dt=0,Kn=1,Gc=2,Fr=1,Qn=2,be,jt,zc,Lt,Wn=function(e){var r;return Mc(e)&&me(r=e.then)?r:!1},Gn=function(e,r){var t=r.value,n=r.state==Kn,o=n?e.ok:e.fail,a=e.resolve,i=e.reject,v=e.domain,u,s,c;try{o?(n||(r.rejection===Qn&&Jc(r),r.rejection=Fr),o===!0?u=t:(v&&v.enter(),u=o(t),v&&(v.exit(),c=!0)),u===e.promise?i(Hn("Promise-chain cycle")):(s=Wn(u))?z(s,u,a,i):a(u)):i(t)}catch(l){v&&!c&&v.exit(),i(l)}},zn=function(e,r){e.notified||(e.notified=!0,Ur(function(){for(var t=e.reactions,n;n=t.get();)Gn(n,e);e.notified=!1,r&&!e.rejection&&Yc(e)}))},Yn=function(e,r,t){var n,o;Qc?(n=Sr.createEvent("Event"),n.promise=r,n.reason=t,n.initEvent(e,!1,!0),R.dispatchEvent(n)):n={promise:r,reason:t},!Vc&&(o=R["on"+e])?o(n):e===qn&&Bc("Unhandled promise rejection",t)},Yc=function(e){z(Bn,R,function(){var r=e.facade,t=e.value,n=Mt(e),o;if(n&&(o=Fc(function(){Pe?Br.emit("unhandledRejection",t,r):Yn(qn,r,t)}),e.rejection=Pe||Mt(e)?Qn:Fr,o.error))throw o.value})},Mt=function(e){return e.rejection!==Fr&&!e.parent},Jc=function(e){z(Bn,R,function(){var r=e.facade;Pe?Br.emit("rejectionHandled",r):Yn(Wc,r,e.value)})},W=function(e,r,t){return function(n){e(r,n,t)}},G=function(e,r,t){e.done||(e.done=!0,t&&(e=t),e.value=r,e.state=Gc,zn(e,!0))},Or=function(e,r,t){if(!e.done){e.done=!0,t&&(e=t);try{if(e.facade===r)throw Hn("Promise can't be resolved itself");var n=Wn(r);n?Ur(function(){var o={done:!1};try{z(n,r,W(Or,o,e),W(G,o,e))}catch(a){G(o,a,e)}}):(e.value=r,e.state=Kn,zn(e,!1))}catch(o){G({done:!1},o,e)}}};if(Vn&&(D=function(r){Uc(this,ge),Lc(r),z(be,this);var t=vr(this);try{r(W(Or,t),W(G,t))}catch(n){G(t,n)}},ge=D.prototype,be=function(r){qc(this,{type:Fe,done:!1,notified:!1,parent:!1,reactions:new xc,rejection:!1,state:Dt,value:void 0})},be.prototype=At(ge,"then",function(r,t){var n=vr(this),o=Tr(kc(this,D));return n.parent=!0,o.ok=me(r)?r:!0,o.fail=me(t)&&t,o.domain=Pe?Br.domain:void 0,n.state==Dt?n.reactions.add(o):Ur(function(){Gn(o,n)}),o.promise}),jt=function(){var e=new be,r=vr(e);this.promise=e,this.resolve=W(Or,r),this.reject=W(G,r)},xn.f=Tr=function(e){return e===D||e===zc?new jt(e):Kc(e)},!Nc&&me(Ie)&&K!==Object.prototype)){Lt=K.then,Hc||At(K,"then",function(r,t){var n=this;return new D(function(o,a){z(Lt,n,o,a)}).then(r,t)},{unsafe:!0});try{delete K.constructor}catch(e){}Nt&&Nt(K,ge)}Ac({global:!0,constructor:!0,wrap:!0,forced:Vn},{Promise:D});Dc(D,Fe,!1,!0);jc(Fe);var Jn={},Xc=P,Zc=Jn,eu=Xc("iterator"),ru=Array.prototype,tu=function(e){return e!==void 0&&(Zc.Array===e||ru[eu]===e)},nu=Math.ceil,ou=Math.floor,au=Math.trunc||function(r){var t=+r;return(t>0?ou:nu)(t)},iu=au,su=function(e){var r=+e;return r!==r||r===0?0:iu(r)},cu=su,uu=Math.min,lu=function(e){return e>0?uu(cu(e),9007199254740991):0},vu=lu,fu=function(e){return vu(e.length)},du=Dr,Ut=Rr,hu=De,pu=Jn,yu=P,gu=yu("iterator"),Xn=function(e){if(!hu(e))return Ut(e,gu)||Ut(e,"@@iterator")||pu[du(e)]},bu=_,$u=U,mu=k,Eu=Le,Su=Xn,Tu=TypeError,Ou=function(e,r){var t=arguments.length<2?Su(e):r;if($u(t))return mu(bu(t,e));throw Tu(Eu(e)+" is not iterable")},_u=_,kt=k,Pu=Rr,Iu=function(e,r,t){var n,o;kt(e);try{if(n=Pu(e,"return"),!n){if(r==="throw")throw t;return t}n=_u(n,e)}catch(a){o=!0,n=a}if(r==="throw")throw t;if(o)throw n;return kt(n),t},wu=Me,Ru=_,Cu=k,Au=Le,Nu=tu,Du=fu,Bt=wr,ju=Ou,Lu=Xn,Ft=Iu,Mu=TypeError,Ee=function(e,r){this.stopped=e,this.result=r},xt=Ee.prototype,Zn=function(e,r,t){var n=t&&t.that,o=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),i=!!(t&&t.IS_ITERATOR),v=!!(t&&t.INTERRUPTED),u=wu(r,n),s,c,l,p,f,m,A,I=function($){return s&&Ft(s,"normal",$),new Ee(!0,$)},F=function($){return o?(Cu($),v?u($[0],$[1],I):u($[0],$[1])):v?u($,I):u($)};if(a)s=e.iterator;else if(i)s=e;else{if(c=Lu(e),!c)throw Mu(Au(e)+" is not iterable");if(Nu(c)){for(l=0,p=Du(e);p>l;l++)if(f=F(e[l]),f&&Bt(xt,f))return f;return new Ee(!1)}s=ju(e,c)}for(m=a?e.next:s.next;!(A=Ru(m,s)).done;){try{f=F(A.value)}catch($){Ft(s,"throw",$)}if(typeof f=="object"&&f&&Bt(xt,f))return f}return new Ee(!1)},Uu=P,eo=Uu("iterator"),ro=!1;try{var ku=0,Vt={next:function(){return{done:!!ku++}},return:function(){ro=!0}};Vt[eo]=function(){return this},Array.from(Vt,function(){throw 2})}catch(e){}var Bu=function(e,r){if(!r&&!ro)return!1;var t=!1;try{var n={};n[eo]=function(){return{next:function(){return{done:t=!0}}}},e(n)}catch(o){}return t},Fu=Z,xu=Bu,Vu=ce.CONSTRUCTOR,to=Vu||!xu(function(e){Fu.all(e).then(void 0,function(){})}),Hu=B,qu=_,Ku=U,Qu=ee,Wu=Mr,Gu=Zn,zu=to;Hu({target:"Promise",stat:!0,forced:zu},{all:function(r){var t=this,n=Qu.f(t),o=n.resolve,a=n.reject,i=Wu(function(){var v=Ku(t.resolve),u=[],s=0,c=1;Gu(r,function(l){var p=s++,f=!1;c++,qu(v,t,l).then(function(m){f||(f=!0,u[p]=m,--c||o(u))},a)}),--c||o(u)});return i.error&&a(i.value),n.promise}});var Yu=B,Ju=ie,Xu=ce.CONSTRUCTOR,_r=Z,Zu=C,el=y,rl=Ar,Ht=_r&&_r.prototype;Yu({target:"Promise",proto:!0,forced:Xu,real:!0},{catch:function(e){return this.then(void 0,e)}});if(!Ju&&el(_r)){var qt=Zu("Promise").prototype.catch;Ht.catch!==qt&&rl(Ht,"catch",qt,{unsafe:!0})}var tl=B,nl=_,ol=U,al=ee,il=Mr,sl=Zn,cl=to;tl({target:"Promise",stat:!0,forced:cl},{race:function(r){var t=this,n=al.f(t),o=n.reject,a=il(function(){var i=ol(t.resolve);sl(r,function(v){nl(i,t,v).then(n.resolve,o)})});return a.error&&o(a.value),n.promise}});var ul=B,ll=_,vl=ee,fl=ce.CONSTRUCTOR;ul({target:"Promise",stat:!0,forced:fl},{reject:function(r){var t=vl.f(this);return ll(t.reject,void 0,r),t.promise}});var dl=k,hl=M,pl=ee,no=function(e,r){if(dl(e),hl(r)&&r.constructor===e)return r;var t=pl.f(e),n=t.resolve;return n(r),t.promise},yl=B,gl=C,oo=ie,bl=Z,ao=ce.CONSTRUCTOR,$l=no,ml=gl("Promise"),El=oo&&!ao;yl({target:"Promise",stat:!0,forced:oo||ao},{resolve:function(r){return $l(El&&this===ml?bl:this,r)}});var Sl=B,Tl=ie,we=Z,Ol=T,io=C,so=y,_l=Cn,Kt=no,Pl=Ar,Pr=we&&we.prototype,Il=!!we&&Ol(function(){Pr.finally.call({then:function(){}},function(){})});Sl({target:"Promise",proto:!0,real:!0,forced:Il},{finally:function(e){var r=_l(this,io("Promise")),t=so(e);return this.then(t?function(n){return Kt(r,e()).then(function(){return n})}:e,t?function(n){return Kt(r,e()).then(function(){throw n})}:e)}});if(!Tl&&so(we)){var Qt=io("Promise").prototype.finally;Pr.finally!==Qt&&Pl(Pr,"finally",Qt,{unsafe:!0})}var wl=C,Rl=wl,Cl=Rl,Al=Cl("Promise","finally"),Nl=Al,Dl=Nl,jl=Dl,Ll=jl,fr=Ll;const xr="_one-stat_",Y=(()=>{try{const e=Date.now().toString(),r=window.localStorage;r.setItem(e,e);const t=r.getItem(e)===e;return r.removeItem(e),t?r:null}catch(e){return null}})();function Ml(e){const r=Y?Y.getItem(xr+e):null;if(r===null)return null;try{return JSON.parse(r)}catch(t){return null}}function Ul(e,r){try{Y&&Y.setItem(xr+e,JSON.stringify(r))}catch(t){}}function kl(e){Y&&Y.removeItem(xr+e)}var Wt={get(e){return Ml(e)||null},set(e,r){Ul(e,r)},remove(e){kl(e)}};function Bl(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=new Array(36);let t=0,n,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?r[o]="-":o===14?r[o]="4":(t<=2&&(t=33554432+Math.random()*16777216|0),n=t&15,t=t>>4,r[o]=e[o===19?n&3|8:n]);return r.join("")}exports.ApiEnv=void 0;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(e){e.Q144P="144",e.Q240P="240",e.Q360P="360",e.Q480P="480",e.Q720P="720",e.Q1080P="1080",e.Q1440P="1440",e.Q2160P="2160",e.Q4320P="4320",e.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(e){e.CHROMECAST="chromecast",e.APPLE_TV="appletv",e.PIP="pip",e.HEADPHONES="externalHeadphones",e.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.RTMP="rtmp",e.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var Re;(function(e){e.AUTO="auto",e.MANUAL=""})(Re||(Re={}));exports.ConnectionType=void 0;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var Ce;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(Ce||(Ce={}));const Gt="1.0.31",Fl="@vkontakte/videoplayer-statistics",xl="CIOPGQJGDIHBABABA",co={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},Vl={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var j;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(j||(j={}));class Hl{constructor(r){this.consequentAuthErrors=0,this.authorized$=new h.ValueSubject(!1),this.params=r;const t=Wt.get("uuid");t?this.uuid=String(t):(this.uuid=Bl(),Wt.set("uuid",this.uuid))}authorize(r){return w(this,void 0,void 0,function*(){return this.authToken=r!=null?r:yield this.refreshAuthToken(),this._authorizeWithBackoff()})}logBeacon(r){const t="log.externalLog",n=this.createLogParams(r),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(t,n,o)||this.logRequest(r)}logRequest(r){var t;return w(this,void 0,void 0,function*(){const n="log.externalLog",o=this.createLogParams(r),a=(t=this.sessionKey)!==null&&t!==void 0?t:yield this._authorizeWithBackoff();if(!a)return;const i=(v,u=this.params.requestRetryCount)=>w(this,void 0,void 0,function*(){try{return yield this.params.apiTransport.sendRequest(n,o,a)}catch(s){if(!s||!("error_code"in s)){this.params.error$.next({id:"logRequestUnknown",category:h.ErrorCategory.NETWORK,message:`Unknown ${n} error`,thrown:s});return}const c=s==null?void 0:s.error_code;switch(c){case j.PARAM_SESSION_EXPIRED:case j.PARAM_SESSION_KEY:case j.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;case j.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:h.ErrorCategory.EXTERNAL_API,message:`${n} error`,data:s});return}}}});return i(r)})}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return w(this,void 0,void 0,function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=fr(this.params.refreshAuthToken(),()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise})}createLogParams(r){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${Fl}:${Gt}`,platform:"WEB",items:r.map(t=>Object.assign(Object.assign({},t),{time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const r=h.getExponentialDelay(this.consequentAuthErrors,Vl);return new Promise(t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{fr(this._authorize().then(t).catch(n=>this.params.error$.next({id:"AuthorizeBackoff",category:h.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:n})),()=>this.backoffTimeoutId=0)},r))})}_authorize(){return w(this,void 0,void 0,function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const r="auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:Gt.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=fr(this.params.apiTransport.sendRequest(r,t).then(n=>{var o;return(!n||!n.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:h.ErrorCategory.EXTERNAL_API,message:"No session key",data:n}),this.sessionKey=(o=n==null?void 0:n.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(n=>w(this,void 0,void 0,function*(){this.sessionKey=void 0;const o=n==null?void 0:n.error_code;switch(o){case j.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:h.ErrorCategory.EXTERNAL_API,message:"authorize error",data:n}):this.params.error$.next({id:"AuthorizeUnknown",category:h.ErrorCategory.NETWORK,message:"authorize error",thrown:n})})),()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise})}}class zt{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(r,t,n){r in this.listeners||(this.listeners[r]=[]),this.listeners[r].push({callback:t,options:n})}removeEventListener(r,t){if(!(r in this.listeners))return;const n=this.listeners[r];for(let o=0,a=n.length;o<a;o++)if(n[o].callback===t){n.splice(o,1);return}}dispatchEvent(r){if(!(r.type in this.listeners))return;const n=this.listeners[r.type].slice();for(let o=0,a=n.length;o<a;o++){const i=n[o];try{i.callback.call(this,r)}catch(v){Promise.resolve().then(()=>{throw v})}i.options&&i.options.once&&this.removeEventListener(r.type,i.callback)}return!r.defaultPrevented}}class uo extends zt{constructor(){super(),this.listeners||zt.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(r){r.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,r)),super.dispatchEvent(r)}}class ql{constructor(){Object.defineProperty(this,"signal",{value:new uo,writable:!0,configurable:!0})}abort(r){let t;try{t=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=r;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(o){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(ql.prototype[Symbol.toStringTag]="AbortController",uo.prototype[Symbol.toStringTag]="AbortSignal");function lo(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Kl(e){typeof e=="function"&&(e={fetch:e});const{fetch:r,Request:t=r.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=e;if(!lo({fetch:r,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:r,Request:a};let a=t;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(s,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const p=new t(s,c);return l&&Object.defineProperty(p,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),p},a.prototype=t.prototype);const i=r;return{fetch:(u,s)=>{const c=a&&a.prototype.isPrototypeOf(u)?u.signal:s?s.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(f){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const p=new Promise((f,m)=>{c.addEventListener("abort",()=>m(l),{once:!0})});return s&&s.signal&&delete s.signal,Promise.race([p,i(u,s)])}return i(u,s)},Request:a}}const Vr=lo({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),vo=Vr?Kl({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Yt=Vr?vo.fetch:window.fetch;Vr?vo.Request:window.Request;class Ql{constructor(r){this.params=r,this.apiKey=r.apiKey,this.apiEnv=r.apiEnv,this.apiBaseUrl=r.apiBaseUrl,this.timeSynchronisation=r.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var r;return w(this,void 0,void 0,function*(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=yield(yield Yt(t,{method:"GET",mode:"cors",cache:"no-cache"})).json(),a=(r=o==null?void 0:o.Answer[0])===null||r===void 0?void 0:r.data;if(!a)throw new Error("Wrong DNS response");return a}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:h.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),co[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}})}sendBeacon(r,t,n){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:r,queryParams:t,sessionKey:n}),a=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,a)}catch(i){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:h.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:i,data:{method:r,params:t}})}return!1}sendRequest(r,t,n){return w(this,void 0,void 0,function*(){const o=h.now(),a=i=>{if(i instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(i.message)){this.params.error$.next({id:"Network",category:h.ErrorCategory.NETWORK,message:"Request failed",thrown:i});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:h.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:i,data:{method:r,params:t,sessionKey:n,time:h.now()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Yt(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:r,queryParams:t,sessionKey:n})}).then(i=>{var v;const u=Number(i.headers.get("content-length"))===0,s=new Date((v=i.headers.get("date"))!==null&&v!==void 0?v:"").getTime(),c=h.now()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,c),!u)return i.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,a)},a)})}_prepareQueryParams(r){const t=new URLSearchParams({format:"JSON",method:r.method,application_key:this.apiKey});return r.sessionKey!==void 0&&t.append("session_key",r.sessionKey),Object.entries(r.queryParams).forEach(([n,o])=>t.append(n,typeof o=="string"?o:JSON.stringify(o))),t}}const fo=3e3,Wl=fo*5;class Gl{constructor(r){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=ho(()=>{var t;try{this.flush()}catch(n){this.error$.next({id:"LoggerError",category:h.ErrorCategory.WTF,message:(t=String(n))!==null&&t!==void 0?t:"Unknown logger error",thrown:n})}},fo,{maxWait:Wl}),this.api=r.api,this.error$=r.error$,this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()})}log(r){this.requestQueue.push(r),this.isPaused||this.debouncedFlush()}flush(r=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(r?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):r||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class zl{constructor(r){this.offset=void 0,this.offset=r}getOffset(){var r;return(r=this.offset)!==null&&r!==void 0?r:0}setOffset(r){this.offset=r}now(){var r;return Date.now()+((r=this.offset)!==null&&r!==void 0?r:0)}date(r=new Date){var t;return r.setTime(r.getTime()+((t=this.offset)!==null&&t!==void 0?t:0)),r}addServerTime(r,t){const n=Date.now(),o=r-n-t/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const Jt=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,"0"),Yl=e=>e&&{[d.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[d.VideoQuality.Q_144P]:exports.Quality.Q144P,[d.VideoQuality.Q_240P]:exports.Quality.Q240P,[d.VideoQuality.Q_360P]:exports.Quality.Q360P,[d.VideoQuality.Q_480P]:exports.Quality.Q480P,[d.VideoQuality.Q_720P]:exports.Quality.Q720P,[d.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[d.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[d.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[d.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[e],Jl=e=>e&&{[d.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[d.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[d.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[e],Xl=e=>{if(e!==void 0)switch(e){case d.VideoFormat.MPEG:return exports.ContentType.MP4;case d.VideoFormat.DASH:case d.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case d.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case d.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case d.VideoFormat.DASH_WEBM:case d.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case d.VideoFormat.HLS:case d.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case d.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case d.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return h.assertNever(e)}};class Zl{constructor(r,t){var n;this.subscription=new h.Subscription,this.timeSynchronisation=new zl,this.vsid=Jt(),this.fieldBlacklist=[],this.statContext=r,this.config=Object.assign(Object.assign({},(n=t.config)!==null&&n!==void 0?n:{}),{requestRetryCount:1});const o=new h.Subject;this.experimental={error$:o};const a=new Ql({apiKey:xl,apiBaseUrl:co[t.apiEnv],apiEnv:t.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new Hl({apiTransport:a,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new Gl({api:this.api,error$:o}),this.subscription.add(h.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(r){this.statContext=Object.assign(Object.assign({},this.statContext),r)}attachTo(r){let t;return new h.Subscription().add(r.events.started$.subscribe(()=>{this.logStarted({position:r.info.position$.getValue()})})).add(r.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:r.info.position$.getValue()})})).add(r.events.seeked$.subscribe(()=>{this.logSeek()})).add(r.events.willPause$.subscribe(()=>{this.logPause({position:r.info.position$.getValue()})})).add(r.events.willResume$.subscribe(()=>{this.logPlay()})).add(r.events.managedError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.fatalError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.inited$.subscribe(()=>{this.logInited()})).add(r.events.canplay$.subscribe(n=>{this.logReady({time:n})})).add(r.events.firstBytes$.subscribe(n=>{this.logFirstBytes({time:n})})).add(r.events.firstFrame$.subscribe(n=>{this.logFirstFrame({time:n})})).add(r.events.watchCoverageRecord$.subscribe(n=>{this.logWatchCoverageRecord(n)})).add(r.events.watchCoverageLive$.subscribe(n=>{this.logWatchCoverageLive(n)})).add(r.info.isStalled$.subscribe(n=>{n?t=h.now():(h.isNonNullable(t)&&this.logEmptyBuffer({duration:h.now()-t}),t=void 0)})).add(r.events.ended$.subscribe(()=>{const n=r.info.throughputEstimation$.getValue();h.isNonNullable(n)&&this.logDownloadSpeed({speed:n/8})})).add(r.info.hostname$.subscribe(n=>{this.updateContext({cdnHostname:n})})).add(r.info.httpConnectionType$.subscribe(n=>{this.updateContext({connectionType:Jl(n)})})).add(r.info.httpConnectionReused$.subscribe(n=>{this.updateContext({connectionReused:n})})).add(r.info.currentQuality$.subscribe(n=>{this.updateContext({quality:Yl(n)})})).add(r.info.currentFormat$.subscribe(n=>{this.updateContext({contentType:Xl(n)})})).add(r.info.chromecastState$.subscribe(n=>{this.updateContext({destination:n===d.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(r){return this.api.authorize(r)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=Jt()}setFieldBlacklist(r=[]){this.fieldBlacklist=r}logInited(){this.log({operation:"init"})}logReady(r){this.log({operation:"player_ready",param:String(r.time)})}logStarted(r){this.log({operation:"play",param:String(Math.round(r.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(r){this.log({operation:"pause",param:String(Math.round(r.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(r){this.log({operation:"first_bytes",param:String(r.time)})}logFirstFrame(r){this.log({operation:"first_frame",param:String(r.time)})}logError(r){this.log({operation:"error",param:r.errorType})}logWatchCoverageRecord(r){this.log({operation:"watch_coverage_record",param:`${r.start}-${r.end}`}),this.logger.flush(!0)}logWatchCoverageLive(r){const t=r.start+this.timeSynchronisation.getOffset(),n=r.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${t}-${n}`}),this.logger.flush(!0)}logEmptyBuffer(r){this.log({operation:"empty_buffer",param:String(r.duration)})}logDownloadSpeed(r){this.log({operation:"download_speed",param:String(r.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(r){this.log({operation:"adv",param:r})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(r){const t=this.createLogItem(r);this.logger.log(t)}createLogItem({operation:r,param:t}){const n=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?Ce.YES:this.statContext.connectionReused===!1?Ce.NO:void 0,stat_type:this.statContext.autoplay===!0?Re.AUTO:this.statContext.autoplay===!1?Re.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};t!==void 0&&(o.param=t);for(const a of this.fieldBlacklist)delete o[a];return{operation:r,timestamp:n,custom:o}}}exports.OneStat=Zl;
package/es2015.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- import{ValueSubject as Oo,getExponentialDelay as Po,ErrorCategory as E,now as ie,assertNever as _o,Subscription as Jr,Subject as Io,fromEvent as wo,isNonNullable as Xr}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{VideoQuality as T,HttpConnectionType as ze,VideoFormat as m,ChromecastState as Ro}from"@vkontakte/videoplayer-core/es2015.esm.js";import Ao from"lodash/debounce.js";function N(e,r,t,n){function o(a){return a instanceof t?a:new t(function(i){i(a)})}return new(t||(t=Promise))(function(a,i){function v(c){try{s(n.next(c))}catch(l){i(l)}}function u(c){try{s(n.throw(c))}catch(l){i(l)}}function s(c){c.done?a(c.value):o(c.value).then(v,u)}s((n=n.apply(e,r||[])).next())})}var Zr=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},pe=function(e){return e&&e.Math==Math&&e},p=pe(typeof globalThis=="object"&&globalThis)||pe(typeof window=="object"&&window)||pe(typeof self=="object"&&self)||pe(typeof Zr=="object"&&Zr)||function(){return this}()||Function("return this")(),_=function(e){try{return!!e()}catch(r){return!0}},Co=_,ke=!Co(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),No=ke,un=Function.prototype,et=un.apply,rt=un.call,ln=typeof Reflect=="object"&&Reflect.apply||(No?rt.bind(et):function(){return rt.apply(et,arguments)}),vn=ke,fn=Function.prototype,Er=fn.call,Do=vn&&fn.bind.bind(Er,Er),I=vn?Do:function(e){return function(){return Er.apply(e,arguments)}},dn=I,jo=dn({}.toString),Lo=dn("".slice),Be=function(e){return Lo(jo(e),8,-1)},Mo=Be,Uo=I,hn=function(e){if(Mo(e)==="Function")return Uo(e)},Sr=typeof document=="object"&&document.all,ko=typeof Sr=="undefined"&&Sr!==void 0,pn={all:Sr,IS_HTMLDDA:ko},yn=pn,Bo=yn.all,h=yn.IS_HTMLDDA?function(e){return typeof e=="function"||e===Bo}:function(e){return typeof e=="function"},Lr={},xo=_,re=!xo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),Fo=ke,ye=Function.prototype.call,w=Fo?ye.bind(ye):function(){return ye.apply(ye,arguments)},gn={},bn={}.propertyIsEnumerable,$n=Object.getOwnPropertyDescriptor,Ho=$n&&!bn.call({1:2},1);gn.f=Ho?function(r){var t=$n(this,r);return!!t&&t.enumerable}:bn;var mn=function(e,r){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:r}},Ko=I,qo=_,Wo=Be,Qe=Object,Vo=Ko("".split),Go=qo(function(){return!Qe("z").propertyIsEnumerable(0)})?function(e){return Wo(e)=="String"?Vo(e,""):Qe(e)}:Qe,xe=function(e){return e==null},zo=xe,Qo=TypeError,En=function(e){if(zo(e))throw Qo("Can't call method on "+e);return e},Yo=Go,Jo=En,Xo=function(e){return Yo(Jo(e))},tt=h,Sn=pn,Zo=Sn.all,x=Sn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:tt(e)||e===Zo}:function(e){return typeof e=="object"?e!==null:tt(e)},Tn={},Ye=Tn,Je=p,ea=h,nt=function(e){return ea(e)?e:void 0},j=function(e,r){return arguments.length<2?nt(Ye[e])||nt(Je[e]):Ye[e]&&Ye[e][r]||Je[e]&&Je[e][r]},ra=I,Mr=ra({}.isPrototypeOf),Fe=typeof navigator!="undefined"&&String(navigator.userAgent)||"",On=p,Xe=Fe,ot=On.process,at=On.Deno,it=ot&&ot.versions||at&&at.version,st=it&&it.v8,S,we;st&&(S=st.split("."),we=S[0]>0&&S[0]<4?1:+(S[0]+S[1]));!we&&Xe&&(S=Xe.match(/Edge\/(\d+)/),(!S||S[1]>=74)&&(S=Xe.match(/Chrome\/(\d+)/),S&&(we=+S[1])));var Pn=we,ct=Pn,ta=_,_n=!!Object.getOwnPropertySymbols&&!ta(function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&ct&&ct<41}),na=_n,In=na&&!Symbol.sham&&typeof Symbol.iterator=="symbol",oa=j,aa=h,ia=Mr,sa=In,ca=Object,wn=sa?function(e){return typeof e=="symbol"}:function(e){var r=oa("Symbol");return aa(r)&&ia(r.prototype,ca(e))},ua=String,He=function(e){try{return ua(e)}catch(r){return"Object"}},la=h,va=He,fa=TypeError,F=function(e){if(la(e))return e;throw fa(va(e)+" is not a function")},da=F,ha=xe,Ur=function(e,r){var t=e[r];return ha(t)?void 0:da(t)},Ze=w,er=h,rr=x,pa=TypeError,ya=function(e,r){var t,n;if(r==="string"&&er(t=e.toString)&&!rr(n=Ze(t,e))||er(t=e.valueOf)&&!rr(n=Ze(t,e))||r!=="string"&&er(t=e.toString)&&!rr(n=Ze(t,e)))return n;throw pa("Can't convert object to primitive value")},Re={},ga={get exports(){return Re},set exports(e){Re=e}},fe=!0,ut=p,ba=Object.defineProperty,$a=function(e,r){try{ba(ut,e,{value:r,configurable:!0,writable:!0})}catch(t){ut[e]=r}return r},ma=p,Ea=$a,lt="__core-js_shared__",Sa=ma[lt]||Ea(lt,{}),kr=Sa,vt=kr;(ga.exports=function(e,r){return vt[e]||(vt[e]=r!==void 0?r:{})})("versions",[]).push({version:"3.27.2",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.27.2/LICENSE",source:"https://github.com/zloirock/core-js"});var Ta=En,Oa=Object,Pa=function(e){return Oa(Ta(e))},_a=I,Ia=Pa,wa=_a({}.hasOwnProperty),te=Object.hasOwn||function(r,t){return wa(Ia(r),t)},Ra=I,Aa=0,Ca=Math.random(),Na=Ra(1 .toString),Rn=function(e){return"Symbol("+(e===void 0?"":e)+")_"+Na(++Aa+Ca,36)},Da=p,ja=Re,ft=te,La=Rn,Ma=_n,Ua=In,Y=Da.Symbol,tr=ja("wks"),ka=Ua?Y.for||Y:Y&&Y.withoutSetter||La,R=function(e){return ft(tr,e)||(tr[e]=Ma&&ft(Y,e)?Y[e]:ka("Symbol."+e)),tr[e]},Ba=w,dt=x,ht=wn,xa=Ur,Fa=ya,Ha=R,Ka=TypeError,qa=Ha("toPrimitive"),Wa=function(e,r){if(!dt(e)||ht(e))return e;var t=xa(e,qa),n;if(t){if(r===void 0&&(r="default"),n=Ba(t,e,r),!dt(n)||ht(n))return n;throw Ka("Can't convert object to primitive value")}return r===void 0&&(r="number"),Fa(e,r)},Va=Wa,Ga=wn,An=function(e){var r=Va(e,"string");return Ga(r)?r:r+""},za=p,pt=x,Tr=za.document,Qa=pt(Tr)&&pt(Tr.createElement),Cn=function(e){return Qa?Tr.createElement(e):{}},Ya=re,Ja=_,Xa=Cn,Nn=!Ya&&!Ja(function(){return Object.defineProperty(Xa("div"),"a",{get:function(){return 7}}).a!=7}),Za=re,ei=w,ri=gn,ti=mn,ni=Xo,oi=An,ai=te,ii=Nn,yt=Object.getOwnPropertyDescriptor;Lr.f=Za?yt:function(r,t){if(r=ni(r),t=oi(t),ii)try{return yt(r,t)}catch(n){}if(ai(r,t))return ti(!ei(ri.f,r,t),r[t])};var si=_,ci=h,ui=/#|\.prototype\./,de=function(e,r){var t=vi[li(e)];return t==di?!0:t==fi?!1:ci(r)?si(r):!!r},li=de.normalize=function(e){return String(e).replace(ui,".").toLowerCase()},vi=de.data={},fi=de.NATIVE="N",di=de.POLYFILL="P",Dn=de,gt=hn,hi=F,pi=ke,yi=gt(gt.bind),Ke=function(e,r){return hi(e),r===void 0?e:pi?yi(e,r):function(){return e.apply(r,arguments)}},qe={},gi=re,bi=_,$i=gi&&bi(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),mi=x,Ei=String,Si=TypeError,H=function(e){if(mi(e))return e;throw Si(Ei(e)+" is not an object")},Ti=re,Oi=Nn,Pi=$i,ge=H,bt=An,_i=TypeError,nr=Object.defineProperty,Ii=Object.getOwnPropertyDescriptor,or="enumerable",ar="configurable",ir="writable";qe.f=Ti?Pi?function(r,t,n){if(ge(r),t=bt(t),ge(n),typeof r=="function"&&t==="prototype"&&"value"in n&&ir in n&&!n[ir]){var o=Ii(r,t);o&&o[ir]&&(r[t]=n.value,n={configurable:ar in n?n[ar]:o[ar],enumerable:or in n?n[or]:o[or],writable:!1})}return nr(r,t,n)}:nr:function(r,t,n){if(ge(r),t=bt(t),ge(n),Oi)try{return nr(r,t,n)}catch(o){}if("get"in n||"set"in n)throw _i("Accessors not supported");return"value"in n&&(r[t]=n.value),r};var wi=re,Ri=qe,Ai=mn,We=wi?function(e,r,t){return Ri.f(e,r,Ai(1,t))}:function(e,r,t){return e[r]=t,e},be=p,Ci=ln,Ni=hn,Di=h,ji=Lr.f,Li=Dn,W=Tn,Mi=Ke,V=We,$t=te,Ui=function(e){var r=function(t,n,o){if(this instanceof r){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,o)}return Ci(e,this,arguments)};return r.prototype=e.prototype,r},K=function(e,r){var t=e.target,n=e.global,o=e.stat,a=e.proto,i=n?be:o?be[t]:(be[t]||{}).prototype,v=n?W:W[t]||V(W,t,{})[t],u=v.prototype,s,c,l,d,f,$,L,A,q;for(d in r)s=Li(n?d:t+(o?".":"#")+d,e.forced),c=!s&&i&&$t(i,d),$=v[d],c&&(e.dontCallGetSet?(q=ji(i,d),L=q&&q.value):L=i[d]),f=c&&L?L:r[d],!(c&&typeof $==typeof f)&&(e.bind&&c?A=Mi(f,be):e.wrap&&c?A=Ui(f):a&&Di(f)?A=Ni(f):A=f,(e.sham||f&&f.sham||$&&$.sham)&&V(A,"sham",!0),V(v,d,A),a&&(l=t+"Prototype",$t(W,l)||V(W,l,{}),V(W[l],d,f),e.real&&u&&(s||!u[d])&&V(u,d,f)))},ki=Be,Ve=typeof process!="undefined"&&ki(process)=="process",Bi=We,Br=function(e,r,t,n){return n&&n.enumerable?e[r]=t:Bi(e,r,t),e},xi=h,Fi=String,Hi=TypeError,Ki=function(e){if(typeof e=="object"||xi(e))return e;throw Hi("Can't set "+Fi(e)+" as a prototype")},qi=I,Wi=H,Vi=Ki,Gi=Object.setPrototypeOf||("__proto__"in{}?function(){var e=!1,r={},t;try{t=qi(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set),t(r,[]),e=r instanceof Array}catch(n){}return function(o,a){return Wi(o),Vi(a),e?t(o,a):o.__proto__=a,o}}():void 0),zi=R,Qi=zi("toStringTag"),jn={};jn[Qi]="z";var xr=String(jn)==="[object z]",Yi=xr,Ji=h,Pe=Be,Xi=R,Zi=Xi("toStringTag"),es=Object,rs=Pe(function(){return arguments}())=="Arguments",ts=function(e,r){try{return e[r]}catch(t){}},Fr=Yi?Pe:function(e){var r,t,n;return e===void 0?"Undefined":e===null?"Null":typeof(t=ts(r=es(e),Zi))=="string"?t:rs?Pe(r):(n=Pe(r))=="Object"&&Ji(r.callee)?"Arguments":n},ns=xr,os=Fr,as=ns?{}.toString:function(){return"[object "+os(this)+"]"},is=xr,ss=qe.f,cs=We,us=te,ls=as,vs=R,mt=vs("toStringTag"),fs=function(e,r,t,n){if(e){var o=t?e:e.prototype;us(o,mt)||ss(o,mt,{configurable:!0,value:r}),n&&!is&&cs(o,"toString",ls)}},ds=j,hs=qe,ps=R,ys=re,Et=ps("species"),gs=function(e){var r=ds(e),t=hs.f;ys&&r&&!r[Et]&&t(r,Et,{configurable:!0,get:function(){return this}})},bs=Mr,$s=TypeError,ms=function(e,r){if(bs(r,e))return e;throw $s("Incorrect invocation")},Es=I,Ss=h,Or=kr,Ts=Es(Function.toString);Ss(Or.inspectSource)||(Or.inspectSource=function(e){return Ts(e)});var Ln=Or.inspectSource,Os=I,Ps=_,Mn=h,_s=Fr,Is=j,ws=Ln,Un=function(){},Rs=[],kn=Is("Reflect","construct"),Hr=/^\s*(?:class|function)\b/,As=Os(Hr.exec),Cs=!Hr.exec(Un),ae=function(r){if(!Mn(r))return!1;try{return kn(Un,Rs,r),!0}catch(t){return!1}},Bn=function(r){if(!Mn(r))return!1;switch(_s(r)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Cs||!!As(Hr,ws(r))}catch(t){return!0}};Bn.sham=!0;var Ns=!kn||Ps(function(){var e;return ae(ae.call)||!ae(Object)||!ae(function(){e=!0})||e})?Bn:ae,Ds=Ns,js=He,Ls=TypeError,Ms=function(e){if(Ds(e))return e;throw Ls(js(e)+" is not a constructor")},St=H,Us=Ms,ks=xe,Bs=R,xs=Bs("species"),xn=function(e,r){var t=St(e).constructor,n;return t===void 0||ks(n=St(t)[xs])?r:Us(n)},Fs=j,Hs=Fs("document","documentElement"),Ks=I,qs=Ks([].slice),Ws=TypeError,Vs=function(e,r){if(e<r)throw Ws("Not enough arguments");return e},Gs=Fe,Fn=/(?:ipad|iphone|ipod).*applewebkit/i.test(Gs),y=p,zs=ln,Qs=Ke,Tt=h,Ys=te,Hn=_,Ot=Hs,Js=qs,Pt=Cn,Xs=Vs,Zs=Fn,ec=Ve,Pr=y.setImmediate,_r=y.clearImmediate,rc=y.process,sr=y.Dispatch,tc=y.Function,_t=y.MessageChannel,nc=y.String,cr=0,se={},It="onreadystatechange",le,M,ur,lr;Hn(function(){le=y.location});var Kr=function(e){if(Ys(se,e)){var r=se[e];delete se[e],r()}},vr=function(e){return function(){Kr(e)}},wt=function(e){Kr(e.data)},Rt=function(e){y.postMessage(nc(e),le.protocol+"//"+le.host)};(!Pr||!_r)&&(Pr=function(r){Xs(arguments.length,1);var t=Tt(r)?r:tc(r),n=Js(arguments,1);return se[++cr]=function(){zs(t,void 0,n)},M(cr),cr},_r=function(r){delete se[r]},ec?M=function(e){rc.nextTick(vr(e))}:sr&&sr.now?M=function(e){sr.now(vr(e))}:_t&&!Zs?(ur=new _t,lr=ur.port2,ur.port1.onmessage=wt,M=Qs(lr.postMessage,lr)):y.addEventListener&&Tt(y.postMessage)&&!y.importScripts&&le&&le.protocol!=="file:"&&!Hn(Rt)?(M=Rt,y.addEventListener("message",wt,!1)):It in Pt("script")?M=function(e){Ot.appendChild(Pt("script"))[It]=function(){Ot.removeChild(this),Kr(e)}}:M=function(e){setTimeout(vr(e),0)});var Kn={set:Pr,clear:_r},qn=function(){this.head=null,this.tail=null};qn.prototype={add:function(e){var r={item:e,next:null},t=this.tail;t?t.next=r:this.head=r,this.tail=r},get:function(){var e=this.head;if(e){var r=this.head=e.next;return r===null&&(this.tail=null),e.item}}};var Wn=qn,oc=Fe,ac=/ipad|iphone|ipod/i.test(oc)&&typeof Pebble!="undefined",ic=Fe,sc=/web0s(?!.*chrome)/i.test(ic),B=p,At=Ke,cc=Lr.f,fr=Kn.set,uc=Wn,lc=Fn,vc=ac,fc=sc,dr=Ve,Ct=B.MutationObserver||B.WebKitMutationObserver,Nt=B.document,Dt=B.process,$e=B.Promise,jt=cc(B,"queueMicrotask"),Ir=jt&&jt.value,G,hr,pr,me,Lt;if(!Ir){var Ee=new uc,Se=function(){var e,r;for(dr&&(e=Dt.domain)&&e.exit();r=Ee.get();)try{r()}catch(t){throw Ee.head&&G(),t}e&&e.enter()};!lc&&!dr&&!fc&&Ct&&Nt?(hr=!0,pr=Nt.createTextNode(""),new Ct(Se).observe(pr,{characterData:!0}),G=function(){pr.data=hr=!hr}):!vc&&$e&&$e.resolve?(me=$e.resolve(void 0),me.constructor=$e,Lt=At(me.then,me),G=function(){Lt(Se)}):dr?G=function(){Dt.nextTick(Se)}:(fr=At(fr,B),G=function(){fr(Se)}),Ir=function(e){Ee.head||G(),Ee.add(e)}}var dc=Ir,hc=function(e,r){try{arguments.length==1?console.error(e):console.error(e,r)}catch(t){}},qr=function(e){try{return{error:!1,value:e()}}catch(r){return{error:!0,value:r}}},pc=p,yc=h,Mt=pc.WeakMap,gc=yc(Mt)&&/native code/.test(String(Mt)),bc=Re,$c=Rn,Ut=bc("keys"),mc=function(e){return Ut[e]||(Ut[e]=$c(e))},Ec={},Sc=gc,Vn=p,Tc=x,Oc=We,yr=te,gr=kr,Pc=mc,_c=Ec,kt="Object already initialized",wr=Vn.TypeError,Ic=Vn.WeakMap,Ae,ve,Ce,wc=function(e){return Ce(e)?ve(e):Ae(e,{})},Rc=function(e){return function(r){var t;if(!Tc(r)||(t=ve(r)).type!==e)throw wr("Incompatible receiver, "+e+" required");return t}};if(Sc||gr.state){var O=gr.state||(gr.state=new Ic);O.get=O.get,O.has=O.has,O.set=O.set,Ae=function(e,r){if(O.has(e))throw wr(kt);return r.facade=e,O.set(e,r),r},ve=function(e){return O.get(e)||{}},Ce=function(e){return O.has(e)}}else{var z=Pc("state");_c[z]=!0,Ae=function(e,r){if(yr(e,z))throw wr(kt);return r.facade=e,Oc(e,z,r),r},ve=function(e){return yr(e,z)?e[z]:{}},Ce=function(e){return yr(e,z)}}var Ac={set:Ae,get:ve,has:Ce,enforce:wc,getterFor:Rc},Cc=p,ne=Cc.Promise,Gn=typeof Deno=="object"&&Deno&&typeof Deno.version=="object",Nc=Gn,Dc=Ve,jc=!Nc&&!Dc&&typeof window=="object"&&typeof document=="object",Lc=p,ce=ne,Mc=h,Uc=Dn,kc=Ln,Bc=R,xc=jc,Fc=Gn,Hc=fe,br=Pn,Bt=ce&&ce.prototype,Kc=Bc("species"),Rr=!1,zn=Mc(Lc.PromiseRejectionEvent),qc=Uc("Promise",function(){var e=kc(ce),r=e!==String(ce);if(!r&&br===66||Hc&&!(Bt.catch&&Bt.finally))return!0;if(!br||br<51||!/native code/.test(e)){var t=new ce(function(a){a(1)}),n=function(a){a(function(){},function(){})},o=t.constructor={};if(o[Kc]=n,Rr=t.then(function(){})instanceof n,!Rr)return!0}return!r&&(xc||Fc)&&!zn}),he={CONSTRUCTOR:qc,REJECTION_EVENT:zn,SUBCLASSING:Rr},oe={},xt=F,Wc=TypeError,Vc=function(e){var r,t;this.promise=new e(function(n,o){if(r!==void 0||t!==void 0)throw Wc("Bad Promise constructor");r=n,t=o}),this.resolve=xt(r),this.reject=xt(t)};oe.f=function(e){return new Vc(e)};var Gc=K,zc=fe,Ne=Ve,D=p,Z=w,Ft=Br,Ht=Gi,Qc=fs,Yc=gs,Jc=F,_e=h,Xc=x,Zc=ms,eu=xn,Qn=Kn.set,Wr=dc,ru=hc,tu=qr,nu=Wn,Yn=Ac,De=ne,Vr=he,Jn=oe,Ge="Promise",Xn=Vr.CONSTRUCTOR,ou=Vr.REJECTION_EVENT,au=Vr.SUBCLASSING,$r=Yn.getterFor(Ge),iu=Yn.set,Q=De&&De.prototype,U=De,Te=Q,Zn=D.TypeError,Ar=D.document,Gr=D.process,Cr=Jn.f,su=Cr,cu=!!(Ar&&Ar.createEvent&&D.dispatchEvent),eo="unhandledrejection",uu="rejectionhandled",Kt=0,ro=1,lu=2,zr=1,to=2,Oe,qt,vu,Wt,no=function(e){var r;return Xc(e)&&_e(r=e.then)?r:!1},oo=function(e,r){var t=r.value,n=r.state==ro,o=n?e.ok:e.fail,a=e.resolve,i=e.reject,v=e.domain,u,s,c;try{o?(n||(r.rejection===to&&du(r),r.rejection=zr),o===!0?u=t:(v&&v.enter(),u=o(t),v&&(v.exit(),c=!0)),u===e.promise?i(Zn("Promise-chain cycle")):(s=no(u))?Z(s,u,a,i):a(u)):i(t)}catch(l){v&&!c&&v.exit(),i(l)}},ao=function(e,r){e.notified||(e.notified=!0,Wr(function(){for(var t=e.reactions,n;n=t.get();)oo(n,e);e.notified=!1,r&&!e.rejection&&fu(e)}))},io=function(e,r,t){var n,o;cu?(n=Ar.createEvent("Event"),n.promise=r,n.reason=t,n.initEvent(e,!1,!0),D.dispatchEvent(n)):n={promise:r,reason:t},!ou&&(o=D["on"+e])?o(n):e===eo&&ru("Unhandled promise rejection",t)},fu=function(e){Z(Qn,D,function(){var r=e.facade,t=e.value,n=Vt(e),o;if(n&&(o=tu(function(){Ne?Gr.emit("unhandledRejection",t,r):io(eo,r,t)}),e.rejection=Ne||Vt(e)?to:zr,o.error))throw o.value})},Vt=function(e){return e.rejection!==zr&&!e.parent},du=function(e){Z(Qn,D,function(){var r=e.facade;Ne?Gr.emit("rejectionHandled",r):io(uu,r,e.value)})},J=function(e,r,t){return function(n){e(r,n,t)}},X=function(e,r,t){e.done||(e.done=!0,t&&(e=t),e.value=r,e.state=lu,ao(e,!0))},Nr=function(e,r,t){if(!e.done){e.done=!0,t&&(e=t);try{if(e.facade===r)throw Zn("Promise can't be resolved itself");var n=no(r);n?Wr(function(){var o={done:!1};try{Z(n,r,J(Nr,o,e),J(X,o,e))}catch(a){X(o,a,e)}}):(e.value=r,e.state=ro,ao(e,!1))}catch(o){X({done:!1},o,e)}}};if(Xn&&(U=function(r){Zc(this,Te),Jc(r),Z(Oe,this);var t=$r(this);try{r(J(Nr,t),J(X,t))}catch(n){X(t,n)}},Te=U.prototype,Oe=function(r){iu(this,{type:Ge,done:!1,notified:!1,parent:!1,reactions:new nu,rejection:!1,state:Kt,value:void 0})},Oe.prototype=Ft(Te,"then",function(r,t){var n=$r(this),o=Cr(eu(this,U));return n.parent=!0,o.ok=_e(r)?r:!0,o.fail=_e(t)&&t,o.domain=Ne?Gr.domain:void 0,n.state==Kt?n.reactions.add(o):Wr(function(){oo(o,n)}),o.promise}),qt=function(){var e=new Oe,r=$r(e);this.promise=e,this.resolve=J(Nr,r),this.reject=J(X,r)},Jn.f=Cr=function(e){return e===U||e===vu?new qt(e):su(e)},!zc&&_e(De)&&Q!==Object.prototype)){Wt=Q.then,au||Ft(Q,"then",function(r,t){var n=this;return new U(function(o,a){Z(Wt,n,o,a)}).then(r,t)},{unsafe:!0});try{delete Q.constructor}catch(e){}Ht&&Ht(Q,Te)}Gc({global:!0,constructor:!0,wrap:!0,forced:Xn},{Promise:U});Qc(U,Ge,!1,!0);Yc(Ge);var so={},hu=R,pu=so,yu=hu("iterator"),gu=Array.prototype,bu=function(e){return e!==void 0&&(pu.Array===e||gu[yu]===e)},$u=Math.ceil,mu=Math.floor,Eu=Math.trunc||function(r){var t=+r;return(t>0?mu:$u)(t)},Su=Eu,Tu=function(e){var r=+e;return r!==r||r===0?0:Su(r)},Ou=Tu,Pu=Math.min,_u=function(e){return e>0?Pu(Ou(e),9007199254740991):0},Iu=_u,wu=function(e){return Iu(e.length)},Ru=Fr,Gt=Ur,Au=xe,Cu=so,Nu=R,Du=Nu("iterator"),co=function(e){if(!Au(e))return Gt(e,Du)||Gt(e,"@@iterator")||Cu[Ru(e)]},ju=w,Lu=F,Mu=H,Uu=He,ku=co,Bu=TypeError,xu=function(e,r){var t=arguments.length<2?ku(e):r;if(Lu(t))return Mu(ju(t,e));throw Bu(Uu(e)+" is not iterable")},Fu=w,zt=H,Hu=Ur,Ku=function(e,r,t){var n,o;zt(e);try{if(n=Hu(e,"return"),!n){if(r==="throw")throw t;return t}n=Fu(n,e)}catch(a){o=!0,n=a}if(r==="throw")throw t;if(o)throw n;return zt(n),t},qu=Ke,Wu=w,Vu=H,Gu=He,zu=bu,Qu=wu,Qt=Mr,Yu=xu,Ju=co,Yt=Ku,Xu=TypeError,Ie=function(e,r){this.stopped=e,this.result=r},Jt=Ie.prototype,uo=function(e,r,t){var n=t&&t.that,o=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),i=!!(t&&t.IS_ITERATOR),v=!!(t&&t.INTERRUPTED),u=qu(r,n),s,c,l,d,f,$,L,A=function(g){return s&&Yt(s,"normal",g),new Ie(!0,g)},q=function(g){return o?(Vu(g),v?u(g[0],g[1],A):u(g[0],g[1])):v?u(g,A):u(g)};if(a)s=e.iterator;else if(i)s=e;else{if(c=Ju(e),!c)throw Xu(Gu(e)+" is not iterable");if(zu(c)){for(l=0,d=Qu(e);d>l;l++)if(f=q(e[l]),f&&Qt(Jt,f))return f;return new Ie(!1)}s=Yu(e,c)}for($=a?e.next:s.next;!(L=Wu($,s)).done;){try{f=q(L.value)}catch(g){Yt(s,"throw",g)}if(typeof f=="object"&&f&&Qt(Jt,f))return f}return new Ie(!1)},Zu=R,lo=Zu("iterator"),vo=!1;try{var el=0,Xt={next:function(){return{done:!!el++}},return:function(){vo=!0}};Xt[lo]=function(){return this},Array.from(Xt,function(){throw 2})}catch(e){}var rl=function(e,r){if(!r&&!vo)return!1;var t=!1;try{var n={};n[lo]=function(){return{next:function(){return{done:t=!0}}}},e(n)}catch(o){}return t},tl=ne,nl=rl,ol=he.CONSTRUCTOR,fo=ol||!nl(function(e){tl.all(e).then(void 0,function(){})}),al=K,il=w,sl=F,cl=oe,ul=qr,ll=uo,vl=fo;al({target:"Promise",stat:!0,forced:vl},{all:function(r){var t=this,n=cl.f(t),o=n.resolve,a=n.reject,i=ul(function(){var v=sl(t.resolve),u=[],s=0,c=1;ll(r,function(l){var d=s++,f=!1;c++,il(v,t,l).then(function($){f||(f=!0,u[d]=$,--c||o(u))},a)}),--c||o(u)});return i.error&&a(i.value),n.promise}});var fl=K,dl=fe,hl=he.CONSTRUCTOR,Dr=ne,pl=j,yl=h,gl=Br,Zt=Dr&&Dr.prototype;fl({target:"Promise",proto:!0,forced:hl,real:!0},{catch:function(e){return this.then(void 0,e)}});if(!dl&&yl(Dr)){var en=pl("Promise").prototype.catch;Zt.catch!==en&&gl(Zt,"catch",en,{unsafe:!0})}var bl=K,$l=w,ml=F,El=oe,Sl=qr,Tl=uo,Ol=fo;bl({target:"Promise",stat:!0,forced:Ol},{race:function(r){var t=this,n=El.f(t),o=n.reject,a=Sl(function(){var i=ml(t.resolve);Tl(r,function(v){$l(i,t,v).then(n.resolve,o)})});return a.error&&o(a.value),n.promise}});var Pl=K,_l=w,Il=oe,wl=he.CONSTRUCTOR;Pl({target:"Promise",stat:!0,forced:wl},{reject:function(r){var t=Il.f(this);return _l(t.reject,void 0,r),t.promise}});var Rl=H,Al=x,Cl=oe,ho=function(e,r){if(Rl(e),Al(r)&&r.constructor===e)return r;var t=Cl.f(e),n=t.resolve;return n(r),t.promise},Nl=K,Dl=j,po=fe,jl=ne,yo=he.CONSTRUCTOR,Ll=ho,Ml=Dl("Promise"),Ul=po&&!yo;Nl({target:"Promise",stat:!0,forced:po||yo},{resolve:function(r){return Ll(Ul&&this===Ml?jl:this,r)}});var kl=K,Bl=fe,je=ne,xl=_,go=j,bo=h,Fl=xn,rn=ho,Hl=Br,jr=je&&je.prototype,Kl=!!je&&xl(function(){jr.finally.call({then:function(){}},function(){})});kl({target:"Promise",proto:!0,real:!0,forced:Kl},{finally:function(e){var r=Fl(this,go("Promise")),t=bo(e);return this.then(t?function(n){return rn(r,e()).then(function(){return n})}:e,t?function(n){return rn(r,e()).then(function(){throw n})}:e)}});if(!Bl&&bo(je)){var tn=go("Promise").prototype.finally;jr.finally!==tn&&Hl(jr,"finally",tn,{unsafe:!0})}var ql=j,Wl=ql,Vl=Wl,Gl=Vl("Promise","finally"),zl=Gl,Ql=zl,Yl=Ql,Jl=Yl,mr=Jl;const Qr="_one-stat_",ee=(()=>{try{const e=Date.now().toString(),r=window.localStorage;r.setItem(e,e);const t=r.getItem(e)===e;return r.removeItem(e),t?r:null}catch(e){return null}})();function Xl(e){const r=ee?ee.getItem(Qr+e):null;if(r===null)return null;try{return JSON.parse(r)}catch(t){return null}}function Zl(e,r){try{ee&&ee.setItem(Qr+e,JSON.stringify(r))}catch(t){}}function ev(e){ee&&ee.removeItem(Qr+e)}var nn={get(e){return Xl(e)||null},set(e,r){Zl(e,r)},remove(e){ev(e)}};function rv(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=new Array(36);let t=0,n,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?r[o]="-":o===14?r[o]="4":(t<=2&&(t=33554432+Math.random()*16777216|0),n=t&15,t=t>>4,r[o]=e[o===19?n&3|8:n]);return r.join("")}var C;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(C||(C={}));var b;(function(e){e.Q144P="144",e.Q240P="240",e.Q360P="360",e.Q480P="480",e.Q720P="720",e.Q1080P="1080",e.Q1440P="1440",e.Q2160P="2160",e.Q4320P="4320",e.UNKNOWN="unknown"})(b||(b={}));var Le;(function(e){e.CHROMECAST="chromecast",e.APPLE_TV="appletv",e.PIP="pip",e.HEADPHONES="externalHeadphones",e.SCREEN=""})(Le||(Le={}));var P;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.RTMP="rtmp",e.UNKNOWN="unknown"})(P||(P={}));var Me;(function(e){e.AUTO="auto",e.MANUAL=""})(Me||(Me={}));var ue;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(ue||(ue={}));var Ue;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(Ue||(Ue={}));const on="1.0.30",tv="@vkontakte/videoplayer-statistics",nv="CIOPGQJGDIHBABABA",$o={[C.PROD]:"https://api.ok.ru",[C.VK_ALIAS]:"https://api.mycdn.me",[C.VIDEOTEST]:"https://videotestapi.ok.ru/api",[C.TEST]:"https://apitest.ok.ru",[C.AUTO]:""},ov={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var k;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(k||(k={}));class av{constructor(r){this.consequentAuthErrors=0,this.authorized$=new Oo(!1),this.params=r;const t=nn.get("uuid");t?this.uuid=String(t):(this.uuid=rv(),nn.set("uuid",this.uuid))}authorize(r){return N(this,void 0,void 0,function*(){return this.authToken=r!=null?r:yield this.refreshAuthToken(),this._authorizeWithBackoff()})}logBeacon(r){const t="log.externalLog",n=this.createLogParams(r),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(t,n,o)||this.logRequest(r)}logRequest(r){var t;return N(this,void 0,void 0,function*(){const n="log.externalLog",o=this.createLogParams(r),a=(t=this.sessionKey)!==null&&t!==void 0?t:yield this._authorizeWithBackoff();if(!a)return;const i=(v,u=this.params.requestRetryCount)=>N(this,void 0,void 0,function*(){try{return yield this.params.apiTransport.sendRequest(n,o,a)}catch(s){if(!s||!("error_code"in s)){this.params.error$.next({id:"logRequestUnknown",category:E.NETWORK,message:`Unknown ${n} error`,thrown:s});return}const c=s==null?void 0:s.error_code;switch(c){case k.PARAM_SESSION_EXPIRED:case k.PARAM_SESSION_KEY:case k.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;case k.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:E.EXTERNAL_API,message:`${n} error`,data:s});return}}}});return i(r)})}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return N(this,void 0,void 0,function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=mr(this.params.refreshAuthToken(),()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise})}createLogParams(r){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${tv}:${on}`,platform:"WEB",items:r.map(t=>Object.assign(Object.assign({},t),{time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const r=Po(this.consequentAuthErrors,ov);return new Promise(t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{mr(this._authorize().then(t).catch(n=>this.params.error$.next({id:"AuthorizeBackoff",category:E.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:n})),()=>this.backoffTimeoutId=0)},r))})}_authorize(){return N(this,void 0,void 0,function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const r="auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:on.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=mr(this.params.apiTransport.sendRequest(r,t).then(n=>{var o;return(!n||!n.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:E.EXTERNAL_API,message:"No session key",data:n}),this.sessionKey=(o=n==null?void 0:n.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(n=>N(this,void 0,void 0,function*(){this.sessionKey=void 0;const o=n==null?void 0:n.error_code;switch(o){case k.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:E.EXTERNAL_API,message:"authorize error",data:n}):this.params.error$.next({id:"AuthorizeUnknown",category:E.NETWORK,message:"authorize error",thrown:n})})),()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise})}}class an{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(r,t,n){r in this.listeners||(this.listeners[r]=[]),this.listeners[r].push({callback:t,options:n})}removeEventListener(r,t){if(!(r in this.listeners))return;const n=this.listeners[r];for(let o=0,a=n.length;o<a;o++)if(n[o].callback===t){n.splice(o,1);return}}dispatchEvent(r){if(!(r.type in this.listeners))return;const n=this.listeners[r.type].slice();for(let o=0,a=n.length;o<a;o++){const i=n[o];try{i.callback.call(this,r)}catch(v){Promise.resolve().then(()=>{throw v})}i.options&&i.options.once&&this.removeEventListener(r.type,i.callback)}return!r.defaultPrevented}}class mo extends an{constructor(){super(),this.listeners||an.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(r){r.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,r)),super.dispatchEvent(r)}}class iv{constructor(){Object.defineProperty(this,"signal",{value:new mo,writable:!0,configurable:!0})}abort(r){let t;try{t=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=r;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(o){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(iv.prototype[Symbol.toStringTag]="AbortController",mo.prototype[Symbol.toStringTag]="AbortSignal");function Eo(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function sv(e){typeof e=="function"&&(e={fetch:e});const{fetch:r,Request:t=r.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=e;if(!Eo({fetch:r,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:r,Request:a};let a=t;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(s,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const d=new t(s,c);return l&&Object.defineProperty(d,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),d},a.prototype=t.prototype);const i=r;return{fetch:(u,s)=>{const c=a&&a.prototype.isPrototypeOf(u)?u.signal:s?s.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(f){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const d=new Promise((f,$)=>{c.addEventListener("abort",()=>$(l),{once:!0})});return s&&s.signal&&delete s.signal,Promise.race([d,i(u,s)])}return i(u,s)},Request:a}}const Yr=Eo({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),So=Yr?sv({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,sn=Yr?So.fetch:window.fetch;Yr?So.Request:window.Request;class cv{constructor(r){this.params=r,this.apiKey=r.apiKey,this.apiEnv=r.apiEnv,this.apiBaseUrl=r.apiBaseUrl,this.timeSynchronisation=r.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var r;return N(this,void 0,void 0,function*(){if(this.apiEnv!==C.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=yield(yield sn(t,{method:"GET",mode:"cors",cache:"no-cache"})).json(),a=(r=o==null?void 0:o.Answer[0])===null||r===void 0?void 0:r.data;if(!a)throw new Error("Wrong DNS response");return a}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:E.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),$o[C.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}})}sendBeacon(r,t,n){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:r,queryParams:t,sessionKey:n}),a=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,a)}catch(i){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:E.NETWORK,message:"Unhandled beacon error",thrown:i,data:{method:r,params:t}})}return!1}sendRequest(r,t,n){return N(this,void 0,void 0,function*(){const o=ie(),a=i=>{if(i instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(i.message)){this.params.error$.next({id:"Network",category:E.NETWORK,message:"Request failed",thrown:i});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:E.NETWORK,message:"Unhandled request error",thrown:i,data:{method:r,params:t,sessionKey:n,time:ie()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),sn(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:r,queryParams:t,sessionKey:n})}).then(i=>{var v;const u=Number(i.headers.get("content-length"))===0,s=new Date((v=i.headers.get("date"))!==null&&v!==void 0?v:"").getTime(),c=ie()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,c),!u)return i.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,a)},a)})}_prepareQueryParams(r){const t=new URLSearchParams({format:"JSON",method:r.method,application_key:this.apiKey});return r.sessionKey!==void 0&&t.append("session_key",r.sessionKey),Object.entries(r.queryParams).forEach(([n,o])=>t.append(n,typeof o=="string"?o:JSON.stringify(o))),t}}const To=3e3,uv=To*5;class lv{constructor(r){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=Ao(()=>{var t;try{this.flush()}catch(n){this.error$.next({id:"LoggerError",category:E.WTF,message:(t=String(n))!==null&&t!==void 0?t:"Unknown logger error",thrown:n})}},To,{maxWait:uv}),this.api=r.api,this.error$=r.error$,this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()})}log(r){this.requestQueue.push(r),this.isPaused||this.debouncedFlush()}flush(r=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(r?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):r||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class vv{constructor(r){this.offset=void 0,this.offset=r}getOffset(){var r;return(r=this.offset)!==null&&r!==void 0?r:0}setOffset(r){this.offset=r}now(){var r;return Date.now()+((r=this.offset)!==null&&r!==void 0?r:0)}date(r=new Date){var t;return r.setTime(r.getTime()+((t=this.offset)!==null&&t!==void 0?t:0)),r}addServerTime(r,t){const n=Date.now(),o=r-n-t/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const cn=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,"0"),fv=e=>e&&{[T.INVARIANT]:b.UNKNOWN,[T.Q_144P]:b.Q144P,[T.Q_240P]:b.Q240P,[T.Q_360P]:b.Q360P,[T.Q_480P]:b.Q480P,[T.Q_720P]:b.Q720P,[T.Q_1080P]:b.Q1080P,[T.Q_1440P]:b.Q1440P,[T.Q_2160P]:b.Q2160P,[T.Q_4320P]:b.Q4320P}[e],dv=e=>e&&{[ze.HTTP1]:ue.HTTP1,[ze.HTTP2]:ue.HTTP2,[ze.QUIC]:ue.HTTP3}[e],hv=e=>{if(e!==void 0)switch(e){case m.MPEG:return P.MP4;case m.DASH:case m.DASH_LIVE:return P.DASH;case m.DASH_SEP:return P.DASH_SEP;case m.DASH_ONDEMAND:return P.ONDEMAND_DASH;case m.DASH_WEBM:case m.DASH_LIVE_WEBM:return P.WEBM;case m.HLS:case m.HLS_LIVE:return P.HLS;case m.HLS_ONDEMAND:return P.ONDEMAND_HLS;case m.WEB_RTC_LIVE:return P.RTMP;default:return _o(e)}};class bv{constructor(r,t){var n;this.subscription=new Jr,this.timeSynchronisation=new vv,this.vsid=cn(),this.fieldBlacklist=[],this.statContext=r,this.config=Object.assign(Object.assign({},(n=t.config)!==null&&n!==void 0?n:{}),{requestRetryCount:1});const o=new Io;this.experimental={error$:o};const a=new cv({apiKey:nv,apiBaseUrl:$o[t.apiEnv],apiEnv:t.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new av({apiTransport:a,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new lv({api:this.api,error$:o}),this.subscription.add(wo(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(r){this.statContext=Object.assign(Object.assign({},this.statContext),r)}attachTo(r){let t;return new Jr().add(r.events.started$.subscribe(()=>{this.logStarted({position:r.info.position$.getValue()})})).add(r.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:r.info.position$.getValue()})})).add(r.events.seeked$.subscribe(()=>{this.logSeek()})).add(r.events.willPause$.subscribe(()=>{this.logPause({position:r.info.position$.getValue()})})).add(r.events.willResume$.subscribe(()=>{this.logPlay()})).add(r.events.managedError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.fatalError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.inited$.subscribe(()=>{this.logInited()})).add(r.events.canplay$.subscribe(n=>{this.logReady({time:n})})).add(r.events.firstBytes$.subscribe(n=>{this.logFirstBytes({time:n})})).add(r.events.firstFrame$.subscribe(n=>{this.logFirstFrame({time:n})})).add(r.events.watchCoverageRecord$.subscribe(n=>{this.logWatchCoverageRecord(n)})).add(r.events.watchCoverageLive$.subscribe(n=>{this.logWatchCoverageLive(n)})).add(r.info.isStalled$.subscribe(n=>{n?t=ie():(Xr(t)&&this.logEmptyBuffer({duration:ie()-t}),t=void 0)})).add(r.events.ended$.subscribe(()=>{const n=r.info.throughputEstimation$.getValue();Xr(n)&&this.logDownloadSpeed({speed:n/8})})).add(r.info.hostname$.subscribe(n=>{this.updateContext({cdnHostname:n})})).add(r.info.httpConnectionType$.subscribe(n=>{this.updateContext({connectionType:dv(n)})})).add(r.info.httpConnectionReused$.subscribe(n=>{this.updateContext({connectionReused:n})})).add(r.info.currentQuality$.subscribe(n=>{this.updateContext({quality:fv(n)})})).add(r.info.currentFormat$.subscribe(n=>{this.updateContext({contentType:hv(n)})})).add(r.info.chromecastState$.subscribe(n=>{this.updateContext({destination:n===Ro.CONNECTED?Le.CHROMECAST:Le.SCREEN})}))}authorize(r){return this.api.authorize(r)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=cn()}setFieldBlacklist(r=[]){this.fieldBlacklist=r}logInited(){this.log({operation:"init"})}logReady(r){this.log({operation:"player_ready",param:String(r.time)})}logStarted(r){this.log({operation:"play",param:String(Math.round(r.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(r){this.log({operation:"pause",param:String(Math.round(r.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(r){this.log({operation:"first_bytes",param:String(r.time)})}logFirstFrame(r){this.log({operation:"first_frame",param:String(r.time)})}logError(r){this.log({operation:"error",param:r.errorType})}logWatchCoverageRecord(r){this.log({operation:"watch_coverage_record",param:`${r.start}-${r.end}`}),this.logger.flush(!0)}logWatchCoverageLive(r){const t=r.start+this.timeSynchronisation.getOffset(),n=r.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${t}-${n}`}),this.logger.flush(!0)}logEmptyBuffer(r){this.log({operation:"empty_buffer",param:String(r.duration)})}logDownloadSpeed(r){this.log({operation:"download_speed",param:String(r.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(r){this.log({operation:"adv",param:r})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(r){const t=this.createLogItem(r);this.logger.log(t)}createLogItem({operation:r,param:t}){const n=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?Ue.YES:this.statContext.connectionReused===!1?Ue.NO:void 0,stat_type:this.statContext.autoplay===!0?Me.AUTO:this.statContext.autoplay===!1?Me.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};t!==void 0&&(o.param=t);for(const a of this.fieldBlacklist)delete o[a];return{operation:r,timestamp:n,custom:o}}}export{C as ApiEnv,ue as ConnectionType,P as ContentType,bv as OneStat,b as Quality,Le as ScreenDestination};
6
+ import{ValueSubject as Oo,getExponentialDelay as Po,ErrorCategory as E,now as ie,assertNever as _o,Subscription as Jr,Subject as Io,fromEvent as wo,isNonNullable as Xr}from"@vkontakte/videoplayer-shared/es2015.esm.js";import{VideoQuality as T,HttpConnectionType as ze,VideoFormat as m,ChromecastState as Ro}from"@vkontakte/videoplayer-core/es2015.esm.js";import Ao from"lodash/debounce.js";function N(e,r,t,n){function o(a){return a instanceof t?a:new t(function(i){i(a)})}return new(t||(t=Promise))(function(a,i){function v(c){try{s(n.next(c))}catch(l){i(l)}}function u(c){try{s(n.throw(c))}catch(l){i(l)}}function s(c){c.done?a(c.value):o(c.value).then(v,u)}s((n=n.apply(e,r||[])).next())})}var Zr=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},pe=function(e){return e&&e.Math==Math&&e},p=pe(typeof globalThis=="object"&&globalThis)||pe(typeof window=="object"&&window)||pe(typeof self=="object"&&self)||pe(typeof Zr=="object"&&Zr)||function(){return this}()||Function("return this")(),_=function(e){try{return!!e()}catch(r){return!0}},Co=_,ke=!Co(function(){var e=function(){}.bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),No=ke,un=Function.prototype,et=un.apply,rt=un.call,ln=typeof Reflect=="object"&&Reflect.apply||(No?rt.bind(et):function(){return rt.apply(et,arguments)}),vn=ke,fn=Function.prototype,Er=fn.call,Do=vn&&fn.bind.bind(Er,Er),I=vn?Do:function(e){return function(){return Er.apply(e,arguments)}},hn=I,jo=hn({}.toString),Lo=hn("".slice),Be=function(e){return Lo(jo(e),8,-1)},Mo=Be,Uo=I,dn=function(e){if(Mo(e)==="Function")return Uo(e)},Sr=typeof document=="object"&&document.all,ko=typeof Sr=="undefined"&&Sr!==void 0,pn={all:Sr,IS_HTMLDDA:ko},yn=pn,Bo=yn.all,d=yn.IS_HTMLDDA?function(e){return typeof e=="function"||e===Bo}:function(e){return typeof e=="function"},Lr={},xo=_,re=!xo(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7}),Fo=ke,ye=Function.prototype.call,w=Fo?ye.bind(ye):function(){return ye.apply(ye,arguments)},gn={},$n={}.propertyIsEnumerable,bn=Object.getOwnPropertyDescriptor,Ho=bn&&!$n.call({1:2},1);gn.f=Ho?function(r){var t=bn(this,r);return!!t&&t.enumerable}:$n;var mn=function(e,r){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:r}},Ko=I,qo=_,Wo=Be,Qe=Object,Vo=Ko("".split),Go=qo(function(){return!Qe("z").propertyIsEnumerable(0)})?function(e){return Wo(e)=="String"?Vo(e,""):Qe(e)}:Qe,xe=function(e){return e==null},zo=xe,Qo=TypeError,En=function(e){if(zo(e))throw Qo("Can't call method on "+e);return e},Yo=Go,Jo=En,Xo=function(e){return Yo(Jo(e))},tt=d,Sn=pn,Zo=Sn.all,x=Sn.IS_HTMLDDA?function(e){return typeof e=="object"?e!==null:tt(e)||e===Zo}:function(e){return typeof e=="object"?e!==null:tt(e)},Tn={},Ye=Tn,Je=p,ea=d,nt=function(e){return ea(e)?e:void 0},j=function(e,r){return arguments.length<2?nt(Ye[e])||nt(Je[e]):Ye[e]&&Ye[e][r]||Je[e]&&Je[e][r]},ra=I,Mr=ra({}.isPrototypeOf),Fe=typeof navigator!="undefined"&&String(navigator.userAgent)||"",On=p,Xe=Fe,ot=On.process,at=On.Deno,it=ot&&ot.versions||at&&at.version,st=it&&it.v8,S,we;st&&(S=st.split("."),we=S[0]>0&&S[0]<4?1:+(S[0]+S[1]));!we&&Xe&&(S=Xe.match(/Edge\/(\d+)/),(!S||S[1]>=74)&&(S=Xe.match(/Chrome\/(\d+)/),S&&(we=+S[1])));var Pn=we,ct=Pn,ta=_,_n=!!Object.getOwnPropertySymbols&&!ta(function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&ct&&ct<41}),na=_n,In=na&&!Symbol.sham&&typeof Symbol.iterator=="symbol",oa=j,aa=d,ia=Mr,sa=In,ca=Object,wn=sa?function(e){return typeof e=="symbol"}:function(e){var r=oa("Symbol");return aa(r)&&ia(r.prototype,ca(e))},ua=String,He=function(e){try{return ua(e)}catch(r){return"Object"}},la=d,va=He,fa=TypeError,F=function(e){if(la(e))return e;throw fa(va(e)+" is not a function")},ha=F,da=xe,Ur=function(e,r){var t=e[r];return da(t)?void 0:ha(t)},Ze=w,er=d,rr=x,pa=TypeError,ya=function(e,r){var t,n;if(r==="string"&&er(t=e.toString)&&!rr(n=Ze(t,e))||er(t=e.valueOf)&&!rr(n=Ze(t,e))||r!=="string"&&er(t=e.toString)&&!rr(n=Ze(t,e)))return n;throw pa("Can't convert object to primitive value")},Re={},ga={get exports(){return Re},set exports(e){Re=e}},fe=!0,ut=p,$a=Object.defineProperty,ba=function(e,r){try{$a(ut,e,{value:r,configurable:!0,writable:!0})}catch(t){ut[e]=r}return r},ma=p,Ea=ba,lt="__core-js_shared__",Sa=ma[lt]||Ea(lt,{}),kr=Sa,vt=kr;(ga.exports=function(e,r){return vt[e]||(vt[e]=r!==void 0?r:{})})("versions",[]).push({version:"3.27.2",mode:"pure",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.27.2/LICENSE",source:"https://github.com/zloirock/core-js"});var Ta=En,Oa=Object,Pa=function(e){return Oa(Ta(e))},_a=I,Ia=Pa,wa=_a({}.hasOwnProperty),te=Object.hasOwn||function(r,t){return wa(Ia(r),t)},Ra=I,Aa=0,Ca=Math.random(),Na=Ra(1 .toString),Rn=function(e){return"Symbol("+(e===void 0?"":e)+")_"+Na(++Aa+Ca,36)},Da=p,ja=Re,ft=te,La=Rn,Ma=_n,Ua=In,Y=Da.Symbol,tr=ja("wks"),ka=Ua?Y.for||Y:Y&&Y.withoutSetter||La,R=function(e){return ft(tr,e)||(tr[e]=Ma&&ft(Y,e)?Y[e]:ka("Symbol."+e)),tr[e]},Ba=w,ht=x,dt=wn,xa=Ur,Fa=ya,Ha=R,Ka=TypeError,qa=Ha("toPrimitive"),Wa=function(e,r){if(!ht(e)||dt(e))return e;var t=xa(e,qa),n;if(t){if(r===void 0&&(r="default"),n=Ba(t,e,r),!ht(n)||dt(n))return n;throw Ka("Can't convert object to primitive value")}return r===void 0&&(r="number"),Fa(e,r)},Va=Wa,Ga=wn,An=function(e){var r=Va(e,"string");return Ga(r)?r:r+""},za=p,pt=x,Tr=za.document,Qa=pt(Tr)&&pt(Tr.createElement),Cn=function(e){return Qa?Tr.createElement(e):{}},Ya=re,Ja=_,Xa=Cn,Nn=!Ya&&!Ja(function(){return Object.defineProperty(Xa("div"),"a",{get:function(){return 7}}).a!=7}),Za=re,ei=w,ri=gn,ti=mn,ni=Xo,oi=An,ai=te,ii=Nn,yt=Object.getOwnPropertyDescriptor;Lr.f=Za?yt:function(r,t){if(r=ni(r),t=oi(t),ii)try{return yt(r,t)}catch(n){}if(ai(r,t))return ti(!ei(ri.f,r,t),r[t])};var si=_,ci=d,ui=/#|\.prototype\./,he=function(e,r){var t=vi[li(e)];return t==hi?!0:t==fi?!1:ci(r)?si(r):!!r},li=he.normalize=function(e){return String(e).replace(ui,".").toLowerCase()},vi=he.data={},fi=he.NATIVE="N",hi=he.POLYFILL="P",Dn=he,gt=dn,di=F,pi=ke,yi=gt(gt.bind),Ke=function(e,r){return di(e),r===void 0?e:pi?yi(e,r):function(){return e.apply(r,arguments)}},qe={},gi=re,$i=_,bi=gi&&$i(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42}),mi=x,Ei=String,Si=TypeError,H=function(e){if(mi(e))return e;throw Si(Ei(e)+" is not an object")},Ti=re,Oi=Nn,Pi=bi,ge=H,$t=An,_i=TypeError,nr=Object.defineProperty,Ii=Object.getOwnPropertyDescriptor,or="enumerable",ar="configurable",ir="writable";qe.f=Ti?Pi?function(r,t,n){if(ge(r),t=$t(t),ge(n),typeof r=="function"&&t==="prototype"&&"value"in n&&ir in n&&!n[ir]){var o=Ii(r,t);o&&o[ir]&&(r[t]=n.value,n={configurable:ar in n?n[ar]:o[ar],enumerable:or in n?n[or]:o[or],writable:!1})}return nr(r,t,n)}:nr:function(r,t,n){if(ge(r),t=$t(t),ge(n),Oi)try{return nr(r,t,n)}catch(o){}if("get"in n||"set"in n)throw _i("Accessors not supported");return"value"in n&&(r[t]=n.value),r};var wi=re,Ri=qe,Ai=mn,We=wi?function(e,r,t){return Ri.f(e,r,Ai(1,t))}:function(e,r,t){return e[r]=t,e},$e=p,Ci=ln,Ni=dn,Di=d,ji=Lr.f,Li=Dn,W=Tn,Mi=Ke,V=We,bt=te,Ui=function(e){var r=function(t,n,o){if(this instanceof r){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,o)}return Ci(e,this,arguments)};return r.prototype=e.prototype,r},K=function(e,r){var t=e.target,n=e.global,o=e.stat,a=e.proto,i=n?$e:o?$e[t]:($e[t]||{}).prototype,v=n?W:W[t]||V(W,t,{})[t],u=v.prototype,s,c,l,h,f,b,L,A,q;for(h in r)s=Li(n?h:t+(o?".":"#")+h,e.forced),c=!s&&i&&bt(i,h),b=v[h],c&&(e.dontCallGetSet?(q=ji(i,h),L=q&&q.value):L=i[h]),f=c&&L?L:r[h],!(c&&typeof b==typeof f)&&(e.bind&&c?A=Mi(f,$e):e.wrap&&c?A=Ui(f):a&&Di(f)?A=Ni(f):A=f,(e.sham||f&&f.sham||b&&b.sham)&&V(A,"sham",!0),V(v,h,A),a&&(l=t+"Prototype",bt(W,l)||V(W,l,{}),V(W[l],h,f),e.real&&u&&(s||!u[h])&&V(u,h,f)))},ki=Be,Ve=typeof process!="undefined"&&ki(process)=="process",Bi=We,Br=function(e,r,t,n){return n&&n.enumerable?e[r]=t:Bi(e,r,t),e},xi=d,Fi=String,Hi=TypeError,Ki=function(e){if(typeof e=="object"||xi(e))return e;throw Hi("Can't set "+Fi(e)+" as a prototype")},qi=I,Wi=H,Vi=Ki,Gi=Object.setPrototypeOf||("__proto__"in{}?function(){var e=!1,r={},t;try{t=qi(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set),t(r,[]),e=r instanceof Array}catch(n){}return function(o,a){return Wi(o),Vi(a),e?t(o,a):o.__proto__=a,o}}():void 0),zi=R,Qi=zi("toStringTag"),jn={};jn[Qi]="z";var xr=String(jn)==="[object z]",Yi=xr,Ji=d,Pe=Be,Xi=R,Zi=Xi("toStringTag"),es=Object,rs=Pe(function(){return arguments}())=="Arguments",ts=function(e,r){try{return e[r]}catch(t){}},Fr=Yi?Pe:function(e){var r,t,n;return e===void 0?"Undefined":e===null?"Null":typeof(t=ts(r=es(e),Zi))=="string"?t:rs?Pe(r):(n=Pe(r))=="Object"&&Ji(r.callee)?"Arguments":n},ns=xr,os=Fr,as=ns?{}.toString:function(){return"[object "+os(this)+"]"},is=xr,ss=qe.f,cs=We,us=te,ls=as,vs=R,mt=vs("toStringTag"),fs=function(e,r,t,n){if(e){var o=t?e:e.prototype;us(o,mt)||ss(o,mt,{configurable:!0,value:r}),n&&!is&&cs(o,"toString",ls)}},hs=j,ds=qe,ps=R,ys=re,Et=ps("species"),gs=function(e){var r=hs(e),t=ds.f;ys&&r&&!r[Et]&&t(r,Et,{configurable:!0,get:function(){return this}})},$s=Mr,bs=TypeError,ms=function(e,r){if($s(r,e))return e;throw bs("Incorrect invocation")},Es=I,Ss=d,Or=kr,Ts=Es(Function.toString);Ss(Or.inspectSource)||(Or.inspectSource=function(e){return Ts(e)});var Ln=Or.inspectSource,Os=I,Ps=_,Mn=d,_s=Fr,Is=j,ws=Ln,Un=function(){},Rs=[],kn=Is("Reflect","construct"),Hr=/^\s*(?:class|function)\b/,As=Os(Hr.exec),Cs=!Hr.exec(Un),ae=function(r){if(!Mn(r))return!1;try{return kn(Un,Rs,r),!0}catch(t){return!1}},Bn=function(r){if(!Mn(r))return!1;switch(_s(r)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Cs||!!As(Hr,ws(r))}catch(t){return!0}};Bn.sham=!0;var Ns=!kn||Ps(function(){var e;return ae(ae.call)||!ae(Object)||!ae(function(){e=!0})||e})?Bn:ae,Ds=Ns,js=He,Ls=TypeError,Ms=function(e){if(Ds(e))return e;throw Ls(js(e)+" is not a constructor")},St=H,Us=Ms,ks=xe,Bs=R,xs=Bs("species"),xn=function(e,r){var t=St(e).constructor,n;return t===void 0||ks(n=St(t)[xs])?r:Us(n)},Fs=j,Hs=Fs("document","documentElement"),Ks=I,qs=Ks([].slice),Ws=TypeError,Vs=function(e,r){if(e<r)throw Ws("Not enough arguments");return e},Gs=Fe,Fn=/(?:ipad|iphone|ipod).*applewebkit/i.test(Gs),y=p,zs=ln,Qs=Ke,Tt=d,Ys=te,Hn=_,Ot=Hs,Js=qs,Pt=Cn,Xs=Vs,Zs=Fn,ec=Ve,Pr=y.setImmediate,_r=y.clearImmediate,rc=y.process,sr=y.Dispatch,tc=y.Function,_t=y.MessageChannel,nc=y.String,cr=0,se={},It="onreadystatechange",le,M,ur,lr;Hn(function(){le=y.location});var Kr=function(e){if(Ys(se,e)){var r=se[e];delete se[e],r()}},vr=function(e){return function(){Kr(e)}},wt=function(e){Kr(e.data)},Rt=function(e){y.postMessage(nc(e),le.protocol+"//"+le.host)};(!Pr||!_r)&&(Pr=function(r){Xs(arguments.length,1);var t=Tt(r)?r:tc(r),n=Js(arguments,1);return se[++cr]=function(){zs(t,void 0,n)},M(cr),cr},_r=function(r){delete se[r]},ec?M=function(e){rc.nextTick(vr(e))}:sr&&sr.now?M=function(e){sr.now(vr(e))}:_t&&!Zs?(ur=new _t,lr=ur.port2,ur.port1.onmessage=wt,M=Qs(lr.postMessage,lr)):y.addEventListener&&Tt(y.postMessage)&&!y.importScripts&&le&&le.protocol!=="file:"&&!Hn(Rt)?(M=Rt,y.addEventListener("message",wt,!1)):It in Pt("script")?M=function(e){Ot.appendChild(Pt("script"))[It]=function(){Ot.removeChild(this),Kr(e)}}:M=function(e){setTimeout(vr(e),0)});var Kn={set:Pr,clear:_r},qn=function(){this.head=null,this.tail=null};qn.prototype={add:function(e){var r={item:e,next:null},t=this.tail;t?t.next=r:this.head=r,this.tail=r},get:function(){var e=this.head;if(e){var r=this.head=e.next;return r===null&&(this.tail=null),e.item}}};var Wn=qn,oc=Fe,ac=/ipad|iphone|ipod/i.test(oc)&&typeof Pebble!="undefined",ic=Fe,sc=/web0s(?!.*chrome)/i.test(ic),B=p,At=Ke,cc=Lr.f,fr=Kn.set,uc=Wn,lc=Fn,vc=ac,fc=sc,hr=Ve,Ct=B.MutationObserver||B.WebKitMutationObserver,Nt=B.document,Dt=B.process,be=B.Promise,jt=cc(B,"queueMicrotask"),Ir=jt&&jt.value,G,dr,pr,me,Lt;if(!Ir){var Ee=new uc,Se=function(){var e,r;for(hr&&(e=Dt.domain)&&e.exit();r=Ee.get();)try{r()}catch(t){throw Ee.head&&G(),t}e&&e.enter()};!lc&&!hr&&!fc&&Ct&&Nt?(dr=!0,pr=Nt.createTextNode(""),new Ct(Se).observe(pr,{characterData:!0}),G=function(){pr.data=dr=!dr}):!vc&&be&&be.resolve?(me=be.resolve(void 0),me.constructor=be,Lt=At(me.then,me),G=function(){Lt(Se)}):hr?G=function(){Dt.nextTick(Se)}:(fr=At(fr,B),G=function(){fr(Se)}),Ir=function(e){Ee.head||G(),Ee.add(e)}}var hc=Ir,dc=function(e,r){try{arguments.length==1?console.error(e):console.error(e,r)}catch(t){}},qr=function(e){try{return{error:!1,value:e()}}catch(r){return{error:!0,value:r}}},pc=p,yc=d,Mt=pc.WeakMap,gc=yc(Mt)&&/native code/.test(String(Mt)),$c=Re,bc=Rn,Ut=$c("keys"),mc=function(e){return Ut[e]||(Ut[e]=bc(e))},Ec={},Sc=gc,Vn=p,Tc=x,Oc=We,yr=te,gr=kr,Pc=mc,_c=Ec,kt="Object already initialized",wr=Vn.TypeError,Ic=Vn.WeakMap,Ae,ve,Ce,wc=function(e){return Ce(e)?ve(e):Ae(e,{})},Rc=function(e){return function(r){var t;if(!Tc(r)||(t=ve(r)).type!==e)throw wr("Incompatible receiver, "+e+" required");return t}};if(Sc||gr.state){var O=gr.state||(gr.state=new Ic);O.get=O.get,O.has=O.has,O.set=O.set,Ae=function(e,r){if(O.has(e))throw wr(kt);return r.facade=e,O.set(e,r),r},ve=function(e){return O.get(e)||{}},Ce=function(e){return O.has(e)}}else{var z=Pc("state");_c[z]=!0,Ae=function(e,r){if(yr(e,z))throw wr(kt);return r.facade=e,Oc(e,z,r),r},ve=function(e){return yr(e,z)?e[z]:{}},Ce=function(e){return yr(e,z)}}var Ac={set:Ae,get:ve,has:Ce,enforce:wc,getterFor:Rc},Cc=p,ne=Cc.Promise,Gn=typeof Deno=="object"&&Deno&&typeof Deno.version=="object",Nc=Gn,Dc=Ve,jc=!Nc&&!Dc&&typeof window=="object"&&typeof document=="object",Lc=p,ce=ne,Mc=d,Uc=Dn,kc=Ln,Bc=R,xc=jc,Fc=Gn,Hc=fe,$r=Pn,Bt=ce&&ce.prototype,Kc=Bc("species"),Rr=!1,zn=Mc(Lc.PromiseRejectionEvent),qc=Uc("Promise",function(){var e=kc(ce),r=e!==String(ce);if(!r&&$r===66||Hc&&!(Bt.catch&&Bt.finally))return!0;if(!$r||$r<51||!/native code/.test(e)){var t=new ce(function(a){a(1)}),n=function(a){a(function(){},function(){})},o=t.constructor={};if(o[Kc]=n,Rr=t.then(function(){})instanceof n,!Rr)return!0}return!r&&(xc||Fc)&&!zn}),de={CONSTRUCTOR:qc,REJECTION_EVENT:zn,SUBCLASSING:Rr},oe={},xt=F,Wc=TypeError,Vc=function(e){var r,t;this.promise=new e(function(n,o){if(r!==void 0||t!==void 0)throw Wc("Bad Promise constructor");r=n,t=o}),this.resolve=xt(r),this.reject=xt(t)};oe.f=function(e){return new Vc(e)};var Gc=K,zc=fe,Ne=Ve,D=p,Z=w,Ft=Br,Ht=Gi,Qc=fs,Yc=gs,Jc=F,_e=d,Xc=x,Zc=ms,eu=xn,Qn=Kn.set,Wr=hc,ru=dc,tu=qr,nu=Wn,Yn=Ac,De=ne,Vr=de,Jn=oe,Ge="Promise",Xn=Vr.CONSTRUCTOR,ou=Vr.REJECTION_EVENT,au=Vr.SUBCLASSING,br=Yn.getterFor(Ge),iu=Yn.set,Q=De&&De.prototype,U=De,Te=Q,Zn=D.TypeError,Ar=D.document,Gr=D.process,Cr=Jn.f,su=Cr,cu=!!(Ar&&Ar.createEvent&&D.dispatchEvent),eo="unhandledrejection",uu="rejectionhandled",Kt=0,ro=1,lu=2,zr=1,to=2,Oe,qt,vu,Wt,no=function(e){var r;return Xc(e)&&_e(r=e.then)?r:!1},oo=function(e,r){var t=r.value,n=r.state==ro,o=n?e.ok:e.fail,a=e.resolve,i=e.reject,v=e.domain,u,s,c;try{o?(n||(r.rejection===to&&hu(r),r.rejection=zr),o===!0?u=t:(v&&v.enter(),u=o(t),v&&(v.exit(),c=!0)),u===e.promise?i(Zn("Promise-chain cycle")):(s=no(u))?Z(s,u,a,i):a(u)):i(t)}catch(l){v&&!c&&v.exit(),i(l)}},ao=function(e,r){e.notified||(e.notified=!0,Wr(function(){for(var t=e.reactions,n;n=t.get();)oo(n,e);e.notified=!1,r&&!e.rejection&&fu(e)}))},io=function(e,r,t){var n,o;cu?(n=Ar.createEvent("Event"),n.promise=r,n.reason=t,n.initEvent(e,!1,!0),D.dispatchEvent(n)):n={promise:r,reason:t},!ou&&(o=D["on"+e])?o(n):e===eo&&ru("Unhandled promise rejection",t)},fu=function(e){Z(Qn,D,function(){var r=e.facade,t=e.value,n=Vt(e),o;if(n&&(o=tu(function(){Ne?Gr.emit("unhandledRejection",t,r):io(eo,r,t)}),e.rejection=Ne||Vt(e)?to:zr,o.error))throw o.value})},Vt=function(e){return e.rejection!==zr&&!e.parent},hu=function(e){Z(Qn,D,function(){var r=e.facade;Ne?Gr.emit("rejectionHandled",r):io(uu,r,e.value)})},J=function(e,r,t){return function(n){e(r,n,t)}},X=function(e,r,t){e.done||(e.done=!0,t&&(e=t),e.value=r,e.state=lu,ao(e,!0))},Nr=function(e,r,t){if(!e.done){e.done=!0,t&&(e=t);try{if(e.facade===r)throw Zn("Promise can't be resolved itself");var n=no(r);n?Wr(function(){var o={done:!1};try{Z(n,r,J(Nr,o,e),J(X,o,e))}catch(a){X(o,a,e)}}):(e.value=r,e.state=ro,ao(e,!1))}catch(o){X({done:!1},o,e)}}};if(Xn&&(U=function(r){Zc(this,Te),Jc(r),Z(Oe,this);var t=br(this);try{r(J(Nr,t),J(X,t))}catch(n){X(t,n)}},Te=U.prototype,Oe=function(r){iu(this,{type:Ge,done:!1,notified:!1,parent:!1,reactions:new nu,rejection:!1,state:Kt,value:void 0})},Oe.prototype=Ft(Te,"then",function(r,t){var n=br(this),o=Cr(eu(this,U));return n.parent=!0,o.ok=_e(r)?r:!0,o.fail=_e(t)&&t,o.domain=Ne?Gr.domain:void 0,n.state==Kt?n.reactions.add(o):Wr(function(){oo(o,n)}),o.promise}),qt=function(){var e=new Oe,r=br(e);this.promise=e,this.resolve=J(Nr,r),this.reject=J(X,r)},Jn.f=Cr=function(e){return e===U||e===vu?new qt(e):su(e)},!zc&&_e(De)&&Q!==Object.prototype)){Wt=Q.then,au||Ft(Q,"then",function(r,t){var n=this;return new U(function(o,a){Z(Wt,n,o,a)}).then(r,t)},{unsafe:!0});try{delete Q.constructor}catch(e){}Ht&&Ht(Q,Te)}Gc({global:!0,constructor:!0,wrap:!0,forced:Xn},{Promise:U});Qc(U,Ge,!1,!0);Yc(Ge);var so={},du=R,pu=so,yu=du("iterator"),gu=Array.prototype,$u=function(e){return e!==void 0&&(pu.Array===e||gu[yu]===e)},bu=Math.ceil,mu=Math.floor,Eu=Math.trunc||function(r){var t=+r;return(t>0?mu:bu)(t)},Su=Eu,Tu=function(e){var r=+e;return r!==r||r===0?0:Su(r)},Ou=Tu,Pu=Math.min,_u=function(e){return e>0?Pu(Ou(e),9007199254740991):0},Iu=_u,wu=function(e){return Iu(e.length)},Ru=Fr,Gt=Ur,Au=xe,Cu=so,Nu=R,Du=Nu("iterator"),co=function(e){if(!Au(e))return Gt(e,Du)||Gt(e,"@@iterator")||Cu[Ru(e)]},ju=w,Lu=F,Mu=H,Uu=He,ku=co,Bu=TypeError,xu=function(e,r){var t=arguments.length<2?ku(e):r;if(Lu(t))return Mu(ju(t,e));throw Bu(Uu(e)+" is not iterable")},Fu=w,zt=H,Hu=Ur,Ku=function(e,r,t){var n,o;zt(e);try{if(n=Hu(e,"return"),!n){if(r==="throw")throw t;return t}n=Fu(n,e)}catch(a){o=!0,n=a}if(r==="throw")throw t;if(o)throw n;return zt(n),t},qu=Ke,Wu=w,Vu=H,Gu=He,zu=$u,Qu=wu,Qt=Mr,Yu=xu,Ju=co,Yt=Ku,Xu=TypeError,Ie=function(e,r){this.stopped=e,this.result=r},Jt=Ie.prototype,uo=function(e,r,t){var n=t&&t.that,o=!!(t&&t.AS_ENTRIES),a=!!(t&&t.IS_RECORD),i=!!(t&&t.IS_ITERATOR),v=!!(t&&t.INTERRUPTED),u=qu(r,n),s,c,l,h,f,b,L,A=function(g){return s&&Yt(s,"normal",g),new Ie(!0,g)},q=function(g){return o?(Vu(g),v?u(g[0],g[1],A):u(g[0],g[1])):v?u(g,A):u(g)};if(a)s=e.iterator;else if(i)s=e;else{if(c=Ju(e),!c)throw Xu(Gu(e)+" is not iterable");if(zu(c)){for(l=0,h=Qu(e);h>l;l++)if(f=q(e[l]),f&&Qt(Jt,f))return f;return new Ie(!1)}s=Yu(e,c)}for(b=a?e.next:s.next;!(L=Wu(b,s)).done;){try{f=q(L.value)}catch(g){Yt(s,"throw",g)}if(typeof f=="object"&&f&&Qt(Jt,f))return f}return new Ie(!1)},Zu=R,lo=Zu("iterator"),vo=!1;try{var el=0,Xt={next:function(){return{done:!!el++}},return:function(){vo=!0}};Xt[lo]=function(){return this},Array.from(Xt,function(){throw 2})}catch(e){}var rl=function(e,r){if(!r&&!vo)return!1;var t=!1;try{var n={};n[lo]=function(){return{next:function(){return{done:t=!0}}}},e(n)}catch(o){}return t},tl=ne,nl=rl,ol=de.CONSTRUCTOR,fo=ol||!nl(function(e){tl.all(e).then(void 0,function(){})}),al=K,il=w,sl=F,cl=oe,ul=qr,ll=uo,vl=fo;al({target:"Promise",stat:!0,forced:vl},{all:function(r){var t=this,n=cl.f(t),o=n.resolve,a=n.reject,i=ul(function(){var v=sl(t.resolve),u=[],s=0,c=1;ll(r,function(l){var h=s++,f=!1;c++,il(v,t,l).then(function(b){f||(f=!0,u[h]=b,--c||o(u))},a)}),--c||o(u)});return i.error&&a(i.value),n.promise}});var fl=K,hl=fe,dl=de.CONSTRUCTOR,Dr=ne,pl=j,yl=d,gl=Br,Zt=Dr&&Dr.prototype;fl({target:"Promise",proto:!0,forced:dl,real:!0},{catch:function(e){return this.then(void 0,e)}});if(!hl&&yl(Dr)){var en=pl("Promise").prototype.catch;Zt.catch!==en&&gl(Zt,"catch",en,{unsafe:!0})}var $l=K,bl=w,ml=F,El=oe,Sl=qr,Tl=uo,Ol=fo;$l({target:"Promise",stat:!0,forced:Ol},{race:function(r){var t=this,n=El.f(t),o=n.reject,a=Sl(function(){var i=ml(t.resolve);Tl(r,function(v){bl(i,t,v).then(n.resolve,o)})});return a.error&&o(a.value),n.promise}});var Pl=K,_l=w,Il=oe,wl=de.CONSTRUCTOR;Pl({target:"Promise",stat:!0,forced:wl},{reject:function(r){var t=Il.f(this);return _l(t.reject,void 0,r),t.promise}});var Rl=H,Al=x,Cl=oe,ho=function(e,r){if(Rl(e),Al(r)&&r.constructor===e)return r;var t=Cl.f(e),n=t.resolve;return n(r),t.promise},Nl=K,Dl=j,po=fe,jl=ne,yo=de.CONSTRUCTOR,Ll=ho,Ml=Dl("Promise"),Ul=po&&!yo;Nl({target:"Promise",stat:!0,forced:po||yo},{resolve:function(r){return Ll(Ul&&this===Ml?jl:this,r)}});var kl=K,Bl=fe,je=ne,xl=_,go=j,$o=d,Fl=xn,rn=ho,Hl=Br,jr=je&&je.prototype,Kl=!!je&&xl(function(){jr.finally.call({then:function(){}},function(){})});kl({target:"Promise",proto:!0,real:!0,forced:Kl},{finally:function(e){var r=Fl(this,go("Promise")),t=$o(e);return this.then(t?function(n){return rn(r,e()).then(function(){return n})}:e,t?function(n){return rn(r,e()).then(function(){throw n})}:e)}});if(!Bl&&$o(je)){var tn=go("Promise").prototype.finally;jr.finally!==tn&&Hl(jr,"finally",tn,{unsafe:!0})}var ql=j,Wl=ql,Vl=Wl,Gl=Vl("Promise","finally"),zl=Gl,Ql=zl,Yl=Ql,Jl=Yl,mr=Jl;const Qr="_one-stat_",ee=(()=>{try{const e=Date.now().toString(),r=window.localStorage;r.setItem(e,e);const t=r.getItem(e)===e;return r.removeItem(e),t?r:null}catch(e){return null}})();function Xl(e){const r=ee?ee.getItem(Qr+e):null;if(r===null)return null;try{return JSON.parse(r)}catch(t){return null}}function Zl(e,r){try{ee&&ee.setItem(Qr+e,JSON.stringify(r))}catch(t){}}function ev(e){ee&&ee.removeItem(Qr+e)}var nn={get(e){return Xl(e)||null},set(e,r){Zl(e,r)},remove(e){ev(e)}};function rv(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=new Array(36);let t=0,n,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?r[o]="-":o===14?r[o]="4":(t<=2&&(t=33554432+Math.random()*16777216|0),n=t&15,t=t>>4,r[o]=e[o===19?n&3|8:n]);return r.join("")}var C;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(C||(C={}));var $;(function(e){e.Q144P="144",e.Q240P="240",e.Q360P="360",e.Q480P="480",e.Q720P="720",e.Q1080P="1080",e.Q1440P="1440",e.Q2160P="2160",e.Q4320P="4320",e.UNKNOWN="unknown"})($||($={}));var Le;(function(e){e.CHROMECAST="chromecast",e.APPLE_TV="appletv",e.PIP="pip",e.HEADPHONES="externalHeadphones",e.SCREEN=""})(Le||(Le={}));var P;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.RTMP="rtmp",e.UNKNOWN="unknown"})(P||(P={}));var Me;(function(e){e.AUTO="auto",e.MANUAL=""})(Me||(Me={}));var ue;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(ue||(ue={}));var Ue;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(Ue||(Ue={}));const on="1.0.31",tv="@vkontakte/videoplayer-statistics",nv="CIOPGQJGDIHBABABA",bo={[C.PROD]:"https://api.ok.ru",[C.VK_ALIAS]:"https://api.mycdn.me",[C.VIDEOTEST]:"https://videotestapi.ok.ru/api",[C.TEST]:"https://apitest.ok.ru",[C.AUTO]:""},ov={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var k;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(k||(k={}));class av{constructor(r){this.consequentAuthErrors=0,this.authorized$=new Oo(!1),this.params=r;const t=nn.get("uuid");t?this.uuid=String(t):(this.uuid=rv(),nn.set("uuid",this.uuid))}authorize(r){return N(this,void 0,void 0,function*(){return this.authToken=r!=null?r:yield this.refreshAuthToken(),this._authorizeWithBackoff()})}logBeacon(r){const t="log.externalLog",n=this.createLogParams(r),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(t,n,o)||this.logRequest(r)}logRequest(r){var t;return N(this,void 0,void 0,function*(){const n="log.externalLog",o=this.createLogParams(r),a=(t=this.sessionKey)!==null&&t!==void 0?t:yield this._authorizeWithBackoff();if(!a)return;const i=(v,u=this.params.requestRetryCount)=>N(this,void 0,void 0,function*(){try{return yield this.params.apiTransport.sendRequest(n,o,a)}catch(s){if(!s||!("error_code"in s)){this.params.error$.next({id:"logRequestUnknown",category:E.NETWORK,message:`Unknown ${n} error`,thrown:s});return}const c=s==null?void 0:s.error_code;switch(c){case k.PARAM_SESSION_EXPIRED:case k.PARAM_SESSION_KEY:case k.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;case k.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),u>0?i(v,u-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:E.EXTERNAL_API,message:`${n} error`,data:s});return}}}});return i(r)})}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return N(this,void 0,void 0,function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=mr(this.params.refreshAuthToken(),()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise})}createLogParams(r){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${tv}:${on}`,platform:"WEB",items:r.map(t=>Object.assign(Object.assign({},t),{time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const r=Po(this.consequentAuthErrors,ov);return new Promise(t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{mr(this._authorize().then(t).catch(n=>this.params.error$.next({id:"AuthorizeBackoff",category:E.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:n})),()=>this.backoffTimeoutId=0)},r))})}_authorize(){return N(this,void 0,void 0,function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const r="auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:on.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=mr(this.params.apiTransport.sendRequest(r,t).then(n=>{var o;return(!n||!n.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:E.EXTERNAL_API,message:"No session key",data:n}),this.sessionKey=(o=n==null?void 0:n.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(n=>N(this,void 0,void 0,function*(){this.sessionKey=void 0;const o=n==null?void 0:n.error_code;switch(o){case k.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:E.EXTERNAL_API,message:"authorize error",data:n}):this.params.error$.next({id:"AuthorizeUnknown",category:E.NETWORK,message:"authorize error",thrown:n})})),()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise})}}class an{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(r,t,n){r in this.listeners||(this.listeners[r]=[]),this.listeners[r].push({callback:t,options:n})}removeEventListener(r,t){if(!(r in this.listeners))return;const n=this.listeners[r];for(let o=0,a=n.length;o<a;o++)if(n[o].callback===t){n.splice(o,1);return}}dispatchEvent(r){if(!(r.type in this.listeners))return;const n=this.listeners[r.type].slice();for(let o=0,a=n.length;o<a;o++){const i=n[o];try{i.callback.call(this,r)}catch(v){Promise.resolve().then(()=>{throw v})}i.options&&i.options.once&&this.removeEventListener(r.type,i.callback)}return!r.defaultPrevented}}class mo extends an{constructor(){super(),this.listeners||an.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(r){r.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,r)),super.dispatchEvent(r)}}class iv{constructor(){Object.defineProperty(this,"signal",{value:new mo,writable:!0,configurable:!0})}abort(r){let t;try{t=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let n=r;if(n===void 0)if(typeof document=="undefined")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch(o){n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(iv.prototype[Symbol.toStringTag]="AbortController",mo.prototype[Symbol.toStringTag]="AbortSignal");function Eo(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function sv(e){typeof e=="function"&&(e={fetch:e});const{fetch:r,Request:t=r.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=e;if(!Eo({fetch:r,Request:t,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:r,Request:a};let a=t;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(s,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const h=new t(s,c);return l&&Object.defineProperty(h,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),h},a.prototype=t.prototype);const i=r;return{fetch:(u,s)=>{const c=a&&a.prototype.isPrototypeOf(u)?u.signal:s?s.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(f){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const h=new Promise((f,b)=>{c.addEventListener("abort",()=>b(l),{once:!0})});return s&&s.signal&&delete s.signal,Promise.race([h,i(u,s)])}return i(u,s)},Request:a}}const Yr=Eo({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),So=Yr?sv({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,sn=Yr?So.fetch:window.fetch;Yr?So.Request:window.Request;class cv{constructor(r){this.params=r,this.apiKey=r.apiKey,this.apiEnv=r.apiEnv,this.apiBaseUrl=r.apiBaseUrl,this.timeSynchronisation=r.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var r;return N(this,void 0,void 0,function*(){if(this.apiEnv!==C.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=yield(yield sn(t,{method:"GET",mode:"cors",cache:"no-cache"})).json(),a=(r=o==null?void 0:o.Answer[0])===null||r===void 0?void 0:r.data;if(!a)throw new Error("Wrong DNS response");return a}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:E.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),bo[C.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}})}sendBeacon(r,t,n){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:r,queryParams:t,sessionKey:n}),a=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,a)}catch(i){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:E.NETWORK,message:"Unhandled beacon error",thrown:i,data:{method:r,params:t}})}return!1}sendRequest(r,t,n){return N(this,void 0,void 0,function*(){const o=ie(),a=i=>{if(i instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(i.message)){this.params.error$.next({id:"Network",category:E.NETWORK,message:"Request failed",thrown:i});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:E.NETWORK,message:"Unhandled request error",thrown:i,data:{method:r,params:t,sessionKey:n,time:ie()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),sn(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:r,queryParams:t,sessionKey:n})}).then(i=>{var v;const u=Number(i.headers.get("content-length"))===0,s=new Date((v=i.headers.get("date"))!==null&&v!==void 0?v:"").getTime(),c=ie()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,c),!u)return i.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,a)},a)})}_prepareQueryParams(r){const t=new URLSearchParams({format:"JSON",method:r.method,application_key:this.apiKey});return r.sessionKey!==void 0&&t.append("session_key",r.sessionKey),Object.entries(r.queryParams).forEach(([n,o])=>t.append(n,typeof o=="string"?o:JSON.stringify(o))),t}}const To=3e3,uv=To*5;class lv{constructor(r){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=Ao(()=>{var t;try{this.flush()}catch(n){this.error$.next({id:"LoggerError",category:E.WTF,message:(t=String(n))!==null&&t!==void 0?t:"Unknown logger error",thrown:n})}},To,{maxWait:uv}),this.api=r.api,this.error$=r.error$,this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()})}log(r){this.requestQueue.push(r),this.isPaused||this.debouncedFlush()}flush(r=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(r?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):r||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class vv{constructor(r){this.offset=void 0,this.offset=r}getOffset(){var r;return(r=this.offset)!==null&&r!==void 0?r:0}setOffset(r){this.offset=r}now(){var r;return Date.now()+((r=this.offset)!==null&&r!==void 0?r:0)}date(r=new Date){var t;return r.setTime(r.getTime()+((t=this.offset)!==null&&t!==void 0?t:0)),r}addServerTime(r,t){const n=Date.now(),o=r-n-t/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const cn=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,"0"),fv=e=>e&&{[T.INVARIANT]:$.UNKNOWN,[T.Q_144P]:$.Q144P,[T.Q_240P]:$.Q240P,[T.Q_360P]:$.Q360P,[T.Q_480P]:$.Q480P,[T.Q_720P]:$.Q720P,[T.Q_1080P]:$.Q1080P,[T.Q_1440P]:$.Q1440P,[T.Q_2160P]:$.Q2160P,[T.Q_4320P]:$.Q4320P}[e],hv=e=>e&&{[ze.HTTP1]:ue.HTTP1,[ze.HTTP2]:ue.HTTP2,[ze.QUIC]:ue.HTTP3}[e],dv=e=>{if(e!==void 0)switch(e){case m.MPEG:return P.MP4;case m.DASH:case m.DASH_LIVE:return P.DASH;case m.DASH_SEP:return P.DASH_SEP;case m.DASH_ONDEMAND:return P.ONDEMAND_DASH;case m.DASH_WEBM:case m.DASH_LIVE_WEBM:return P.WEBM;case m.HLS:case m.HLS_LIVE:return P.HLS;case m.HLS_ONDEMAND:return P.ONDEMAND_HLS;case m.WEB_RTC_LIVE:return P.RTMP;default:return _o(e)}};class $v{constructor(r,t){var n;this.subscription=new Jr,this.timeSynchronisation=new vv,this.vsid=cn(),this.fieldBlacklist=[],this.statContext=r,this.config=Object.assign(Object.assign({},(n=t.config)!==null&&n!==void 0?n:{}),{requestRetryCount:1});const o=new Io;this.experimental={error$:o};const a=new cv({apiKey:nv,apiBaseUrl:bo[t.apiEnv],apiEnv:t.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new av({apiTransport:a,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new lv({api:this.api,error$:o}),this.subscription.add(wo(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(r){this.statContext=Object.assign(Object.assign({},this.statContext),r)}attachTo(r){let t;return new Jr().add(r.events.started$.subscribe(()=>{this.logStarted({position:r.info.position$.getValue()})})).add(r.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:r.info.position$.getValue()})})).add(r.events.seeked$.subscribe(()=>{this.logSeek()})).add(r.events.willPause$.subscribe(()=>{this.logPause({position:r.info.position$.getValue()})})).add(r.events.willResume$.subscribe(()=>{this.logPlay()})).add(r.events.managedError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.fatalError$.subscribe(({id:n})=>{this.logError({errorType:n})})).add(r.events.inited$.subscribe(()=>{this.logInited()})).add(r.events.canplay$.subscribe(n=>{this.logReady({time:n})})).add(r.events.firstBytes$.subscribe(n=>{this.logFirstBytes({time:n})})).add(r.events.firstFrame$.subscribe(n=>{this.logFirstFrame({time:n})})).add(r.events.watchCoverageRecord$.subscribe(n=>{this.logWatchCoverageRecord(n)})).add(r.events.watchCoverageLive$.subscribe(n=>{this.logWatchCoverageLive(n)})).add(r.info.isStalled$.subscribe(n=>{n?t=ie():(Xr(t)&&this.logEmptyBuffer({duration:ie()-t}),t=void 0)})).add(r.events.ended$.subscribe(()=>{const n=r.info.throughputEstimation$.getValue();Xr(n)&&this.logDownloadSpeed({speed:n/8})})).add(r.info.hostname$.subscribe(n=>{this.updateContext({cdnHostname:n})})).add(r.info.httpConnectionType$.subscribe(n=>{this.updateContext({connectionType:hv(n)})})).add(r.info.httpConnectionReused$.subscribe(n=>{this.updateContext({connectionReused:n})})).add(r.info.currentQuality$.subscribe(n=>{this.updateContext({quality:fv(n)})})).add(r.info.currentFormat$.subscribe(n=>{this.updateContext({contentType:dv(n)})})).add(r.info.chromecastState$.subscribe(n=>{this.updateContext({destination:n===Ro.CONNECTED?Le.CHROMECAST:Le.SCREEN})}))}authorize(r){return this.api.authorize(r)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=cn()}setFieldBlacklist(r=[]){this.fieldBlacklist=r}logInited(){this.log({operation:"init"})}logReady(r){this.log({operation:"player_ready",param:String(r.time)})}logStarted(r){this.log({operation:"play",param:String(Math.round(r.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(r){this.log({operation:"pause",param:String(Math.round(r.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(r){this.log({operation:"first_bytes",param:String(r.time)})}logFirstFrame(r){this.log({operation:"first_frame",param:String(r.time)})}logError(r){this.log({operation:"error",param:r.errorType})}logWatchCoverageRecord(r){this.log({operation:"watch_coverage_record",param:`${r.start}-${r.end}`}),this.logger.flush(!0)}logWatchCoverageLive(r){const t=r.start+this.timeSynchronisation.getOffset(),n=r.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${t}-${n}`}),this.logger.flush(!0)}logEmptyBuffer(r){this.log({operation:"empty_buffer",param:String(r.duration)})}logDownloadSpeed(r){this.log({operation:"download_speed",param:String(r.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(r){this.log({operation:"adv",param:r})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(r){const t=this.createLogItem(r);this.logger.log(t)}createLogItem({operation:r,param:t}){const n=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?Ue.YES:this.statContext.connectionReused===!1?Ue.NO:void 0,stat_type:this.statContext.autoplay===!0?Me.AUTO:this.statContext.autoplay===!1?Me.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};t!==void 0&&(o.param=t);for(const a of this.fieldBlacklist)delete o[a];return{operation:r,timestamp:n,custom:o}}}export{C as ApiEnv,ue as ConnectionType,P as ContentType,$v as OneStat,$ as Quality,Le as ScreenDestination};
package/es2018.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- "use strict";var a=require("@vkontakte/videoplayer-shared/es2018.cjs.js"),n=require("@vkontakte/videoplayer-core/es2018.cjs.js"),L=require("lodash/debounce.js");const A="_one-stat_",g=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const o=e.getItem(t)===t;return e.removeItem(t),o?e:null}catch(t){return null}})();function x(t){const e=g?g.getItem(A+t):null;if(e===null)return null;try{return JSON.parse(e)}catch(o){return null}}function $(t,e){try{g&&g.setItem(A+t,JSON.stringify(e))}catch(o){}}function q(t){g&&g.removeItem(A+t)}var _={get(t){return x(t)||null},set(t,e){$(t,e)},remove(t){q(t)}};function Q(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let o=0,s,r;for(r=0;r<36;r++)r===8||r===13||r===18||r===23?e[r]="-":r===14?e[r]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),s=o&15,o=o>>4,e[r]=t[r===19?s&3|8:s]);return e.join("")}exports.ApiEnv=void 0;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var y;(function(t){t.AUTO="auto",t.MANUAL=""})(y||(y={}));exports.ConnectionType=void 0;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var b;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(b||(b={}));const v="1.0.30",B="@vkontakte/videoplayer-statistics",D="CIOPGQJGDIHBABABA",P={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},F={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var p;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(p||(p={}));class H{constructor(e){this.consequentAuthErrors=0,this.authorized$=new a.ValueSubject(!1),this.params=e;const o=_.get("uuid");o?this.uuid=String(o):(this.uuid=Q(),_.set("uuid",this.uuid))}async authorize(e){return this.authToken=e!=null?e:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon(o,s,r)||this.logRequest(e)}async logRequest(e){var o;const s="log.externalLog",r=this.createLogParams(e),i=(o=this.sessionKey)!==null&&o!==void 0?o:await this._authorizeWithBackoff();if(!i)return;const u=async(f,d=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,r,i)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:a.ErrorCategory.NETWORK,message:`Unknown ${s} error`,thrown:h});return}const c=h==null?void 0:h.error_code;switch(c){case p.PARAM_SESSION_EXPIRED:case p.PARAM_SESSION_KEY:case p.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),d>0?u(f,d-1):void 0;case p.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),d>0?u(f,d-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:a.ErrorCategory.EXTERNAL_API,message:`${s} error`,data:h});return}}}};return u(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${B}:${v}`,platform:"WEB",items:e.map(o=>({...o,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=a.getExponentialDelay(this.consequentAuthErrors,F);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(o).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:a.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",o={session_data:{version:2,device_id:this.uuid,client_version:v.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(s=>{var r;return(!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:a.ErrorCategory.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=(r=s==null?void 0:s.session_key)!==null&&r!==void 0?r:void 0,this.sessionKey}).catch(async s=>{this.sessionKey=void 0;const r=s==null?void 0:s.error_code;switch(r){case p.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}r?this.params.error$.next({id:`Authorize#${r}`,category:a.ErrorCategory.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:a.ErrorCategory.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class S{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,o,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:o,options:s})}removeEventListener(e,o){if(!(e in this.listeners))return;const s=this.listeners[e];for(let r=0,i=s.length;r<i;r++)if(s[r].callback===o){s.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let r=0,i=s.length;r<i;r++){const u=s[r];try{u.callback.call(this,e)}catch(f){Promise.resolve().then(()=>{throw f})}u.options&&u.options.once&&this.removeEventListener(e.type,u.callback)}return!e.defaultPrevented}}class O extends S{constructor(){super(),this.listeners||S.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class U{constructor(){Object.defineProperty(this,"signal",{value:new O,writable:!0,configurable:!0})}abort(e){let o;try{o=new Event("abort")}catch(r){typeof document!="undefined"?document.createEvent?(o=document.createEvent("Event"),o.initEvent("abort",!1,!1)):(o=document.createEventObject(),o.type="abort"):o={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document=="undefined")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch(r){s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(o)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(U.prototype[Symbol.toStringTag]="AbortController",O.prototype[Symbol.toStringTag]="AbortSignal");function R(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function M(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:o=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!R({fetch:e,Request:o,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=o;(i&&!i.prototype.hasOwnProperty("signal")||r)&&(i=function(h,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const m=new o(h,c);return l&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),m},i.prototype=o.prototype);const u=e;return{fetch:(d,h)=>{const c=i&&i.prototype.isPrototypeOf(d)?d.signal:h?h.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(k){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const m=new Promise((k,I)=>{c.addEventListener("abort",()=>I(l),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([m,u(d,h)])}return u(d,h)},Request:i}}const E=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),C=E?M({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,w=E?C.fetch:window.fetch;E?C.Request:window.Request;class V{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var e;if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const o=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),r=await(await w(o,{method:"GET",mode:"cors",cache:"no-cache"})).json(),i=(e=r==null?void 0:r.Answer[0])===null||e===void 0?void 0:e.data;if(!i)throw new Error("Wrong DNS response");return i}catch(o){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:a.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:o}),P[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,o,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const r=this._prepareQueryParams({method:e,queryParams:o,sessionKey:s}),i=new window.Blob([r.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(u){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:a.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:u,data:{method:e,params:o}})}return!1}async sendRequest(e,o,s){const r=a.now(),i=u=>{if(u instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(u.message)){this.params.error$.next({id:"Network",category:a.ErrorCategory.NETWORK,message:"Request failed",thrown:u});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:a.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:u,data:{method:e,params:o,sessionKey:s,time:a.now()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),w(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:o,sessionKey:s})}).then(u=>{var f;const d=Number(u.headers.get("content-length"))===0,h=new Date((f=u.headers.get("date"))!==null&&f!==void 0?f:"").getTime(),c=a.now()-r;if(isFinite(h)&&this.timeSynchronisation.addServerTime(h,c),!d)return u.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,i)},i)}_prepareQueryParams(e){const o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,r])=>o.append(s,typeof r=="string"?r:JSON.stringify(r))),o}}const N=3e3,K=N*5;class W{constructor(e){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=L(()=>{var o;try{this.flush()}catch(s){this.error$.next({id:"LoggerError",category:a.ErrorCategory.WTF,message:(o=String(s))!==null&&o!==void 0?o:"Unknown logger error",thrown:s})}},N,{maxWait:K}),this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(o=>{o&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class z{constructor(e){this.offset=void 0,this.offset=e}getOffset(){var e;return(e=this.offset)!==null&&e!==void 0?e:0}setOffset(e){this.offset=e}now(){var e;return Date.now()+((e=this.offset)!==null&&e!==void 0?e:0)}date(e=new Date){var o;return e.setTime(e.getTime()+((o=this.offset)!==null&&o!==void 0?o:0)),e}addServerTime(e,o){const s=Date.now(),r=e-s-o/2;if(Math.abs(r)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(r):this.offset=Math.round(.2*r+(1-.2)*this.offset)}}const T=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),j=t=>t&&{[n.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[n.VideoQuality.Q_144P]:exports.Quality.Q144P,[n.VideoQuality.Q_240P]:exports.Quality.Q240P,[n.VideoQuality.Q_360P]:exports.Quality.Q360P,[n.VideoQuality.Q_480P]:exports.Quality.Q480P,[n.VideoQuality.Q_720P]:exports.Quality.Q720P,[n.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[n.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[n.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[n.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[t],G=t=>t&&{[n.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[n.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[n.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Y=t=>{if(t!==void 0)switch(t){case n.VideoFormat.MPEG:return exports.ContentType.MP4;case n.VideoFormat.DASH:case n.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case n.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case n.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case n.VideoFormat.DASH_WEBM:case n.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case n.VideoFormat.HLS:case n.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case n.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case n.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return a.assertNever(t)}};class J{constructor(e,o){var s;this.subscription=new a.Subscription,this.timeSynchronisation=new z,this.vsid=T(),this.fieldBlacklist=[],this.statContext=e,this.config={...(s=o.config)!==null&&s!==void 0?s:{},requestRetryCount:1};const r=new a.Subject;this.experimental={error$:r};const i=new V({apiKey:D,apiBaseUrl:P[o.apiEnv],apiEnv:o.apiEnv,error$:r,timeSynchronisation:this.timeSynchronisation});this.api=new H({apiTransport:i,refreshAuthToken:o.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:r}),this.logger=new W({api:this.api,error$:r}),this.subscription.add(a.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let o;return new a.Subscription().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?o=a.now():(a.isNonNullable(o)&&this.logEmptyBuffer({duration:a.now()-o}),o=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();a.isNonNullable(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:G(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:j(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:Y(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===n.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=T()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const o=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${o}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const o=this.createLogItem(e);this.logger.log(o)}createLogItem({operation:e,param:o}){const s=this.timeSynchronisation.now(),r={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?b.YES:this.statContext.connectionReused===!1?b.NO:void 0,stat_type:this.statContext.autoplay===!0?y.AUTO:this.statContext.autoplay===!1?y.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};o!==void 0&&(r.param=o);for(const i of this.fieldBlacklist)delete r[i];return{operation:e,timestamp:s,custom:r}}}exports.OneStat=J;
6
+ "use strict";var a=require("@vkontakte/videoplayer-shared/es2018.cjs.js"),n=require("@vkontakte/videoplayer-core/es2018.cjs.js"),L=require("lodash/debounce.js");const A="_one-stat_",g=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const o=e.getItem(t)===t;return e.removeItem(t),o?e:null}catch(t){return null}})();function x(t){const e=g?g.getItem(A+t):null;if(e===null)return null;try{return JSON.parse(e)}catch(o){return null}}function $(t,e){try{g&&g.setItem(A+t,JSON.stringify(e))}catch(o){}}function q(t){g&&g.removeItem(A+t)}var _={get(t){return x(t)||null},set(t,e){$(t,e)},remove(t){q(t)}};function Q(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let o=0,s,r;for(r=0;r<36;r++)r===8||r===13||r===18||r===23?e[r]="-":r===14?e[r]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),s=o&15,o=o>>4,e[r]=t[r===19?s&3|8:s]);return e.join("")}exports.ApiEnv=void 0;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var y;(function(t){t.AUTO="auto",t.MANUAL=""})(y||(y={}));exports.ConnectionType=void 0;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var b;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(b||(b={}));const v="1.0.31",B="@vkontakte/videoplayer-statistics",D="CIOPGQJGDIHBABABA",P={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},F={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var p;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(p||(p={}));class H{constructor(e){this.consequentAuthErrors=0,this.authorized$=new a.ValueSubject(!1),this.params=e;const o=_.get("uuid");o?this.uuid=String(o):(this.uuid=Q(),_.set("uuid",this.uuid))}async authorize(e){return this.authToken=e!=null?e:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon(o,s,r)||this.logRequest(e)}async logRequest(e){var o;const s="log.externalLog",r=this.createLogParams(e),i=(o=this.sessionKey)!==null&&o!==void 0?o:await this._authorizeWithBackoff();if(!i)return;const u=async(f,d=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,r,i)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:a.ErrorCategory.NETWORK,message:`Unknown ${s} error`,thrown:h});return}const c=h==null?void 0:h.error_code;switch(c){case p.PARAM_SESSION_EXPIRED:case p.PARAM_SESSION_KEY:case p.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),d>0?u(f,d-1):void 0;case p.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),d>0?u(f,d-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:a.ErrorCategory.EXTERNAL_API,message:`${s} error`,data:h});return}}}};return u(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${B}:${v}`,platform:"WEB",items:e.map(o=>({...o,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=a.getExponentialDelay(this.consequentAuthErrors,F);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(o).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:a.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",o={session_data:{version:2,device_id:this.uuid,client_version:v.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(s=>{var r;return(!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:a.ErrorCategory.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=(r=s==null?void 0:s.session_key)!==null&&r!==void 0?r:void 0,this.sessionKey}).catch(async s=>{this.sessionKey=void 0;const r=s==null?void 0:s.error_code;switch(r){case p.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}r?this.params.error$.next({id:`Authorize#${r}`,category:a.ErrorCategory.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:a.ErrorCategory.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class S{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,o,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:o,options:s})}removeEventListener(e,o){if(!(e in this.listeners))return;const s=this.listeners[e];for(let r=0,i=s.length;r<i;r++)if(s[r].callback===o){s.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let r=0,i=s.length;r<i;r++){const u=s[r];try{u.callback.call(this,e)}catch(f){Promise.resolve().then(()=>{throw f})}u.options&&u.options.once&&this.removeEventListener(e.type,u.callback)}return!e.defaultPrevented}}class O extends S{constructor(){super(),this.listeners||S.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class U{constructor(){Object.defineProperty(this,"signal",{value:new O,writable:!0,configurable:!0})}abort(e){let o;try{o=new Event("abort")}catch(r){typeof document!="undefined"?document.createEvent?(o=document.createEvent("Event"),o.initEvent("abort",!1,!1)):(o=document.createEventObject(),o.type="abort"):o={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document=="undefined")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch(r){s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(o)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(U.prototype[Symbol.toStringTag]="AbortController",O.prototype[Symbol.toStringTag]="AbortSignal");function R(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function M(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:o=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!R({fetch:e,Request:o,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=o;(i&&!i.prototype.hasOwnProperty("signal")||r)&&(i=function(h,c){let l;c&&c.signal&&(l=c.signal,delete c.signal);const m=new o(h,c);return l&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:l}),m},i.prototype=o.prototype);const u=e;return{fetch:(d,h)=>{const c=i&&i.prototype.isPrototypeOf(d)?d.signal:h?h.signal:void 0;if(c){let l;try{l=new DOMException("Aborted","AbortError")}catch(k){l=new Error("Aborted"),l.name="AbortError"}if(c.aborted)return Promise.reject(l);const m=new Promise((k,I)=>{c.addEventListener("abort",()=>I(l),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([m,u(d,h)])}return u(d,h)},Request:i}}const E=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),C=E?M({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,w=E?C.fetch:window.fetch;E?C.Request:window.Request;class V{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var e;if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const o=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),r=await(await w(o,{method:"GET",mode:"cors",cache:"no-cache"})).json(),i=(e=r==null?void 0:r.Answer[0])===null||e===void 0?void 0:e.data;if(!i)throw new Error("Wrong DNS response");return i}catch(o){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:a.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:o}),P[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,o,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const r=this._prepareQueryParams({method:e,queryParams:o,sessionKey:s}),i=new window.Blob([r.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(u){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:a.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:u,data:{method:e,params:o}})}return!1}async sendRequest(e,o,s){const r=a.now(),i=u=>{if(u instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(u.message)){this.params.error$.next({id:"Network",category:a.ErrorCategory.NETWORK,message:"Request failed",thrown:u});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:a.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:u,data:{method:e,params:o,sessionKey:s,time:a.now()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),w(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:o,sessionKey:s})}).then(u=>{var f;const d=Number(u.headers.get("content-length"))===0,h=new Date((f=u.headers.get("date"))!==null&&f!==void 0?f:"").getTime(),c=a.now()-r;if(isFinite(h)&&this.timeSynchronisation.addServerTime(h,c),!d)return u.json().then(l=>Object.prototype.hasOwnProperty.call(l,"error_msg")?Promise.reject(l):l,i)},i)}_prepareQueryParams(e){const o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,r])=>o.append(s,typeof r=="string"?r:JSON.stringify(r))),o}}const N=3e3,K=N*5;class W{constructor(e){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=L(()=>{var o;try{this.flush()}catch(s){this.error$.next({id:"LoggerError",category:a.ErrorCategory.WTF,message:(o=String(s))!==null&&o!==void 0?o:"Unknown logger error",thrown:s})}},N,{maxWait:K}),this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(o=>{o&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class z{constructor(e){this.offset=void 0,this.offset=e}getOffset(){var e;return(e=this.offset)!==null&&e!==void 0?e:0}setOffset(e){this.offset=e}now(){var e;return Date.now()+((e=this.offset)!==null&&e!==void 0?e:0)}date(e=new Date){var o;return e.setTime(e.getTime()+((o=this.offset)!==null&&o!==void 0?o:0)),e}addServerTime(e,o){const s=Date.now(),r=e-s-o/2;if(Math.abs(r)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(r):this.offset=Math.round(.2*r+(1-.2)*this.offset)}}const T=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),j=t=>t&&{[n.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[n.VideoQuality.Q_144P]:exports.Quality.Q144P,[n.VideoQuality.Q_240P]:exports.Quality.Q240P,[n.VideoQuality.Q_360P]:exports.Quality.Q360P,[n.VideoQuality.Q_480P]:exports.Quality.Q480P,[n.VideoQuality.Q_720P]:exports.Quality.Q720P,[n.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[n.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[n.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[n.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[t],G=t=>t&&{[n.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[n.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[n.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Y=t=>{if(t!==void 0)switch(t){case n.VideoFormat.MPEG:return exports.ContentType.MP4;case n.VideoFormat.DASH:case n.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case n.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case n.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case n.VideoFormat.DASH_WEBM:case n.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case n.VideoFormat.HLS:case n.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case n.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case n.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return a.assertNever(t)}};class J{constructor(e,o){var s;this.subscription=new a.Subscription,this.timeSynchronisation=new z,this.vsid=T(),this.fieldBlacklist=[],this.statContext=e,this.config={...(s=o.config)!==null&&s!==void 0?s:{},requestRetryCount:1};const r=new a.Subject;this.experimental={error$:r};const i=new V({apiKey:D,apiBaseUrl:P[o.apiEnv],apiEnv:o.apiEnv,error$:r,timeSynchronisation:this.timeSynchronisation});this.api=new H({apiTransport:i,refreshAuthToken:o.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:r}),this.logger=new W({api:this.api,error$:r}),this.subscription.add(a.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let o;return new a.Subscription().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?o=a.now():(a.isNonNullable(o)&&this.logEmptyBuffer({duration:a.now()-o}),o=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();a.isNonNullable(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:G(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:j(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:Y(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===n.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=T()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const o=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${o}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const o=this.createLogItem(e);this.logger.log(o)}createLogItem({operation:e,param:o}){const s=this.timeSynchronisation.now(),r={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?b.YES:this.statContext.connectionReused===!1?b.NO:void 0,stat_type:this.statContext.autoplay===!0?y.AUTO:this.statContext.autoplay===!1?y.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};o!==void 0&&(r.param=o);for(const i of this.fieldBlacklist)delete r[i];return{operation:e,timestamp:s,custom:r}}}exports.OneStat=J;
package/es2018.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- import{ValueSubject as K,getExponentialDelay as Q,ErrorCategory as f,now as E,assertNever as W,Subscription as N,Subject as z,fromEvent as V,isNonNullable as k}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{VideoQuality as p,HttpConnectionType as T,VideoFormat as d,ChromecastState as j}from"@vkontakte/videoplayer-core/es2018.esm.js";import G from"lodash/debounce.js";const R="_one-stat_",_=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}})();function Y(t){const e=_?_.getItem(R+t):null;if(e===null)return null;try{return JSON.parse(e)}catch(r){return null}}function J(t,e){try{_&&_.setItem(R+t,JSON.stringify(e))}catch(r){}}function X(t){_&&_.removeItem(R+t)}var I={get(t){return Y(t)||null},set(t,e){J(t,e)},remove(t){X(t)}};function Z(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let r=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(r<=2&&(r=33554432+Math.random()*16777216|0),s=r&15,r=r>>4,e[o]=t[o===19?s&3|8:s]);return e.join("")}var b;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(b||(b={}));var l;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(l||(l={}));var v;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(v||(v={}));var g;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(g||(g={}));var w;(function(t){t.AUTO="auto",t.MANUAL=""})(w||(w={}));var y;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(y||(y={}));var P;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(P||(P={}));const L="1.0.30",ee="@vkontakte/videoplayer-statistics",te="CIOPGQJGDIHBABABA",B={[b.PROD]:"https://api.ok.ru",[b.VK_ALIAS]:"https://api.mycdn.me",[b.VIDEOTEST]:"https://videotestapi.ok.ru/api",[b.TEST]:"https://apitest.ok.ru",[b.AUTO]:""},se={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var A;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(A||(A={}));class re{constructor(e){this.consequentAuthErrors=0,this.authorized$=new K(!1),this.params=e;const r=I.get("uuid");r?this.uuid=String(r):(this.uuid=Z(),I.set("uuid",this.uuid))}async authorize(e){return this.authToken=e!=null?e:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(r,s,o)||this.logRequest(e)}async logRequest(e){var r;const s="log.externalLog",o=this.createLogParams(e),i=(r=this.sessionKey)!==null&&r!==void 0?r:await this._authorizeWithBackoff();if(!i)return;const n=async(m,c=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(a){if(!a||!("error_code"in a)){this.params.error$.next({id:"logRequestUnknown",category:f.NETWORK,message:`Unknown ${s} error`,thrown:a});return}const h=a==null?void 0:a.error_code;switch(h){case A.PARAM_SESSION_EXPIRED:case A.PARAM_SESSION_KEY:case A.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),c>0?n(m,c-1):void 0;case A.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),c>0?n(m,c-1):void 0;default:{this.params.error$.next({id:`LogRequest#${h}`,category:f.EXTERNAL_API,message:`${s} error`,data:a});return}}}};return n(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${ee}:${L}`,platform:"WEB",items:e.map(r=>({...r,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=Q(this.consequentAuthErrors,se);return new Promise(r=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(r).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:f.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",r={session_data:{version:2,device_id:this.uuid,client_version:L.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(r.session_data.auth_token=this.authToken,r.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,r).then(s=>{var o;return(!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:f.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=(o=s==null?void 0:s.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(async s=>{this.sessionKey=void 0;const o=s==null?void 0:s.error_code;switch(o){case A.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:f.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:f.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class x{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:s})}removeEventListener(e,r){if(!(e in this.listeners))return;const s=this.listeners[e];for(let o=0,i=s.length;o<i;o++)if(s[o].callback===r){s.splice(o,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let o=0,i=s.length;o<i;o++){const n=s[o];try{n.callback.call(this,e)}catch(m){Promise.resolve().then(()=>{throw m})}n.options&&n.options.once&&this.removeEventListener(e.type,n.callback)}return!e.defaultPrevented}}class q extends x{constructor(){super(),this.listeners||x.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class oe{constructor(){Object.defineProperty(this,"signal",{value:new q,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document=="undefined")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch(o){s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",q.prototype[Symbol.toStringTag]="AbortSignal");function U(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ie(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!U({fetch:e,Request:r,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty("signal")||o)&&(i=function(a,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const S=new r(a,h);return u&&Object.defineProperty(S,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),S},i.prototype=r.prototype);const n=e;return{fetch:(c,a)=>{const h=i&&i.prototype.isPrototypeOf(c)?c.signal:a?a.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(M){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const S=new Promise((M,F)=>{h.addEventListener("abort",()=>F(u),{once:!0})});return a&&a.signal&&delete a.signal,Promise.race([S,n(c,a)])}return n(c,a)},Request:i}}const O=U({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),D=O?ie({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=O?D.fetch:window.fetch;O?D.Request:window.Request;class ne{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var e;if(this.apiEnv!==b.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const r=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=await(await C(r,{method:"GET",mode:"cors",cache:"no-cache"})).json(),i=(e=o==null?void 0:o.Answer[0])===null||e===void 0?void 0:e.data;if(!i)throw new Error("Wrong DNS response");return i}catch(r){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:f.NETWORK,message:"Unhandled resolve api base url error",thrown:r}),B[b.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,r,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:r,sessionKey:s}),i=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(n){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:f.NETWORK,message:"Unhandled beacon error",thrown:n,data:{method:e,params:r}})}return!1}async sendRequest(e,r,s){const o=E(),i=n=>{if(n instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(n.message)){this.params.error$.next({id:"Network",category:f.NETWORK,message:"Request failed",thrown:n});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:f.NETWORK,message:"Unhandled request error",thrown:n,data:{method:e,params:r,sessionKey:s,time:E()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),C(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:s})}).then(n=>{var m;const c=Number(n.headers.get("content-length"))===0,a=new Date((m=n.headers.get("date"))!==null&&m!==void 0?m:"").getTime(),h=E()-o;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,h),!c)return n.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,i)},i)}_prepareQueryParams(e){const r=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&r.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,o])=>r.append(s,typeof o=="string"?o:JSON.stringify(o))),r}}const H=3e3,ae=H*5;class he{constructor(e){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=G(()=>{var r;try{this.flush()}catch(s){this.error$.next({id:"LoggerError",category:f.WTF,message:(r=String(s))!==null&&r!==void 0?r:"Unknown logger error",thrown:s})}},H,{maxWait:ae}),this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(r=>{r&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class ue{constructor(e){this.offset=void 0,this.offset=e}getOffset(){var e;return(e=this.offset)!==null&&e!==void 0?e:0}setOffset(e){this.offset=e}now(){var e;return Date.now()+((e=this.offset)!==null&&e!==void 0?e:0)}date(e=new Date){var r;return e.setTime(e.getTime()+((r=this.offset)!==null&&r!==void 0?r:0)),e}addServerTime(e,r){const s=Date.now(),o=e-s-r/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),ce=t=>t&&{[p.INVARIANT]:l.UNKNOWN,[p.Q_144P]:l.Q144P,[p.Q_240P]:l.Q240P,[p.Q_360P]:l.Q360P,[p.Q_480P]:l.Q480P,[p.Q_720P]:l.Q720P,[p.Q_1080P]:l.Q1080P,[p.Q_1440P]:l.Q1440P,[p.Q_2160P]:l.Q2160P,[p.Q_4320P]:l.Q4320P}[t],le=t=>t&&{[T.HTTP1]:y.HTTP1,[T.HTTP2]:y.HTTP2,[T.QUIC]:y.HTTP3}[t],de=t=>{if(t!==void 0)switch(t){case d.MPEG:return g.MP4;case d.DASH:case d.DASH_LIVE:return g.DASH;case d.DASH_SEP:return g.DASH_SEP;case d.DASH_ONDEMAND:return g.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return g.WEBM;case d.HLS:case d.HLS_LIVE:return g.HLS;case d.HLS_ONDEMAND:return g.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return g.RTMP;default:return W(t)}};class me{constructor(e,r){var s;this.subscription=new N,this.timeSynchronisation=new ue,this.vsid=$(),this.fieldBlacklist=[],this.statContext=e,this.config={...(s=r.config)!==null&&s!==void 0?s:{},requestRetryCount:1};const o=new z;this.experimental={error$:o};const i=new ne({apiKey:te,apiBaseUrl:B[r.apiEnv],apiEnv:r.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new re({apiTransport:i,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new he({api:this.api,error$:o}),this.subscription.add(V(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let r;return new N().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?r=E():(k(r)&&this.logEmptyBuffer({duration:E()-r}),r=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();k(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:le(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:ce(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:de(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===j.CONNECTED?v.CHROMECAST:v.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=$()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const r=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${r}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const r=this.createLogItem(e);this.logger.log(r)}createLogItem({operation:e,param:r}){const s=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?P.YES:this.statContext.connectionReused===!1?P.NO:void 0,stat_type:this.statContext.autoplay===!0?w.AUTO:this.statContext.autoplay===!1?w.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};r!==void 0&&(o.param=r);for(const i of this.fieldBlacklist)delete o[i];return{operation:e,timestamp:s,custom:o}}}export{b as ApiEnv,y as ConnectionType,g as ContentType,me as OneStat,l as Quality,v as ScreenDestination};
6
+ import{ValueSubject as K,getExponentialDelay as Q,ErrorCategory as f,now as E,assertNever as W,Subscription as N,Subject as z,fromEvent as V,isNonNullable as k}from"@vkontakte/videoplayer-shared/es2018.esm.js";import{VideoQuality as p,HttpConnectionType as T,VideoFormat as d,ChromecastState as j}from"@vkontakte/videoplayer-core/es2018.esm.js";import G from"lodash/debounce.js";const R="_one-stat_",_=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}})();function Y(t){const e=_?_.getItem(R+t):null;if(e===null)return null;try{return JSON.parse(e)}catch(r){return null}}function J(t,e){try{_&&_.setItem(R+t,JSON.stringify(e))}catch(r){}}function X(t){_&&_.removeItem(R+t)}var I={get(t){return Y(t)||null},set(t,e){J(t,e)},remove(t){X(t)}};function Z(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let r=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(r<=2&&(r=33554432+Math.random()*16777216|0),s=r&15,r=r>>4,e[o]=t[o===19?s&3|8:s]);return e.join("")}var b;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(b||(b={}));var l;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(l||(l={}));var v;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(v||(v={}));var g;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(g||(g={}));var w;(function(t){t.AUTO="auto",t.MANUAL=""})(w||(w={}));var y;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(y||(y={}));var P;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(P||(P={}));const L="1.0.31",ee="@vkontakte/videoplayer-statistics",te="CIOPGQJGDIHBABABA",B={[b.PROD]:"https://api.ok.ru",[b.VK_ALIAS]:"https://api.mycdn.me",[b.VIDEOTEST]:"https://videotestapi.ok.ru/api",[b.TEST]:"https://apitest.ok.ru",[b.AUTO]:""},se={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var A;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(A||(A={}));class re{constructor(e){this.consequentAuthErrors=0,this.authorized$=new K(!1),this.params=e;const r=I.get("uuid");r?this.uuid=String(r):(this.uuid=Z(),I.set("uuid",this.uuid))}async authorize(e){return this.authToken=e!=null?e:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(r,s,o)||this.logRequest(e)}async logRequest(e){var r;const s="log.externalLog",o=this.createLogParams(e),i=(r=this.sessionKey)!==null&&r!==void 0?r:await this._authorizeWithBackoff();if(!i)return;const n=async(m,c=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(a){if(!a||!("error_code"in a)){this.params.error$.next({id:"logRequestUnknown",category:f.NETWORK,message:`Unknown ${s} error`,thrown:a});return}const h=a==null?void 0:a.error_code;switch(h){case A.PARAM_SESSION_EXPIRED:case A.PARAM_SESSION_KEY:case A.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),c>0?n(m,c-1):void 0;case A.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),c>0?n(m,c-1):void 0;default:{this.params.error$.next({id:`LogRequest#${h}`,category:f.EXTERNAL_API,message:`${s} error`,data:a});return}}}};return n(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${ee}:${L}`,platform:"WEB",items:e.map(r=>({...r,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=Q(this.consequentAuthErrors,se);return new Promise(r=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(r).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:f.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",r={session_data:{version:2,device_id:this.uuid,client_version:L.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(r.session_data.auth_token=this.authToken,r.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,r).then(s=>{var o;return(!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:f.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=(o=s==null?void 0:s.session_key)!==null&&o!==void 0?o:void 0,this.sessionKey}).catch(async s=>{this.sessionKey=void 0;const o=s==null?void 0:s.error_code;switch(o){case A.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:f.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:f.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class x{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:s})}removeEventListener(e,r){if(!(e in this.listeners))return;const s=this.listeners[e];for(let o=0,i=s.length;o<i;o++)if(s[o].callback===r){s.splice(o,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let o=0,i=s.length;o<i;o++){const n=s[o];try{n.callback.call(this,e)}catch(m){Promise.resolve().then(()=>{throw m})}n.options&&n.options.once&&this.removeEventListener(e.type,n.callback)}return!e.defaultPrevented}}class q extends x{constructor(){super(),this.listeners||x.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class oe{constructor(){Object.defineProperty(this,"signal",{value:new q,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch(o){typeof document!="undefined"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document=="undefined")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch(o){s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}}typeof Symbol!="undefined"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",q.prototype[Symbol.toStringTag]="AbortSignal");function U(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ie(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!U({fetch:e,Request:r,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty("signal")||o)&&(i=function(a,h){let u;h&&h.signal&&(u=h.signal,delete h.signal);const S=new r(a,h);return u&&Object.defineProperty(S,"signal",{writable:!1,enumerable:!1,configurable:!0,value:u}),S},i.prototype=r.prototype);const n=e;return{fetch:(c,a)=>{const h=i&&i.prototype.isPrototypeOf(c)?c.signal:a?a.signal:void 0;if(h){let u;try{u=new DOMException("Aborted","AbortError")}catch(M){u=new Error("Aborted"),u.name="AbortError"}if(h.aborted)return Promise.reject(u);const S=new Promise((M,F)=>{h.addEventListener("abort",()=>F(u),{once:!0})});return a&&a.signal&&delete a.signal,Promise.race([S,n(c,a)])}return n(c,a)},Request:i}}const O=U({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),D=O?ie({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=O?D.fetch:window.fetch;O?D.Request:window.Request;class ne{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var e;if(this.apiEnv!==b.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const r=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=await(await C(r,{method:"GET",mode:"cors",cache:"no-cache"})).json(),i=(e=o==null?void 0:o.Answer[0])===null||e===void 0?void 0:e.data;if(!i)throw new Error("Wrong DNS response");return i}catch(r){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:f.NETWORK,message:"Unhandled resolve api base url error",thrown:r}),B[b.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,r,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:r,sessionKey:s}),i=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(n){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:f.NETWORK,message:"Unhandled beacon error",thrown:n,data:{method:e,params:r}})}return!1}async sendRequest(e,r,s){const o=E(),i=n=>{if(n instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(n.message)){this.params.error$.next({id:"Network",category:f.NETWORK,message:"Request failed",thrown:n});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:f.NETWORK,message:"Unhandled request error",thrown:n,data:{method:e,params:r,sessionKey:s,time:E()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),C(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:s})}).then(n=>{var m;const c=Number(n.headers.get("content-length"))===0,a=new Date((m=n.headers.get("date"))!==null&&m!==void 0?m:"").getTime(),h=E()-o;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,h),!c)return n.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,i)},i)}_prepareQueryParams(e){const r=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&r.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,o])=>r.append(s,typeof o=="string"?o:JSON.stringify(o))),r}}const H=3e3,ae=H*5;class he{constructor(e){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=G(()=>{var r;try{this.flush()}catch(s){this.error$.next({id:"LoggerError",category:f.WTF,message:(r=String(s))!==null&&r!==void 0?r:"Unknown logger error",thrown:s})}},H,{maxWait:ae}),this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(r=>{r&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class ue{constructor(e){this.offset=void 0,this.offset=e}getOffset(){var e;return(e=this.offset)!==null&&e!==void 0?e:0}setOffset(e){this.offset=e}now(){var e;return Date.now()+((e=this.offset)!==null&&e!==void 0?e:0)}date(e=new Date){var r;return e.setTime(e.getTime()+((r=this.offset)!==null&&r!==void 0?r:0)),e}addServerTime(e,r){const s=Date.now(),o=e-s-r/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),ce=t=>t&&{[p.INVARIANT]:l.UNKNOWN,[p.Q_144P]:l.Q144P,[p.Q_240P]:l.Q240P,[p.Q_360P]:l.Q360P,[p.Q_480P]:l.Q480P,[p.Q_720P]:l.Q720P,[p.Q_1080P]:l.Q1080P,[p.Q_1440P]:l.Q1440P,[p.Q_2160P]:l.Q2160P,[p.Q_4320P]:l.Q4320P}[t],le=t=>t&&{[T.HTTP1]:y.HTTP1,[T.HTTP2]:y.HTTP2,[T.QUIC]:y.HTTP3}[t],de=t=>{if(t!==void 0)switch(t){case d.MPEG:return g.MP4;case d.DASH:case d.DASH_LIVE:return g.DASH;case d.DASH_SEP:return g.DASH_SEP;case d.DASH_ONDEMAND:return g.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return g.WEBM;case d.HLS:case d.HLS_LIVE:return g.HLS;case d.HLS_ONDEMAND:return g.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return g.RTMP;default:return W(t)}};class me{constructor(e,r){var s;this.subscription=new N,this.timeSynchronisation=new ue,this.vsid=$(),this.fieldBlacklist=[],this.statContext=e,this.config={...(s=r.config)!==null&&s!==void 0?s:{},requestRetryCount:1};const o=new z;this.experimental={error$:o};const i=new ne({apiKey:te,apiBaseUrl:B[r.apiEnv],apiEnv:r.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new re({apiTransport:i,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new he({api:this.api,error$:o}),this.subscription.add(V(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let r;return new N().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?r=E():(k(r)&&this.logEmptyBuffer({duration:E()-r}),r=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();k(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:le(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:ce(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:de(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===j.CONNECTED?v.CHROMECAST:v.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=$()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const r=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${r}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const r=this.createLogItem(e);this.logger.log(r)}createLogItem({operation:e,param:r}){const s=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?P.YES:this.statContext.connectionReused===!1?P.NO:void 0,stat_type:this.statContext.autoplay===!0?w.AUTO:this.statContext.autoplay===!1?w.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};r!==void 0&&(o.param=r);for(const i of this.fieldBlacklist)delete o[i];return{operation:e,timestamp:s,custom:o}}}export{b as ApiEnv,y as ConnectionType,g as ContentType,me as OneStat,l as Quality,v as ScreenDestination};
package/esnext.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- "use strict";var a=require("@vkontakte/videoplayer-shared/esnext.cjs.js"),n=require("@vkontakte/videoplayer-core/esnext.cjs.js"),L=require("lodash/debounce.js");const A="_one-stat_",g=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const o=e.getItem(t)===t;return e.removeItem(t),o?e:null}catch{return null}})();function x(t){const e=g?g.getItem(A+t):null;if(e===null)return null;try{return JSON.parse(e)}catch{return null}}function $(t,e){try{g&&g.setItem(A+t,JSON.stringify(e))}catch{}}function q(t){g&&g.removeItem(A+t)}var S={get(t){return x(t)||null},set(t,e){$(t,e)},remove(t){q(t)}};function B(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let o=0,s,r;for(r=0;r<36;r++)r===8||r===13||r===18||r===23?e[r]="-":r===14?e[r]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),s=o&15,o=o>>4,e[r]=t[r===19?s&3|8:s]);return e.join("")}exports.ApiEnv=void 0;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var y;(function(t){t.AUTO="auto",t.MANUAL=""})(y||(y={}));exports.ConnectionType=void 0;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var b;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(b||(b={}));const T="1.0.30",Q="@vkontakte/videoplayer-statistics",D="CIOPGQJGDIHBABABA",v={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},F={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var p;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(p||(p={}));class U{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new a.ValueSubject(!1);backoffTimeoutId;constructor(e){this.params=e;const o=S.get("uuid");o?this.uuid=String(o):(this.uuid=B(),S.set("uuid",this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon(o,s,r)||this.logRequest(e)}async logRequest(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey??await this._authorizeWithBackoff();if(!r)return;const i=async(u,l=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(o,s,r)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:a.ErrorCategory.NETWORK,message:`Unknown ${o} error`,thrown:h});return}const c=h?.error_code;switch(c){case p.PARAM_SESSION_EXPIRED:case p.PARAM_SESSION_KEY:case p.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),l>0?i(u,l-1):void 0;case p.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),l>0?i(u,l-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:a.ErrorCategory.EXTERNAL_API,message:`${o} error`,data:h});return}}}};return i(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${Q}:${T}`,platform:"WEB",items:e.map(o=>({...o,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=a.getExponentialDelay(this.consequentAuthErrors,F);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(o).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:a.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",o={session_data:{version:2,device_id:this.uuid,client_version:T.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:a.ErrorCategory.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const r=s?.error_code;switch(r){case p.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}r?this.params.error$.next({id:`Authorize#${r}`,category:a.ErrorCategory.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:a.ErrorCategory.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class _{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,o,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:o,options:s})}removeEventListener(e,o){if(!(e in this.listeners))return;const s=this.listeners[e];for(let r=0,i=s.length;r<i;r++)if(s[r].callback===o){s.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let r=0,i=s.length;r<i;r++){const u=s[r];try{u.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}u.options&&u.options.once&&this.removeEventListener(e.type,u.callback)}return!e.defaultPrevented}}class O extends _{constructor(){super(),this.listeners||_.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class H{constructor(){Object.defineProperty(this,"signal",{value:new O,writable:!0,configurable:!0})}abort(e){let o;try{o=new Event("abort")}catch{typeof document<"u"?document.createEvent?(o=document.createEvent("Event"),o.initEvent("abort",!1,!1)):(o=document.createEventObject(),o.type="abort"):o={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document>"u")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch{s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(o)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(H.prototype[Symbol.toStringTag]="AbortController",O.prototype[Symbol.toStringTag]="AbortSignal");function R(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function M(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:o=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!R({fetch:e,Request:o,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=o;(i&&!i.prototype.hasOwnProperty("signal")||r)&&(i=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);const m=new o(c,d);return f&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),m},i.prototype=o.prototype);const u=e;return{fetch:(h,c)=>{const d=i&&i.prototype.isPrototypeOf(h)?h.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);const m=new Promise((k,I)=>{d.addEventListener("abort",()=>I(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([m,u(h,c)])}return u(h,c)},Request:i}}const E=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),C=E?M({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,w=E?C.fetch:window.fetch;E?C.Request:window.Request;class V{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),r=(await(await w(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!r)throw new Error("Wrong DNS response");return r}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:a.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),v[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,o,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const r=this._prepareQueryParams({method:e,queryParams:o,sessionKey:s}),i=new window.Blob([r.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(u){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:a.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:u,data:{method:e,params:o}})}return!1}async sendRequest(e,o,s){const r=a.now(),i=u=>{if(u instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(u.message)){this.params.error$.next({id:"Network",category:a.ErrorCategory.NETWORK,message:"Request failed",thrown:u});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:a.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:u,data:{method:e,params:o,sessionKey:s,time:a.now()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),w(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:o,sessionKey:s})}).then(u=>{const l=Number(u.headers.get("content-length"))===0,h=new Date(u.headers.get("date")??"").getTime(),c=a.now()-r;if(isFinite(h)&&this.timeSynchronisation.addServerTime(h,c),!l)return u.json().then(d=>Object.prototype.hasOwnProperty.call(d,"error_msg")?Promise.reject(d):d,i)},i)}_prepareQueryParams(e){const o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,r])=>o.append(s,typeof r=="string"?r:JSON.stringify(r))),o}}const N=3e3,K=N*5;class z{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=L(()=>{try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:a.ErrorCategory.WTF,message:String(e)??"Unknown logger error",thrown:e})}},N,{maxWait:K});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(o=>{o&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class W{offset=void 0;constructor(e){this.offset=e}getOffset(){return this.offset??0}setOffset(e){this.offset=e}now(){return Date.now()+(this.offset??0)}date(e=new Date){return e.setTime(e.getTime()+(this.offset??0)),e}addServerTime(e,o){const s=Date.now(),r=e-s-o/2;if(Math.abs(r)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(r):this.offset=Math.round(.2*r+(1-.2)*this.offset)}}const P=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),j=t=>t&&{[n.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[n.VideoQuality.Q_144P]:exports.Quality.Q144P,[n.VideoQuality.Q_240P]:exports.Quality.Q240P,[n.VideoQuality.Q_360P]:exports.Quality.Q360P,[n.VideoQuality.Q_480P]:exports.Quality.Q480P,[n.VideoQuality.Q_720P]:exports.Quality.Q720P,[n.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[n.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[n.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[n.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[t],G=t=>t&&{[n.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[n.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[n.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Y=t=>{if(t!==void 0)switch(t){case n.VideoFormat.MPEG:return exports.ContentType.MP4;case n.VideoFormat.DASH:case n.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case n.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case n.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case n.VideoFormat.DASH_WEBM:case n.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case n.VideoFormat.HLS:case n.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case n.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case n.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return a.assertNever(t)}};class J{api;logger;config;subscription=new a.Subscription;timeSynchronisation=new W;experimental;statContext;vsid=P();fieldBlacklist=[];constructor(e,o){this.statContext=e,this.config={...o.config??{},requestRetryCount:1};const s=new a.Subject;this.experimental={error$:s};const r=new V({apiKey:D,apiBaseUrl:v[o.apiEnv],apiEnv:o.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new U({apiTransport:r,refreshAuthToken:o.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new z({api:this.api,error$:s}),this.subscription.add(a.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let o;return new a.Subscription().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?o=a.now():(a.isNonNullable(o)&&this.logEmptyBuffer({duration:a.now()-o}),o=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();a.isNonNullable(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:G(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:j(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:Y(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===n.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=P()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const o=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${o}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const o=this.createLogItem(e);this.logger.log(o)}createLogItem({operation:e,param:o}){const s=this.timeSynchronisation.now(),r={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?b.YES:this.statContext.connectionReused===!1?b.NO:void 0,stat_type:this.statContext.autoplay===!0?y.AUTO:this.statContext.autoplay===!1?y.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};o!==void 0&&(r.param=o);for(const i of this.fieldBlacklist)delete r[i];return{operation:e,timestamp:s,custom:r}}}exports.OneStat=J;
6
+ "use strict";var a=require("@vkontakte/videoplayer-shared/esnext.cjs.js"),n=require("@vkontakte/videoplayer-core/esnext.cjs.js"),L=require("lodash/debounce.js");const A="_one-stat_",g=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const o=e.getItem(t)===t;return e.removeItem(t),o?e:null}catch{return null}})();function x(t){const e=g?g.getItem(A+t):null;if(e===null)return null;try{return JSON.parse(e)}catch{return null}}function $(t,e){try{g&&g.setItem(A+t,JSON.stringify(e))}catch{}}function q(t){g&&g.removeItem(A+t)}var S={get(t){return x(t)||null},set(t,e){$(t,e)},remove(t){q(t)}};function B(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let o=0,s,r;for(r=0;r<36;r++)r===8||r===13||r===18||r===23?e[r]="-":r===14?e[r]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),s=o&15,o=o>>4,e[r]=t[r===19?s&3|8:s]);return e.join("")}exports.ApiEnv=void 0;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(exports.ApiEnv||(exports.ApiEnv={}));exports.Quality=void 0;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(exports.Quality||(exports.Quality={}));exports.ScreenDestination=void 0;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(exports.ScreenDestination||(exports.ScreenDestination={}));exports.ContentType=void 0;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(exports.ContentType||(exports.ContentType={}));var y;(function(t){t.AUTO="auto",t.MANUAL=""})(y||(y={}));exports.ConnectionType=void 0;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(exports.ConnectionType||(exports.ConnectionType={}));var b;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(b||(b={}));const T="1.0.31",Q="@vkontakte/videoplayer-statistics",D="CIOPGQJGDIHBABABA",v={[exports.ApiEnv.PROD]:"https://api.ok.ru",[exports.ApiEnv.VK_ALIAS]:"https://api.mycdn.me",[exports.ApiEnv.VIDEOTEST]:"https://videotestapi.ok.ru/api",[exports.ApiEnv.TEST]:"https://apitest.ok.ru",[exports.ApiEnv.AUTO]:""},F={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var p;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(p||(p={}));class U{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new a.ValueSubject(!1);backoffTimeoutId;constructor(e){this.params=e;const o=S.get("uuid");o?this.uuid=String(o):(this.uuid=B(),S.set("uuid",this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon(o,s,r)||this.logRequest(e)}async logRequest(e){const o="log.externalLog",s=this.createLogParams(e),r=this.sessionKey??await this._authorizeWithBackoff();if(!r)return;const i=async(u,l=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(o,s,r)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:a.ErrorCategory.NETWORK,message:`Unknown ${o} error`,thrown:h});return}const c=h?.error_code;switch(c){case p.PARAM_SESSION_EXPIRED:case p.PARAM_SESSION_KEY:case p.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),l>0?i(u,l-1):void 0;case p.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),l>0?i(u,l-1):void 0;default:{this.params.error$.next({id:`LogRequest#${c}`,category:a.ErrorCategory.EXTERNAL_API,message:`${o} error`,data:h});return}}}};return i(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${Q}:${T}`,platform:"WEB",items:e.map(o=>({...o,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=a.getExponentialDelay(this.consequentAuthErrors,F);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(o).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:a.ErrorCategory.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",o={session_data:{version:2,device_id:this.uuid,client_version:T.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:a.ErrorCategory.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const r=s?.error_code;switch(r){case p.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}r?this.params.error$.next({id:`Authorize#${r}`,category:a.ErrorCategory.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:a.ErrorCategory.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class _{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,o,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:o,options:s})}removeEventListener(e,o){if(!(e in this.listeners))return;const s=this.listeners[e];for(let r=0,i=s.length;r<i;r++)if(s[r].callback===o){s.splice(r,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let r=0,i=s.length;r<i;r++){const u=s[r];try{u.callback.call(this,e)}catch(l){Promise.resolve().then(()=>{throw l})}u.options&&u.options.once&&this.removeEventListener(e.type,u.callback)}return!e.defaultPrevented}}class O extends _{constructor(){super(),this.listeners||_.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class H{constructor(){Object.defineProperty(this,"signal",{value:new O,writable:!0,configurable:!0})}abort(e){let o;try{o=new Event("abort")}catch{typeof document<"u"?document.createEvent?(o=document.createEvent("Event"),o.initEvent("abort",!1,!1)):(o=document.createEventObject(),o.type="abort"):o={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document>"u")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch{s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(o)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(H.prototype[Symbol.toStringTag]="AbortController",O.prototype[Symbol.toStringTag]="AbortSignal");function R(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function M(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:o=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!R({fetch:e,Request:o,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=o;(i&&!i.prototype.hasOwnProperty("signal")||r)&&(i=function(c,d){let f;d&&d.signal&&(f=d.signal,delete d.signal);const m=new o(c,d);return f&&Object.defineProperty(m,"signal",{writable:!1,enumerable:!1,configurable:!0,value:f}),m},i.prototype=o.prototype);const u=e;return{fetch:(h,c)=>{const d=i&&i.prototype.isPrototypeOf(h)?h.signal:c?c.signal:void 0;if(d){let f;try{f=new DOMException("Aborted","AbortError")}catch{f=new Error("Aborted"),f.name="AbortError"}if(d.aborted)return Promise.reject(f);const m=new Promise((k,I)=>{d.addEventListener("abort",()=>I(f),{once:!0})});return c&&c.signal&&delete c.signal,Promise.race([m,u(h,c)])}return u(h,c)},Request:i}}const E=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),C=E?M({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,w=E?C.fetch:window.fetch;E?C.Request:window.Request;class V{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),r=(await(await w(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!r)throw new Error("Wrong DNS response");return r}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:a.ErrorCategory.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),v[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,o,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const r=this._prepareQueryParams({method:e,queryParams:o,sessionKey:s}),i=new window.Blob([r.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(u){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:a.ErrorCategory.NETWORK,message:"Unhandled beacon error",thrown:u,data:{method:e,params:o}})}return!1}async sendRequest(e,o,s){const r=a.now(),i=u=>{if(u instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(u.message)){this.params.error$.next({id:"Network",category:a.ErrorCategory.NETWORK,message:"Request failed",thrown:u});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:a.ErrorCategory.NETWORK,message:"Unhandled request error",thrown:u,data:{method:e,params:o,sessionKey:s,time:a.now()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),w(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:o,sessionKey:s})}).then(u=>{const l=Number(u.headers.get("content-length"))===0,h=new Date(u.headers.get("date")??"").getTime(),c=a.now()-r;if(isFinite(h)&&this.timeSynchronisation.addServerTime(h,c),!l)return u.json().then(d=>Object.prototype.hasOwnProperty.call(d,"error_msg")?Promise.reject(d):d,i)},i)}_prepareQueryParams(e){const o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,r])=>o.append(s,typeof r=="string"?r:JSON.stringify(r))),o}}const N=3e3,K=N*5;class z{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=L(()=>{try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:a.ErrorCategory.WTF,message:String(e)??"Unknown logger error",thrown:e})}},N,{maxWait:K});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(o=>{o&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class W{offset=void 0;constructor(e){this.offset=e}getOffset(){return this.offset??0}setOffset(e){this.offset=e}now(){return Date.now()+(this.offset??0)}date(e=new Date){return e.setTime(e.getTime()+(this.offset??0)),e}addServerTime(e,o){const s=Date.now(),r=e-s-o/2;if(Math.abs(r)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(r):this.offset=Math.round(.2*r+(1-.2)*this.offset)}}const P=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),j=t=>t&&{[n.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[n.VideoQuality.Q_144P]:exports.Quality.Q144P,[n.VideoQuality.Q_240P]:exports.Quality.Q240P,[n.VideoQuality.Q_360P]:exports.Quality.Q360P,[n.VideoQuality.Q_480P]:exports.Quality.Q480P,[n.VideoQuality.Q_720P]:exports.Quality.Q720P,[n.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[n.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[n.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[n.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[t],G=t=>t&&{[n.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[n.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[n.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Y=t=>{if(t!==void 0)switch(t){case n.VideoFormat.MPEG:return exports.ContentType.MP4;case n.VideoFormat.DASH:case n.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case n.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case n.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case n.VideoFormat.DASH_WEBM:case n.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case n.VideoFormat.HLS:case n.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case n.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case n.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return a.assertNever(t)}};class J{api;logger;config;subscription=new a.Subscription;timeSynchronisation=new W;experimental;statContext;vsid=P();fieldBlacklist=[];constructor(e,o){this.statContext=e,this.config={...o.config??{},requestRetryCount:1};const s=new a.Subject;this.experimental={error$:s};const r=new V({apiKey:D,apiBaseUrl:v[o.apiEnv],apiEnv:o.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new U({apiTransport:r,refreshAuthToken:o.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new z({api:this.api,error$:s}),this.subscription.add(a.fromEvent(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let o;return new a.Subscription().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?o=a.now():(a.isNonNullable(o)&&this.logEmptyBuffer({duration:a.now()-o}),o=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();a.isNonNullable(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:G(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:j(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:Y(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===n.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=P()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const o=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${o}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const o=this.createLogItem(e);this.logger.log(o)}createLogItem({operation:e,param:o}){const s=this.timeSynchronisation.now(),r={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?b.YES:this.statContext.connectionReused===!1?b.NO:void 0,stat_type:this.statContext.autoplay===!0?y.AUTO:this.statContext.autoplay===!1?y.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};o!==void 0&&(r.param=o);for(const i of this.fieldBlacklist)delete r[i];return{operation:e,timestamp:s,custom:r}}}exports.OneStat=J;
package/esnext.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.30
3
- * Thu, 02 Feb 2023 10:21:08 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-30/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.31
3
+ * Thu, 02 Feb 2023 10:22:17 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-31/doc/
5
5
  */
6
- import{ValueSubject as K,getExponentialDelay as z,ErrorCategory as l,now as E,assertNever as Q,Subscription as k,Subject as W,fromEvent as V,isNonNullable as N}from"@vkontakte/videoplayer-shared/esnext.esm.js";import{VideoQuality as f,HttpConnectionType as v,VideoFormat as d,ChromecastState as j}from"@vkontakte/videoplayer-core/esnext.esm.js";import G from"lodash/debounce.js";const R="_one-stat_",y=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch{return null}})();function Y(t){const e=y?y.getItem(R+t):null;if(e===null)return null;try{return JSON.parse(e)}catch{return null}}function J(t,e){try{y&&y.setItem(R+t,JSON.stringify(e))}catch{}}function X(t){y&&y.removeItem(R+t)}var I={get(t){return Y(t)||null},set(t,e){J(t,e)},remove(t){X(t)}};function Z(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let r=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(r<=2&&(r=33554432+Math.random()*16777216|0),s=r&15,r=r>>4,e[o]=t[o===19?s&3|8:s]);return e.join("")}var b;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(b||(b={}));var c;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(c||(c={}));var w;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(w||(w={}));var p;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(p||(p={}));var P;(function(t){t.AUTO="auto",t.MANUAL=""})(P||(P={}));var S;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(S||(S={}));var T;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(T||(T={}));const L="1.0.30",ee="@vkontakte/videoplayer-statistics",te="CIOPGQJGDIHBABABA",B={[b.PROD]:"https://api.ok.ru",[b.VK_ALIAS]:"https://api.mycdn.me",[b.VIDEOTEST]:"https://videotestapi.ok.ru/api",[b.TEST]:"https://apitest.ok.ru",[b.AUTO]:""},se={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var A;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(A||(A={}));class re{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new K(!1);backoffTimeoutId;constructor(e){this.params=e;const r=I.get("uuid");r?this.uuid=String(r):(this.uuid=Z(),I.set("uuid",this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(r,s,o)||this.logRequest(e)}async logRequest(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const i=async(n,g=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(r,s,o)}catch(a){if(!a||!("error_code"in a)){this.params.error$.next({id:"logRequestUnknown",category:l.NETWORK,message:`Unknown ${r} error`,thrown:a});return}const h=a?.error_code;switch(h){case A.PARAM_SESSION_EXPIRED:case A.PARAM_SESSION_KEY:case A.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),g>0?i(n,g-1):void 0;case A.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),g>0?i(n,g-1):void 0;default:{this.params.error$.next({id:`LogRequest#${h}`,category:l.EXTERNAL_API,message:`${r} error`,data:a});return}}}};return i(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${ee}:${L}`,platform:"WEB",items:e.map(r=>({...r,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=z(this.consequentAuthErrors,se);return new Promise(r=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(r).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:l.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",r={session_data:{version:2,device_id:this.uuid,client_version:L.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(r.session_data.auth_token=this.authToken,r.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,r).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:l.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const o=s?.error_code;switch(o){case A.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:l.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:l.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class x{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:s})}removeEventListener(e,r){if(!(e in this.listeners))return;const s=this.listeners[e];for(let o=0,i=s.length;o<i;o++)if(s[o].callback===r){s.splice(o,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let o=0,i=s.length;o<i;o++){const n=s[o];try{n.callback.call(this,e)}catch(g){Promise.resolve().then(()=>{throw g})}n.options&&n.options.once&&this.removeEventListener(e.type,n.callback)}return!e.defaultPrevented}}class q extends x{constructor(){super(),this.listeners||x.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class oe{constructor(){Object.defineProperty(this,"signal",{value:new q,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document>"u")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch{s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",q.prototype[Symbol.toStringTag]="AbortSignal");function U(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ie(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!U({fetch:e,Request:r,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty("signal")||o)&&(i=function(h,u){let m;u&&u.signal&&(m=u.signal,delete u.signal);const _=new r(h,u);return m&&Object.defineProperty(_,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),_},i.prototype=r.prototype);const n=e;return{fetch:(a,h)=>{const u=i&&i.prototype.isPrototypeOf(a)?a.signal:h?h.signal:void 0;if(u){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(u.aborted)return Promise.reject(m);const _=new Promise((M,F)=>{u.addEventListener("abort",()=>F(m),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([_,n(a,h)])}return n(a,h)},Request:i}}const O=U({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),D=O?ie({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=O?D.fetch:window.fetch;O?D.Request:window.Request;class ne{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==b.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await C(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:l.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),B[b.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,r,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:r,sessionKey:s}),i=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(n){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:l.NETWORK,message:"Unhandled beacon error",thrown:n,data:{method:e,params:r}})}return!1}async sendRequest(e,r,s){const o=E(),i=n=>{if(n instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(n.message)){this.params.error$.next({id:"Network",category:l.NETWORK,message:"Request failed",thrown:n});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:l.NETWORK,message:"Unhandled request error",thrown:n,data:{method:e,params:r,sessionKey:s,time:E()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),C(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:s})}).then(n=>{const g=Number(n.headers.get("content-length"))===0,a=new Date(n.headers.get("date")??"").getTime(),h=E()-o;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,h),!g)return n.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,i)},i)}_prepareQueryParams(e){const r=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&r.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,o])=>r.append(s,typeof o=="string"?o:JSON.stringify(o))),r}}const H=3e3,ae=H*5;class he{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=G(()=>{try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:l.WTF,message:String(e)??"Unknown logger error",thrown:e})}},H,{maxWait:ae});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(r=>{r&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class ue{offset=void 0;constructor(e){this.offset=e}getOffset(){return this.offset??0}setOffset(e){this.offset=e}now(){return Date.now()+(this.offset??0)}date(e=new Date){return e.setTime(e.getTime()+(this.offset??0)),e}addServerTime(e,r){const s=Date.now(),o=e-s-r/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),ce=t=>t&&{[f.INVARIANT]:c.UNKNOWN,[f.Q_144P]:c.Q144P,[f.Q_240P]:c.Q240P,[f.Q_360P]:c.Q360P,[f.Q_480P]:c.Q480P,[f.Q_720P]:c.Q720P,[f.Q_1080P]:c.Q1080P,[f.Q_1440P]:c.Q1440P,[f.Q_2160P]:c.Q2160P,[f.Q_4320P]:c.Q4320P}[t],de=t=>t&&{[v.HTTP1]:S.HTTP1,[v.HTTP2]:S.HTTP2,[v.QUIC]:S.HTTP3}[t],le=t=>{if(t!==void 0)switch(t){case d.MPEG:return p.MP4;case d.DASH:case d.DASH_LIVE:return p.DASH;case d.DASH_SEP:return p.DASH_SEP;case d.DASH_ONDEMAND:return p.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return p.WEBM;case d.HLS:case d.HLS_LIVE:return p.HLS;case d.HLS_ONDEMAND:return p.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return p.RTMP;default:return Q(t)}};class me{api;logger;config;subscription=new k;timeSynchronisation=new ue;experimental;statContext;vsid=$();fieldBlacklist=[];constructor(e,r){this.statContext=e,this.config={...r.config??{},requestRetryCount:1};const s=new W;this.experimental={error$:s};const o=new ne({apiKey:te,apiBaseUrl:B[r.apiEnv],apiEnv:r.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new re({apiTransport:o,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new he({api:this.api,error$:s}),this.subscription.add(V(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let r;return new k().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?r=E():(N(r)&&this.logEmptyBuffer({duration:E()-r}),r=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();N(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:de(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:ce(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:le(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===j.CONNECTED?w.CHROMECAST:w.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=$()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const r=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${r}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const r=this.createLogItem(e);this.logger.log(r)}createLogItem({operation:e,param:r}){const s=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?T.YES:this.statContext.connectionReused===!1?T.NO:void 0,stat_type:this.statContext.autoplay===!0?P.AUTO:this.statContext.autoplay===!1?P.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};r!==void 0&&(o.param=r);for(const i of this.fieldBlacklist)delete o[i];return{operation:e,timestamp:s,custom:o}}}export{b as ApiEnv,S as ConnectionType,p as ContentType,me as OneStat,c as Quality,w as ScreenDestination};
6
+ import{ValueSubject as K,getExponentialDelay as z,ErrorCategory as l,now as E,assertNever as Q,Subscription as k,Subject as W,fromEvent as V,isNonNullable as N}from"@vkontakte/videoplayer-shared/esnext.esm.js";import{VideoQuality as f,HttpConnectionType as v,VideoFormat as d,ChromecastState as j}from"@vkontakte/videoplayer-core/esnext.esm.js";import G from"lodash/debounce.js";const R="_one-stat_",y=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch{return null}})();function Y(t){const e=y?y.getItem(R+t):null;if(e===null)return null;try{return JSON.parse(e)}catch{return null}}function J(t,e){try{y&&y.setItem(R+t,JSON.stringify(e))}catch{}}function X(t){y&&y.removeItem(R+t)}var I={get(t){return Y(t)||null},set(t,e){J(t,e)},remove(t){X(t)}};function Z(){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36);let r=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(r<=2&&(r=33554432+Math.random()*16777216|0),s=r&15,r=r>>4,e[o]=t[o===19?s&3|8:s]);return e.join("")}var b;(function(t){t.PROD="prod",t.VK_ALIAS="vk_alias",t.VIDEOTEST="videotest",t.TEST="test",t.AUTO="auto"})(b||(b={}));var c;(function(t){t.Q144P="144",t.Q240P="240",t.Q360P="360",t.Q480P="480",t.Q720P="720",t.Q1080P="1080",t.Q1440P="1440",t.Q2160P="2160",t.Q4320P="4320",t.UNKNOWN="unknown"})(c||(c={}));var w;(function(t){t.CHROMECAST="chromecast",t.APPLE_TV="appletv",t.PIP="pip",t.HEADPHONES="externalHeadphones",t.SCREEN=""})(w||(w={}));var p;(function(t){t.MP4="mp4",t.DASH="dash",t.DASH_SEP="dash_sep",t.ONDEMAND_DASH="ondemand_dash",t.HLS="hls",t.ONDEMAND_HLS="ondemand_hls",t.WEBM="webm",t.RTMP="rtmp",t.UNKNOWN="unknown"})(p||(p={}));var P;(function(t){t.AUTO="auto",t.MANUAL=""})(P||(P={}));var S;(function(t){t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3"})(S||(S={}));var T;(function(t){t[t.YES=1]="YES",t[t.NO=0]="NO"})(T||(T={}));const L="1.0.31",ee="@vkontakte/videoplayer-statistics",te="CIOPGQJGDIHBABABA",B={[b.PROD]:"https://api.ok.ru",[b.VK_ALIAS]:"https://api.mycdn.me",[b.VIDEOTEST]:"https://videotestapi.ok.ru/api",[b.TEST]:"https://apitest.ok.ru",[b.AUTO]:""},se={start:1e3,factor:1.5,max:5*60*1e3,random:.1};var A;(function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"})(A||(A={}));class re{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new K(!1);backoffTimeoutId;constructor(e){this.params=e;const r=I.get("uuid");r?this.uuid=String(r):(this.uuid=Z(),I.set("uuid",this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(r,s,o)||this.logRequest(e)}async logRequest(e){const r="log.externalLog",s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const i=async(n,g=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(r,s,o)}catch(a){if(!a||!("error_code"in a)){this.params.error$.next({id:"logRequestUnknown",category:l.NETWORK,message:`Unknown ${r} error`,thrown:a});return}const h=a?.error_code;switch(h){case A.PARAM_SESSION_EXPIRED:case A.PARAM_SESSION_KEY:case A.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),g>0?i(n,g-1):void 0;case A.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),g>0?i(n,g-1):void 0;default:{this.params.error$.next({id:`LogRequest#${h}`,category:l.EXTERNAL_API,message:`${r} error`,data:a});return}}}};return i(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`${ee}:${L}`,platform:"WEB",items:e.map(r=>({...r,time:0,type:1}))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=z(this.consequentAuthErrors,se);return new Promise(r=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(r).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:l.NETWORK,message:"Otherwise unhandle errror in authrization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e="auth.anonymLogin",r={session_data:{version:2,device_id:this.uuid,client_version:L.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(r.session_data.auth_token=this.authToken,r.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,r).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:l.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const o=s?.error_code;switch(o){case A.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:l.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:l.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class x{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,r,s){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:r,options:s})}removeEventListener(e,r){if(!(e in this.listeners))return;const s=this.listeners[e];for(let o=0,i=s.length;o<i;o++)if(s[o].callback===r){s.splice(o,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;const s=this.listeners[e.type].slice();for(let o=0,i=s.length;o<i;o++){const n=s[o];try{n.callback.call(this,e)}catch(g){Promise.resolve().then(()=>{throw g})}n.options&&n.options.once&&this.removeEventListener(e.type,n.callback)}return!e.defaultPrevented}}class q extends x{constructor(){super(),this.listeners||x.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}}class oe{constructor(){Object.defineProperty(this,"signal",{value:new q,writable:!0,configurable:!0})}abort(e){let r;try{r=new Event("abort")}catch{typeof document<"u"?document.createEvent?(r=document.createEvent("Event"),r.initEvent("abort",!1,!1)):(r=document.createEventObject(),r.type="abort"):r={type:"abort",bubbles:!1,cancelable:!1}}let s=e;if(s===void 0)if(typeof document>"u")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch{s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(r)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(oe.prototype[Symbol.toStringTag]="AbortController",q.prototype[Symbol.toStringTag]="AbortSignal");function U(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof t.Request=="function"&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController}function ie(t){typeof t=="function"&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!U({fetch:e,Request:r,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty("signal")||o)&&(i=function(h,u){let m;u&&u.signal&&(m=u.signal,delete u.signal);const _=new r(h,u);return m&&Object.defineProperty(_,"signal",{writable:!1,enumerable:!1,configurable:!0,value:m}),_},i.prototype=r.prototype);const n=e;return{fetch:(a,h)=>{const u=i&&i.prototype.isPrototypeOf(a)?a.signal:h?h.signal:void 0;if(u){let m;try{m=new DOMException("Aborted","AbortError")}catch{m=new Error("Aborted"),m.name="AbortError"}if(u.aborted)return Promise.reject(m);const _=new Promise((M,F)=>{u.addEventListener("abort",()=>F(m),{once:!0})});return h&&h.signal&&delete h.signal,Promise.race([_,n(a,h)])}return n(a,h)},Request:i}}const O=U({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),D=O?ie({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=O?D.fetch:window.fetch;O?D.Request:window.Request;class ne{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.apiEnv,this.apiBaseUrl=e.apiBaseUrl,this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==b.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await C(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:l.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),B[b.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,r,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:r,sessionKey:s}),i=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,i)}catch(n){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:l.NETWORK,message:"Unhandled beacon error",thrown:n,data:{method:e,params:r}})}return!1}async sendRequest(e,r,s){const o=E(),i=n=>{if(n instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(n.message)){this.params.error$.next({id:"Network",category:l.NETWORK,message:"Request failed",thrown:n});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:l.NETWORK,message:"Unhandled request error",thrown:n,data:{method:e,params:r,sessionKey:s,time:E()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),C(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:s})}).then(n=>{const g=Number(n.headers.get("content-length"))===0,a=new Date(n.headers.get("date")??"").getTime(),h=E()-o;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,h),!g)return n.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,i)},i)}_prepareQueryParams(e){const r=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&r.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([s,o])=>r.append(s,typeof o=="string"?o:JSON.stringify(o))),r}}const H=3e3,ae=H*5;class he{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=G(()=>{try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:l.WTF,message:String(e)??"Unknown logger error",thrown:e})}},H,{maxWait:ae});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe(r=>{r&&this.debouncedFlush()})}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){this.requestQueue.length!==0&&(this.api.authorized$.getValue()?(e?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):e||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class ue{offset=void 0;constructor(e){this.offset=e}getOffset(){return this.offset??0}setOffset(e){this.offset=e}now(){return Date.now()+(this.offset??0)}date(e=new Date){return e.setTime(e.getTime()+(this.offset??0)),e}addServerTime(e,r){const s=Date.now(),o=e-s-r/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,"0"),ce=t=>t&&{[f.INVARIANT]:c.UNKNOWN,[f.Q_144P]:c.Q144P,[f.Q_240P]:c.Q240P,[f.Q_360P]:c.Q360P,[f.Q_480P]:c.Q480P,[f.Q_720P]:c.Q720P,[f.Q_1080P]:c.Q1080P,[f.Q_1440P]:c.Q1440P,[f.Q_2160P]:c.Q2160P,[f.Q_4320P]:c.Q4320P}[t],de=t=>t&&{[v.HTTP1]:S.HTTP1,[v.HTTP2]:S.HTTP2,[v.QUIC]:S.HTTP3}[t],le=t=>{if(t!==void 0)switch(t){case d.MPEG:return p.MP4;case d.DASH:case d.DASH_LIVE:return p.DASH;case d.DASH_SEP:return p.DASH_SEP;case d.DASH_ONDEMAND:return p.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return p.WEBM;case d.HLS:case d.HLS_LIVE:return p.HLS;case d.HLS_ONDEMAND:return p.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return p.RTMP;default:return Q(t)}};class me{api;logger;config;subscription=new k;timeSynchronisation=new ue;experimental;statContext;vsid=$();fieldBlacklist=[];constructor(e,r){this.statContext=e,this.config={...r.config??{},requestRetryCount:1};const s=new W;this.experimental={error$:s};const o=new ne({apiKey:te,apiBaseUrl:B[r.apiEnv],apiEnv:r.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new re({apiTransport:o,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new he({api:this.api,error$:s}),this.subscription.add(V(window,"beforeunload").subscribe(()=>this.logger.flush(!0)))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let r;return new k().add(e.events.started$.subscribe(()=>{this.logStarted({position:e.info.position$.getValue()})})).add(e.events.looped$.subscribe(()=>{this.resetViewSession(),this.logStarted({position:e.info.position$.getValue()})})).add(e.events.seeked$.subscribe(()=>{this.logSeek()})).add(e.events.willPause$.subscribe(()=>{this.logPause({position:e.info.position$.getValue()})})).add(e.events.willResume$.subscribe(()=>{this.logPlay()})).add(e.events.managedError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.fatalError$.subscribe(({id:s})=>{this.logError({errorType:s})})).add(e.events.inited$.subscribe(()=>{this.logInited()})).add(e.events.canplay$.subscribe(s=>{this.logReady({time:s})})).add(e.events.firstBytes$.subscribe(s=>{this.logFirstBytes({time:s})})).add(e.events.firstFrame$.subscribe(s=>{this.logFirstFrame({time:s})})).add(e.events.watchCoverageRecord$.subscribe(s=>{this.logWatchCoverageRecord(s)})).add(e.events.watchCoverageLive$.subscribe(s=>{this.logWatchCoverageLive(s)})).add(e.info.isStalled$.subscribe(s=>{s?r=E():(N(r)&&this.logEmptyBuffer({duration:E()-r}),r=void 0)})).add(e.events.ended$.subscribe(()=>{const s=e.info.throughputEstimation$.getValue();N(s)&&this.logDownloadSpeed({speed:s/8})})).add(e.info.hostname$.subscribe(s=>{this.updateContext({cdnHostname:s})})).add(e.info.httpConnectionType$.subscribe(s=>{this.updateContext({connectionType:de(s)})})).add(e.info.httpConnectionReused$.subscribe(s=>{this.updateContext({connectionReused:s})})).add(e.info.currentQuality$.subscribe(s=>{this.updateContext({quality:ce(s)})})).add(e.info.currentFormat$.subscribe(s=>{this.updateContext({contentType:le(s)})})).add(e.info.chromecastState$.subscribe(s=>{this.updateContext({destination:s===j.CONNECTED?w.CHROMECAST:w.SCREEN})}))}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=$()}setFieldBlacklist(e=[]){this.fieldBlacklist=e}logInited(){this.log({operation:"init"})}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(e){this.log({operation:"play",param:String(Math.round(e.position))})}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(){this.log({operation:"seek"})}logFirstBytes(e){this.log({operation:"first_bytes",param:String(e.time)})}logFirstFrame(e){this.log({operation:"first_frame",param:String(e.time)})}logError(e){this.log({operation:"error",param:e.errorType})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`}),this.logger.flush(!0)}logWatchCoverageLive(e){const r=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:"watch_coverage_live",param:`${r}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(e){this.log({operation:"download_speed",param:String(e.speed)})}logAdSlotRequest(){this.log({operation:"adv",param:"slot_request"})}logAdStarted(e){this.log({operation:"adv",param:e})}logAdPaused(){this.log({operation:"adv",param:"pause"})}logAdResumed(){this.log({operation:"adv",param:"resume"})}logAdEnded(){this.log({operation:"adv",param:"ended"})}logAdSkipped(){this.log({operation:"adv",param:"skip"})}logAdClicked(){this.log({operation:"adv",param:"click"})}log(e){const r=this.createLogItem(e);this.logger.log(r)}createLogItem({operation:e,param:r}){const s=this.timeSynchronisation.now(),o={vsid:this.vsid,vid:this.statContext.movieId,quality:this.statContext.quality,dst:this.statContext.destination,ct:this.statContext.contentType,aid:this.statContext.albumId,place:this.statContext.place,cdn_host:this.statContext.cdnHostname,connection_type:this.statContext.connectionType,connection_reused:this.statContext.connectionReused===!0?T.YES:this.statContext.connectionReused===!1?T.NO:void 0,stat_type:this.statContext.autoplay===!0?P.AUTO:this.statContext.autoplay===!1?P.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};r!==void 0&&(o.param=r);for(const i of this.fieldBlacklist)delete o[i];return{operation:e,timestamp:s,custom:o}}}export{b as ApiEnv,S as ConnectionType,p as ContentType,me as OneStat,c as Quality,w as ScreenDestination};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/videoplayer-statistics",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "author": "vk.com",
5
5
  "description": "Statistics library for vk.com videoplayer",
6
6
  "homepage": "https://vk.com",