@vkontakte/videoplayer-statistics 1.0.27 → 1.0.28
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 +4 -4
- package/es2015.esm.js +4 -4
- package/es2018.cjs.js +4 -4
- package/es2018.esm.js +4 -4
- package/esnext.cjs.js +4 -4
- package/esnext.esm.js +4 -4
- package/package.json +1 -1
package/es2015.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/es2015.cjs.js'),e=require('@vkontakte/videoplayer-core/es2015.cjs.js');function r(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var n=r(require('lodash/debounce.js'));function o(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}var i='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},s=function(t){return t&&t.Math==Math&&t},a=s('object'==typeof globalThis&&globalThis)||s('object'==typeof window&&window)||s('object'==typeof self&&self)||s('object'==typeof i&&i)||function(){return this}()||Function('return this')(),u=function(t){try{return!!t()}catch(t){return!0}},c=!u((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),h=c,l=Function.prototype,d=l.apply,p=l.call,f='object'==typeof Reflect&&Reflect.apply||(h?p.bind(d):function(){return p.apply(d,arguments)}),v=c,y=Function.prototype,m=y.bind,g=y.call,b=v&&m.bind(g,g),w=v?function(t){return t&&b(t)}:function(t){return t&&function(){return g.apply(t,arguments)}},T=function(t){return'function'==typeof t},S={},E=!u((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),P=c,_=Function.prototype.call,A=P?_.bind(_):function(){return _.apply(_,arguments)},O={},x={}.propertyIsEnumerable,C=Object.getOwnPropertyDescriptor,R=C&&!x.call({1:2},1);O.f=R?function(t){var e=C(this,t);return!!e&&e.enumerable}:x;var k,N,j=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},I=w,L=I({}.toString),Q=I(''.slice),D=function(t){return Q(L(t),8,-1)},$=u,M=D,F=Object,B=w(''.split),q=$((function(){return!F('z').propertyIsEnumerable(0)}))?function(t){return'String'==M(t)?B(t,''):F(t)}:F,U=TypeError,H=function(t){if(null==t)throw U('Can\'t call method on '+t);return t},V=q,z=H,K=T,W=function(t){return'object'==typeof t?null!==t:K(t)},G={},Y=G,J=a,Z=T,X=function(t){return Z(t)?t:void 0},tt=function(t,e){return arguments.length<2?X(Y[t])||X(J[t]):Y[t]&&Y[t][e]||J[t]&&J[t][e]},et=w({}.isPrototypeOf),rt=tt('navigator','userAgent')||'',nt=a,ot=rt,it=nt.process,st=nt.Deno,at=it&&it.versions||st&&st.version,ut=at&&at.v8;ut&&(N=(k=ut.split('.'))[0]>0&&k[0]<4?1:+(k[0]+k[1])),!N&&ot&&(!(k=ot.match(/Edge\/(\d+)/))||k[1]>=74)&&(k=ot.match(/Chrome\/(\d+)/))&&(N=+k[1]);var ct=N,ht=ct,lt=u,dt=!!Object.getOwnPropertySymbols&&!lt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&ht&&ht<41})),pt=dt&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,ft=tt,vt=T,yt=et,mt=Object,gt=pt?function(t){return'symbol'==typeof t}:function(t){var e=ft('Symbol');return vt(e)&&yt(e.prototype,mt(t))},bt=String,wt=function(t){try{return bt(t)}catch(t){return'Object'}},Tt=T,St=wt,Et=TypeError,Pt=function(t){if(Tt(t))return t;throw Et(St(t)+' is not a function')},_t=Pt,At=function(t,e){var r=t[e];return null==r?void 0:_t(r)},Ot=A,xt=T,Ct=W,Rt=TypeError,kt={exports:{}},Nt=a,jt=Object.defineProperty,It=function(t,e){try{jt(Nt,t,{value:e,configurable:!0,writable:!0})}catch(r){Nt[t]=e}return e},Lt=a['__core-js_shared__']||It('__core-js_shared__',{}),Qt=Lt;(kt.exports=function(t,e){return Qt[t]||(Qt[t]=void 0!==e?e:{})})('versions',[]).push({version:'3.24.1',mode:'pure',copyright:'© 2014-2022 Denis Pushkarev (zloirock.ru)',license:'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',source:'https://github.com/zloirock/core-js'});var Dt=H,$t=Object,Mt=function(t){return $t(Dt(t))},Ft=w({}.hasOwnProperty),Bt=Object.hasOwn||function(t,e){return Ft(Mt(t),e)},qt=w,Ut=0,Ht=Math.random(),Vt=qt(1..toString),zt=function(t){return'Symbol('+(void 0===t?'':t)+')_'+Vt(++Ut+Ht,36)},Kt=a,Wt=kt.exports,Gt=Bt,Yt=zt,Jt=dt,Zt=pt,Xt=Wt('wks'),te=Kt.Symbol,ee=te&&te.for,re=Zt?te:te&&te.withoutSetter||Yt,ne=function(t){if(!Gt(Xt,t)||!Jt&&'string'!=typeof Xt[t]){var e='Symbol.'+t;Jt&&Gt(te,t)?Xt[t]=te[t]:Xt[t]=Zt&&ee?ee(e):re(e)}return Xt[t]},oe=A,ie=W,se=gt,ae=At,ue=function(t,e){var r,n;if('string'===e&&xt(r=t.toString)&&!Ct(n=Ot(r,t)))return n;if(xt(r=t.valueOf)&&!Ct(n=Ot(r,t)))return n;if('string'!==e&&xt(r=t.toString)&&!Ct(n=Ot(r,t)))return n;throw Rt('Can\'t convert object to primitive value')},ce=TypeError,he=ne('toPrimitive'),le=function(t,e){if(!ie(t)||se(t))return t;var r,n=ae(t,he);if(n){if(void 0===e&&(e='default'),r=oe(n,t,e),!ie(r)||se(r))return r;throw ce('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),ue(t,e)},de=gt,pe=function(t){var e=le(t,'string');return de(e)?e:e+''},fe=W,ve=a.document,ye=fe(ve)&&fe(ve.createElement),me=function(t){return ye?ve.createElement(t):{}},ge=me,be=!E&&!u((function(){return 7!=Object.defineProperty(ge('div'),'a',{get:function(){return 7}}).a})),we=E,Te=A,Se=O,Ee=j,Pe=function(t){return V(z(t))},_e=pe,Ae=Bt,Oe=be,xe=Object.getOwnPropertyDescriptor;S.f=we?xe:function(t,e){if(t=Pe(t),e=_e(e),Oe)try{return xe(t,e)}catch(t){}if(Ae(t,e))return Ee(!Te(Se.f,t,e),t[e])};var Ce=u,Re=T,ke=/#|\.prototype\./,Ne=function(t,e){var r=Ie[je(t)];return r==Qe||r!=Le&&(Re(e)?Ce(e):!!e)},je=Ne.normalize=function(t){return String(t).replace(ke,'.').toLowerCase()},Ie=Ne.data={},Le=Ne.NATIVE='N',Qe=Ne.POLYFILL='P',De=Ne,$e=Pt,Me=c,Fe=w(w.bind),Be=function(t,e){return $e(t),void 0===e?t:Me?Fe(t,e):function(){return t.apply(e,arguments)}},qe={},Ue=E&&u((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),He=W,Ve=String,ze=TypeError,Ke=function(t){if(He(t))return t;throw ze(Ve(t)+' is not an object')},We=E,Ge=be,Ye=Ue,Je=Ke,Ze=pe,Xe=TypeError,tr=Object.defineProperty,er=Object.getOwnPropertyDescriptor;qe.f=We?Ye?function(t,e,r){if(Je(t),e=Ze(e),Je(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var n=er(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:'configurable'in r?r.configurable:n.configurable,enumerable:'enumerable'in r?r.enumerable:n.enumerable,writable:!1})}return tr(t,e,r)}:tr:function(t,e,r){if(Je(t),e=Ze(e),Je(r),Ge)try{return tr(t,e,r)}catch(t){}if('get'in r||'set'in r)throw Xe('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var rr=qe,nr=j,or=E?function(t,e,r){return rr.f(t,e,nr(1,r))}:function(t,e,r){return t[e]=r,t},ir=a,sr=f,ar=w,ur=T,cr=S.f,hr=De,lr=G,dr=Be,pr=or,fr=Bt,vr=function(t){var e=function(r,n,o){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,n)}return new t(r,n,o)}return sr(t,this,arguments)};return e.prototype=t.prototype,e},yr=function(t,e){var r,n,o,i,s,a,u,c,h=t.target,l=t.global,d=t.stat,p=t.proto,f=l?ir:d?ir[h]:(ir[h]||{}).prototype,v=l?lr:lr[h]||pr(lr,h,{})[h],y=v.prototype;for(o in e)r=!hr(l?o:h+(d?'.':'#')+o,t.forced)&&f&&fr(f,o),s=v[o],r&&(a=t.dontCallGetSet?(c=cr(f,o))&&c.value:f[o]),i=r&&a?a:e[o],r&&typeof s==typeof i||(u=t.bind&&r?dr(i,ir):t.wrap&&r?vr(i):p&&ur(i)?ar(i):i,(t.sham||i&&i.sham||s&&s.sham)&&pr(u,'sham',!0),pr(v,o,u),p&&(fr(lr,n=h+'Prototype')||pr(lr,n,{}),pr(lr[n],o,i),t.real&&y&&!y[o]&&pr(y,o,i)))},mr='process'==D(a.process),gr=or,br=(TypeError,w);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=br(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var wr={};wr[ne('toStringTag')]='z';var Tr='[object z]'===String(wr),Sr=Tr,Er=T,Pr=D,_r=ne('toStringTag'),Ar=Object,Or='Arguments'==Pr(function(){return arguments}()),xr=Sr?Pr:function(t){var e,r,n;return void 0===t?'Undefined':null===t?'Null':'string'==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=Ar(t),_r))?r:Or?Pr(e):'Object'==(n=Pr(e))&&Er(e.callee)?'Arguments':n},Cr=xr,Rr=Tr?{}.toString:function(){return'[object '+Cr(this)+']'},kr=Tr,Nr=qe.f,jr=or,Ir=Bt,Lr=Rr,Qr=ne('toStringTag'),Dr=tt,$r=qe,Mr=E,Fr=ne('species'),Br=et,qr=TypeError,Ur=T,Hr=Lt,Vr=w(Function.toString);Ur(Hr.inspectSource)||(Hr.inspectSource=function(t){return Vr(t)});var zr=Hr.inspectSource,Kr=w,Wr=u,Gr=T,Yr=xr,Jr=zr,Zr=function(){},Xr=[],tn=tt('Reflect','construct'),en=/^\s*(?:class|function)\b/,rn=Kr(en.exec),nn=!en.exec(Zr),on=function(t){if(!Gr(t))return!1;try{return tn(Zr,Xr,t),!0}catch(t){return!1}},sn=function(t){if(!Gr(t))return!1;switch(Yr(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return nn||!!rn(en,Jr(t))}catch(t){return!0}};sn.sham=!0;var an,un,cn,hn,ln=!tn||Wr((function(){var t;return on(on.call)||!on(Object)||!on((function(){t=!0}))||t}))?sn:on,dn=wt,pn=TypeError,fn=Ke,vn=function(t){if(ln(t))return t;throw pn(dn(t)+' is not a constructor')},yn=ne('species'),mn=function(t,e){var r,n=fn(t).constructor;return void 0===n||null==(r=fn(n)[yn])?e:vn(r)},gn=tt('document','documentElement'),bn=w([].slice),wn=TypeError,Tn=/(?:ipad|iphone|ipod).*applewebkit/i.test(rt),Sn=a,En=f,Pn=Be,_n=T,An=Bt,On=u,xn=gn,Cn=bn,Rn=me,kn=function(t,e){if(t<e)throw wn('Not enough arguments');return t},Nn=Tn,jn=mr,In=Sn.setImmediate,Ln=Sn.clearImmediate,Qn=Sn.process,Dn=Sn.Dispatch,$n=Sn.Function,Mn=Sn.MessageChannel,Fn=Sn.String,Bn=0,qn={};try{an=Sn.location}catch(t){}var Un=function(t){if(An(qn,t)){var e=qn[t];delete qn[t],e()}},Hn=function(t){return function(){Un(t)}},Vn=function(t){Un(t.data)},zn=function(t){Sn.postMessage(Fn(t),an.protocol+'//'+an.host)};In&&Ln||(In=function(t){kn(arguments.length,1);var e=_n(t)?t:$n(t),r=Cn(arguments,1);return qn[++Bn]=function(){En(e,void 0,r)},un(Bn),Bn},Ln=function(t){delete qn[t]},jn?un=function(t){Qn.nextTick(Hn(t))}:Dn&&Dn.now?un=function(t){Dn.now(Hn(t))}:Mn&&!Nn?(hn=(cn=new Mn).port2,cn.port1.onmessage=Vn,un=Pn(hn.postMessage,hn)):Sn.addEventListener&&_n(Sn.postMessage)&&!Sn.importScripts&&an&&'file:'!==an.protocol&&!On(zn)?(un=zn,Sn.addEventListener('message',Vn,!1)):un='onreadystatechange'in Rn('script')?function(t){xn.appendChild(Rn('script')).onreadystatechange=function(){xn.removeChild(this),Un(t)}}:function(t){setTimeout(Hn(t),0)});var Kn,Wn,Gn,Yn,Jn,Zn,Xn,to,eo={set:In,clear:Ln},ro=a,no=/ipad|iphone|ipod/i.test(rt)&&void 0!==ro.Pebble,oo=/web0s(?!.*chrome)/i.test(rt),io=a,so=Be,ao=S.f,uo=eo.set,co=Tn,ho=no,lo=oo,po=mr,fo=io.MutationObserver||io.WebKitMutationObserver,vo=io.document,yo=io.process,mo=io.Promise,go=ao(io,'queueMicrotask'),bo=go&&go.value;bo||(Kn=function(){var t,e;for(po&&(t=yo.domain)&&t.exit();Wn;){e=Wn.fn,Wn=Wn.next;try{e()}catch(t){throw Wn?Yn():Gn=void 0,t}}Gn=void 0,t&&t.enter()},co||po||lo||!fo||!vo?!ho&&mo&&mo.resolve?((Xn=mo.resolve(void 0)).constructor=mo,to=so(Xn.then,Xn),Yn=function(){to(Kn)}):po?Yn=function(){yo.nextTick(Kn)}:(uo=so(uo,io),Yn=function(){uo(Kn)}):(Jn=!0,Zn=vo.createTextNode(''),new fo(Kn).observe(Zn,{characterData:!0}),Yn=function(){Zn.data=Jn=!Jn}));var wo=bo||function(t){var e={fn:t,next:void 0};Gn&&(Gn.next=e),Wn||(Wn=e,Yn()),Gn=e},To=a,So=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},Eo=function(){this.head=null,this.tail=null};Eo.prototype={add:function(t){var e={item:t,next:null};this.head?this.tail.next=e:this.head=e,this.tail=e},get:function(){var t=this.head;if(t)return this.head=t.next,this.tail===t&&(this.tail=null),t.item}};var Po,_o,Ao,Oo=Eo,xo=T,Co=zr,Ro=a.WeakMap,ko=xo(Ro)&&/native code/.test(Co(Ro)),No=kt.exports,jo=zt,Io=No('keys'),Lo=ko,Qo=a,Do=w,$o=W,Mo=or,Fo=Bt,Bo=Lt,qo=function(t){return Io[t]||(Io[t]=jo(t))},Uo=Qo.TypeError,Ho=Qo.WeakMap;if(Lo||Bo.state){var Vo=Bo.state||(Bo.state=new Ho),zo=Do(Vo.get),Ko=Do(Vo.has),Wo=Do(Vo.set);Po=function(t,e){if(Ko(Vo,t))throw new Uo('Object already initialized');return e.facade=t,Wo(Vo,t,e),e},_o=function(t){return zo(Vo,t)||{}},Ao=function(t){return Ko(Vo,t)}}else{var Go=qo('state');Po=function(t,e){if(Fo(t,Go))throw new Uo('Object already initialized');return e.facade=t,Mo(t,Go,e),e},_o=function(t){return Fo(t,Go)?t[Go]:{}},Ao=function(t){return Fo(t,Go)}}var Yo={set:Po,get:_o,has:Ao,enforce:function(t){return Ao(t)?_o(t):Po(t,{})},getterFor:function(t){return function(e){var r;if(!$o(e)||(r=_o(e)).type!==t)throw Uo('Incompatible receiver, '+t+' required');return r}}},Jo=a.Promise,Zo='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,Xo=!Zo&&!mr&&'object'==typeof window&&'object'==typeof document,ti=a,ei=Jo,ri=T,ni=De,oi=zr,ii=ne,si=Xo,ai=Zo,ui=ct,ci=ei&&ei.prototype,hi=ii('species'),li=!1,di=ri(ti.PromiseRejectionEvent),pi={CONSTRUCTOR:ni('Promise',(function(){var t=oi(ei),e=t!==String(ei);if(!e&&66===ui)return!0;if(!ci.catch||!ci.finally)return!0;if(!ui||ui<51||!/native code/.test(t)){var r=new ei((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};if((r.constructor={})[hi]=n,!(li=r.then((function(){}))instanceof n))return!0}return!e&&(si||ai)&&!di})),REJECTION_EVENT:di,SUBCLASSING:li},fi={},vi=Pt,yi=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError('Bad Promise constructor');e=t,r=n})),this.resolve=vi(e),this.reject=vi(r)};fi.f=function(t){return new yi(t)};var mi,gi,bi=yr,wi=mr,Ti=a,Si=A,Ei=function(t,e,r,n){return n&&n.enumerable?t[e]=r:gr(t,e,r),t},Pi=function(t,e,r,n){if(t){var o=r?t:t.prototype;Ir(o,Qr)||Nr(o,Qr,{configurable:!0,value:e}),n&&!kr&&jr(o,'toString',Lr)}},_i=function(t){var e=Dr(t),r=$r.f;Mr&&e&&!e[Fr]&&r(e,Fr,{configurable:!0,get:function(){return this}})},Ai=Pt,Oi=T,xi=W,Ci=function(t,e){if(Br(e,t))return t;throw qr('Incorrect invocation')},Ri=mn,ki=eo.set,Ni=wo,ji=function(t,e){var r=To.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ii=So,Li=Oo,Qi=Yo,Di=Jo,$i=fi,Mi=pi.CONSTRUCTOR,Fi=pi.REJECTION_EVENT,Bi=Qi.getterFor('Promise'),qi=Qi.set,Ui=Di&&Di.prototype,Hi=Di,Vi=Ui,zi=Ti.TypeError,Ki=Ti.document,Wi=Ti.process,Gi=$i.f,Yi=Gi,Ji=!!(Ki&&Ki.createEvent&&Ti.dispatchEvent),Zi=function(t){var e;return!(!xi(t)||!Oi(e=t.then))&&e},Xi=function(t,e){var r,n,o,i=e.value,s=1==e.state,a=s?t.ok:t.fail,u=t.resolve,c=t.reject,h=t.domain;try{a?(s||(2===e.rejection&&os(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),o=!0)),r===t.promise?c(zi('Promise-chain cycle')):(n=Zi(r))?Si(n,r,u,c):u(r)):c(i)}catch(t){h&&!o&&h.exit(),c(t)}},ts=function(t,e){t.notified||(t.notified=!0,Ni((function(){for(var r,n=t.reactions;r=n.get();)Xi(r,t);t.notified=!1,e&&!t.rejection&&rs(t)})))},es=function(t,e,r){var n,o;Ji?((n=Ki.createEvent('Event')).promise=e,n.reason=r,n.initEvent(t,!1,!0),Ti.dispatchEvent(n)):n={promise:e,reason:r},!Fi&&(o=Ti['on'+t])?o(n):'unhandledrejection'===t&&ji('Unhandled promise rejection',r)},rs=function(t){Si(ki,Ti,(function(){var e,r=t.facade,n=t.value;if(ns(t)&&(e=Ii((function(){wi?Wi.emit('unhandledRejection',n,r):es('unhandledrejection',r,n)})),t.rejection=wi||ns(t)?2:1,e.error))throw e.value}))},ns=function(t){return 1!==t.rejection&&!t.parent},os=function(t){Si(ki,Ti,(function(){var e=t.facade;wi?Wi.emit('rejectionHandled',e):es('rejectionhandled',e,t.value)}))},is=function(t,e,r){return function(n){t(e,n,r)}},ss=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,ts(t,!0))},as=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw zi('Promise can\'t be resolved itself');var n=Zi(e);n?Ni((function(){var r={done:!1};try{Si(n,e,is(as,r,t),is(ss,r,t))}catch(e){ss(r,e,t)}})):(t.value=e,t.state=1,ts(t,!1))}catch(e){ss({done:!1},e,t)}}};Mi&&(Vi=(Hi=function(t){Ci(this,Vi),Ai(t),Si(mi,this);var e=Bi(this);try{t(is(as,e),is(ss,e))}catch(t){ss(e,t)}}).prototype,(mi=function(t){qi(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new Li,rejection:!1,state:0,value:void 0})}).prototype=Ei(Vi,'then',(function(t,e){var r=Bi(this),n=Gi(Ri(this,Hi));return r.parent=!0,n.ok=!Oi(t)||t,n.fail=Oi(e)&&e,n.domain=wi?Wi.domain:void 0,0==r.state?r.reactions.add(n):Ni((function(){Xi(n,r)})),n.promise})),gi=function(){var t=new mi,e=Bi(t);this.promise=t,this.resolve=is(as,e),this.reject=is(ss,e)},$i.f=Gi=function(t){return t===Hi||undefined===t?new gi(t):Yi(t)}),bi({global:!0,constructor:!0,wrap:!0,forced:Mi},{Promise:Hi}),Pi(Hi,'Promise',!1,!0),_i('Promise');var us={},cs=us,hs=ne('iterator'),ls=Array.prototype,ds=Math.ceil,ps=Math.floor,fs=Math.trunc||function(t){var e=+t;return(e>0?ps:ds)(e)},vs=function(t){var e=+t;return e!=e||0===e?0:fs(e)},ys=Math.min,ms=function(t){return t>0?ys(vs(t),9007199254740991):0},gs=xr,bs=At,ws=us,Ts=ne('iterator'),Ss=function(t){if(null!=t)return bs(t,Ts)||bs(t,'@@iterator')||ws[gs(t)]},Es=A,Ps=Pt,_s=Ke,As=wt,Os=Ss,xs=TypeError,Cs=A,Rs=Ke,ks=At,Ns=Be,js=A,Is=Ke,Ls=wt,Qs=function(t){return void 0!==t&&(cs.Array===t||ls[hs]===t)},Ds=function(t){return ms(t.length)},$s=et,Ms=function(t,e){var r=arguments.length<2?Os(t):e;if(Ps(r))return _s(Es(r,t));throw xs(As(t)+' is not iterable')},Fs=Ss,Bs=function(t,e,r){var n,o;Rs(t);try{if(!(n=ks(t,'return'))){if('throw'===e)throw r;return r}n=Cs(n,t)}catch(t){o=!0,n=t}if('throw'===e)throw r;if(o)throw n;return Rs(n),r},qs=TypeError,Us=function(t,e){this.stopped=t,this.result=e},Hs=Us.prototype,Vs=function(t,e,r){var n,o,i,s,a,u,c,h=r&&r.that,l=!(!r||!r.AS_ENTRIES),d=!(!r||!r.IS_RECORD),p=!(!r||!r.IS_ITERATOR),f=!(!r||!r.INTERRUPTED),v=Ns(e,h),y=function(t){return n&&Bs(n,'normal',t),new Us(!0,t)},m=function(t){return l?(Is(t),f?v(t[0],t[1],y):v(t[0],t[1])):f?v(t,y):v(t)};if(d)n=t.iterator;else if(p)n=t;else{if(!(o=Fs(t)))throw qs(Ls(t)+' is not iterable');if(Qs(o)){for(i=0,s=Ds(t);s>i;i++)if((a=m(t[i]))&&$s(Hs,a))return a;return new Us(!1)}n=Ms(t,o)}for(u=d?t.next:n.next;!(c=js(u,n)).done;){try{a=m(c.value)}catch(t){Bs(n,'throw',t)}if('object'==typeof a&&a&&$s(Hs,a))return a}return new Us(!1)},zs=ne('iterator'),Ks=!1;try{var Ws=0,Gs={next:function(){return{done:!!Ws++}},return:function(){Ks=!0}};Gs[zs]=function(){return this},Array.from(Gs,(function(){throw 2}))}catch(t){}var Ys=Jo,Js=pi.CONSTRUCTOR||!function(t,e){if(!e&&!Ks)return!1;var r=!1;try{var n={};n[zs]=function(){return{next:function(){return{done:r=!0}}}},t(n)}catch(t){}return r}((function(t){Ys.all(t).then(void 0,(function(){}))})),Zs=A,Xs=Pt,ta=fi,ea=So,ra=Vs;yr({target:'Promise',stat:!0,forced:Js},{all:function(t){var e=this,r=ta.f(e),n=r.resolve,o=r.reject,i=ea((function(){var r=Xs(e.resolve),i=[],s=0,a=1;ra(t,(function(t){var u=s++,c=!1;a++,Zs(r,e,t).then((function(t){c||(c=!0,i[u]=t,--a||n(i))}),o)})),--a||n(i)}));return i.error&&o(i.value),r.promise}});var na=yr,oa=pi.CONSTRUCTOR;Jo&&Jo.prototype,na({target:'Promise',proto:!0,forced:oa,real:!0},{catch:function(t){return this.then(void 0,t)}});var ia=A,sa=Pt,aa=fi,ua=So,ca=Vs;yr({target:'Promise',stat:!0,forced:Js},{race:function(t){var e=this,r=aa.f(e),n=r.reject,o=ua((function(){var o=sa(e.resolve);ca(t,(function(t){ia(o,e,t).then(r.resolve,n)}))}));return o.error&&n(o.value),r.promise}});var ha=A,la=fi;yr({target:'Promise',stat:!0,forced:pi.CONSTRUCTOR},{reject:function(t){var e=la.f(this);return ha(e.reject,void 0,t),e.promise}});var da=Ke,pa=W,fa=fi,va=function(t,e){if(da(t),pa(e)&&e.constructor===t)return e;var r=fa.f(t);return(0,r.resolve)(e),r.promise},ya=yr,ma=Jo,ga=pi.CONSTRUCTOR,ba=va,wa=tt('Promise'),Ta=!ga;ya({target:'Promise',stat:!0,forced:true},{resolve:function(t){return ba(Ta&&this===wa?ma:this,t)}});var Sa=yr,Ea=Jo,Pa=u,_a=tt,Aa=T,Oa=mn,xa=va,Ca=Ea&&Ea.prototype;Sa({target:'Promise',proto:!0,real:!0,forced:!!Ea&&Pa((function(){Ca.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=Oa(this,_a('Promise')),r=Aa(t);return this.then(r?function(r){return xa(e,t()).then((function(){return r}))}:t,r?function(r){return xa(e,t()).then((function(){throw r}))}:t)}});var Ra=tt('Promise','finally');const ka=(()=>{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}})();var Na,ja,Ia,La,Qa,Da,$a,Ma={get:t=>function(t){const e=ka?ka.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{ka&&ka.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){ka&&ka.removeItem('_one-stat_'+t)}(t)}};exports.ApiEnv=void 0,(Na=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',Na.VK_ALIAS='vk_alias',Na.VIDEOTEST='videotest',Na.TEST='test',Na.AUTO='auto',exports.Quality=void 0,(ja=exports.Quality||(exports.Quality={})).Q144P='144',ja.Q240P='240',ja.Q360P='360',ja.Q480P='480',ja.Q720P='720',ja.Q1080P='1080',ja.Q1440P='1440',ja.Q2160P='2160',ja.Q4320P='4320',ja.UNKNOWN='unknown',exports.ScreenDestination=void 0,(Ia=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',Ia.APPLE_TV='appletv',Ia.PIP='pip',Ia.HEADPHONES='externalHeadphones',Ia.SCREEN='',exports.ContentType=void 0,(La=exports.ContentType||(exports.ContentType={})).MP4='mp4',La.DASH='dash',La.DASH_SEP='dash_sep',La.ONDEMAND_DASH='ondemand_dash',La.HLS='hls',La.ONDEMAND_HLS='ondemand_hls',La.WEBM='webm',La.RTMP='rtmp',La.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(Qa||(Qa={})),exports.ConnectionType=void 0,(Da=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',Da.HTTP2='http2',Da.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}($a||($a={}));const Fa={[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]:''},Ba={start:1e3,factor:1.5,max:3e5,random:.1};var qa;!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'}(qa||(qa={}));class Ua{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t.ValueSubject(!1),this.params=e;const r=Ma.get('uuid');r?this.uuid=String(r):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let r,n,o=0;for(n=0;n<36;n++)8===n||13===n||18===n||23===n?e[n]='-':14===n?e[n]='4':(o<=2&&(o=33554432+16777216*Math.random()|0),r=15&o,o>>=4,e[n]=t[19===n?3&r|8:r]);return e.join('')}(),Ma.set('uuid',this.uuid))}authorize(t){return o(this,void 0,void 0,(function*(){return this.authToken=null!=t?t:yield this.refreshAuthToken(),this._authorizeWithBackoff()}))}logBeacon(t){const e=this.createLogParams(t),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon('log.externalLog',e,r)||this.logRequest(t)}logRequest(t){var e;return o(this,void 0,void 0,(function*(){const r='log.externalLog',n=this.createLogParams(t),i=null!==(e=this.sessionKey)&&void 0!==e?e:yield this._authorizeWithBackoff();if(!i)return;const s=(t,e=this.params.requestRetryCount)=>o(this,void 0,void 0,(function*(){try{return yield this.params.apiTransport.sendRequest(r,n,i)}catch(n){if(!n||!('error_code'in n))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${r} error`,thrown:n});const o=null==n?void 0:n.error_code;switch(o){case qa.PARAM_SESSION_EXPIRED:case qa.PARAM_SESSION_KEY:case qa.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?s(t,e-1):void 0;case qa.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),e>0?s(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${r} error`,data:n})}}}));return s(t)}))}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return o(this,void 0,void 0,(function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=Ra(this.params.refreshAuthToken(),(()=>{this.refreshAuthTokenPromise=void 0}))),this.refreshAuthTokenPromise}))}createLogParams(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:t.map((t=>Object.assign(Object.assign({},t),{time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t.getExponentialDelay(this.consequentAuthErrors,Ba);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{Ra(this._authorize().then(t).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))),(()=>this.backoffTimeoutId=0))}),e))}))}_authorize(){return o(this,void 0,void 0,(function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=Ra(this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((t=>o(this,void 0,void 0,(function*(){this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case qa.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})))),(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}))}}function Ha(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const Va=Ha({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),za=Va?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!Ha({fetch:e,Request:r,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty('signal')||o)&&(i=function(t,e){let n;e&&e.signal&&(n=e.signal,delete e.signal);const o=new r(t,e);return n&&Object.defineProperty(o,'signal',{writable:!1,enumerable:!1,configurable:!0,value:n}),o},i.prototype=r.prototype);const s=e;return{fetch:(t,e)=>{const r=i&&i.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(r){let n;try{n=new DOMException('Aborted','AbortError')}catch(t){n=new Error('Aborted'),n.name='AbortError'}if(r.aborted)return Promise.reject(n);const o=new Promise(((t,e)=>{r.addEventListener('abort',(()=>e(n)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([o,s(t,e)])}return s(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ka=Va?za.fetch:window.fetch;Va?za.Request:window.Request;class Wa{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var t;return o(this,void 0,void 0,(function*(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),r=yield Ka(e,{method:'GET',mode:'cors',cache:'no-cache'}),n=yield r.json(),o=null===(t=null==n?void 0:n.Answer[0])||void 0===t?void 0:t.data;if(!o)throw new Error('Wrong DNS response');return o}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),Fa[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}))}sendBeacon(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;const n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,o)}catch(r){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:r,data:{method:t,params:e}})}return!1}sendRequest(e,r,n){return o(this,void 0,void 0,(function*(){const o=t.now(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:e,params:r,sessionKey:n,time:t.now()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Ka(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:n})}).then((e=>{var r;const n=0===Number(e.headers.get('content-length')),s=new Date(null!==(r=e.headers.get('date'))&&void 0!==r?r:'').getTime(),a=t.now()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,a),n)return e.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),i)}),i)}))}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,r])=>e.append(t,'string'==typeof r?r:JSON.stringify(r)))),e}}class Ga{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=n.default((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class Ya{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const r=t-Date.now()-e/2;if(Math.abs(r)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(r);else{const t=.2;this.offset=Math.round(t*r+(1-t)*this.offset)}}}const Ja=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0'),Za=t=>t&&{[e.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[e.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[e.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Xa=r=>{if(void 0!==r)switch(r){case e.VideoFormat.MPEG:return exports.ContentType.MP4;case e.VideoFormat.DASH:case e.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case e.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case e.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case e.VideoFormat.DASH_WEBM:case e.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case e.VideoFormat.HLS:case e.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case e.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case e.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return t.assertNever(r)}};exports.OneStat=class{constructor(e,r){var n;this.subscription=new t.Subscription,this.timeSynchronisation=new Ya,this.vsid=Ja(),this.fieldBlacklist=[],this.statContext=e,this.config=Object.assign(Object.assign({},null!==(n=r.config)&&void 0!==n?n:{}),{requestRetryCount:1});const o=new t.Subject;this.experimental={error$:o};const i=new Wa({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:Fa[r.apiEnv],apiEnv:r.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new Ua({apiTransport:i,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new Ga({api:this.api,error$:o}),this.subscription.add(t.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext=Object.assign(Object.assign({},this.statContext),t)}attachTo(r){let n;return(new t.Subscription).add(t.merge(r.events.started$,r.events.looped$).subscribe((()=>{this.logStarted({position:r.info.position$.getValue()})}))).add(r.events.looped$.subscribe((()=>{this.resetViewSession()}))).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:t})=>{this.logError({errorType:t})}))).add(r.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(r.events.inited$.subscribe((()=>{this.logInited()}))).add(r.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(r.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(r.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(r.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(r.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(r.info.isStalled$.subscribe((e=>{e?n=t.now():(t.isNonNullable(n)&&this.logEmptyBuffer({duration:t.now()-n}),n=void 0)}))).add(r.events.ended$.subscribe((()=>{const e=r.info.throughputEstimation$.getValue();t.isNonNullable(e)&&this.logDownloadSpeed({speed:e/8})}))).add(r.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(r.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:Za(t)})}))).add(r.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(r.info.currentQuality$.subscribe((t=>{var r;this.updateContext({quality:(r=t,r&&{[e.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[e.VideoQuality.Q_144P]:exports.Quality.Q144P,[e.VideoQuality.Q_240P]:exports.Quality.Q240P,[e.VideoQuality.Q_360P]:exports.Quality.Q360P,[e.VideoQuality.Q_480P]:exports.Quality.Q480P,[e.VideoQuality.Q_720P]:exports.Quality.Q720P,[e.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[e.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[e.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[e.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[r])})}))).add(r.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:Xa(t)})}))).add(r.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===e.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=Ja()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),r=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${r}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){const r=this.timeSynchronisation.now(),n={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:!0===this.statContext.connectionReused?$a.YES:!1===this.statContext.connectionReused?$a.NO:void 0,stat_type:!0===this.statContext.autoplay?Qa.AUTO:!1===this.statContext.autoplay?Qa.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(n.param=e);for(const t of this.fieldBlacklist)delete n[t];return{operation:t,timestamp:r,custom:n}}};
|
|
6
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/es2015.cjs.js'),e=require('@vkontakte/videoplayer-core/es2015.cjs.js');function r(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var o=r(require('lodash/debounce.js'));function n(t,e,r,o){return new(r||(r=Promise))((function(n,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((o=o.apply(t,e||[])).next())}))}var i='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},s=function(t){return t&&t.Math==Math&&t},a=s('object'==typeof globalThis&&globalThis)||s('object'==typeof window&&window)||s('object'==typeof self&&self)||s('object'==typeof i&&i)||function(){return this}()||Function('return this')(),u=function(t){try{return!!t()}catch(t){return!0}},c=!u((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),h=c,l=Function.prototype,d=l.apply,p=l.call,f='object'==typeof Reflect&&Reflect.apply||(h?p.bind(d):function(){return p.apply(d,arguments)}),v=c,y=Function.prototype,m=y.bind,g=y.call,b=v&&m.bind(g,g),w=v?function(t){return t&&b(t)}:function(t){return t&&function(){return g.apply(t,arguments)}},T=function(t){return'function'==typeof t},S={},E=!u((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),P=c,_=Function.prototype.call,A=P?_.bind(_):function(){return _.apply(_,arguments)},O={},x={}.propertyIsEnumerable,C=Object.getOwnPropertyDescriptor,R=C&&!x.call({1:2},1);O.f=R?function(t){var e=C(this,t);return!!e&&e.enumerable}:x;var k,N,j=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},I=w,L=I({}.toString),Q=I(''.slice),D=function(t){return Q(L(t),8,-1)},$=u,M=D,F=Object,B=w(''.split),q=$((function(){return!F('z').propertyIsEnumerable(0)}))?function(t){return'String'==M(t)?B(t,''):F(t)}:F,U=TypeError,H=function(t){if(null==t)throw U('Can\'t call method on '+t);return t},V=q,z=H,K=T,W=function(t){return'object'==typeof t?null!==t:K(t)},G={},Y=G,J=a,Z=T,X=function(t){return Z(t)?t:void 0},tt=function(t,e){return arguments.length<2?X(Y[t])||X(J[t]):Y[t]&&Y[t][e]||J[t]&&J[t][e]},et=w({}.isPrototypeOf),rt=tt('navigator','userAgent')||'',ot=a,nt=rt,it=ot.process,st=ot.Deno,at=it&&it.versions||st&&st.version,ut=at&&at.v8;ut&&(N=(k=ut.split('.'))[0]>0&&k[0]<4?1:+(k[0]+k[1])),!N&&nt&&(!(k=nt.match(/Edge\/(\d+)/))||k[1]>=74)&&(k=nt.match(/Chrome\/(\d+)/))&&(N=+k[1]);var ct=N,ht=ct,lt=u,dt=!!Object.getOwnPropertySymbols&&!lt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&ht&&ht<41})),pt=dt&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,ft=tt,vt=T,yt=et,mt=Object,gt=pt?function(t){return'symbol'==typeof t}:function(t){var e=ft('Symbol');return vt(e)&&yt(e.prototype,mt(t))},bt=String,wt=function(t){try{return bt(t)}catch(t){return'Object'}},Tt=T,St=wt,Et=TypeError,Pt=function(t){if(Tt(t))return t;throw Et(St(t)+' is not a function')},_t=Pt,At=function(t,e){var r=t[e];return null==r?void 0:_t(r)},Ot=A,xt=T,Ct=W,Rt=TypeError,kt={exports:{}},Nt=a,jt=Object.defineProperty,It=function(t,e){try{jt(Nt,t,{value:e,configurable:!0,writable:!0})}catch(r){Nt[t]=e}return e},Lt=a['__core-js_shared__']||It('__core-js_shared__',{}),Qt=Lt;(kt.exports=function(t,e){return Qt[t]||(Qt[t]=void 0!==e?e:{})})('versions',[]).push({version:'3.24.1',mode:'pure',copyright:'© 2014-2022 Denis Pushkarev (zloirock.ru)',license:'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',source:'https://github.com/zloirock/core-js'});var Dt=H,$t=Object,Mt=function(t){return $t(Dt(t))},Ft=w({}.hasOwnProperty),Bt=Object.hasOwn||function(t,e){return Ft(Mt(t),e)},qt=w,Ut=0,Ht=Math.random(),Vt=qt(1..toString),zt=function(t){return'Symbol('+(void 0===t?'':t)+')_'+Vt(++Ut+Ht,36)},Kt=a,Wt=kt.exports,Gt=Bt,Yt=zt,Jt=dt,Zt=pt,Xt=Wt('wks'),te=Kt.Symbol,ee=te&&te.for,re=Zt?te:te&&te.withoutSetter||Yt,oe=function(t){if(!Gt(Xt,t)||!Jt&&'string'!=typeof Xt[t]){var e='Symbol.'+t;Jt&&Gt(te,t)?Xt[t]=te[t]:Xt[t]=Zt&&ee?ee(e):re(e)}return Xt[t]},ne=A,ie=W,se=gt,ae=At,ue=function(t,e){var r,o;if('string'===e&&xt(r=t.toString)&&!Ct(o=Ot(r,t)))return o;if(xt(r=t.valueOf)&&!Ct(o=Ot(r,t)))return o;if('string'!==e&&xt(r=t.toString)&&!Ct(o=Ot(r,t)))return o;throw Rt('Can\'t convert object to primitive value')},ce=TypeError,he=oe('toPrimitive'),le=function(t,e){if(!ie(t)||se(t))return t;var r,o=ae(t,he);if(o){if(void 0===e&&(e='default'),r=ne(o,t,e),!ie(r)||se(r))return r;throw ce('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),ue(t,e)},de=gt,pe=function(t){var e=le(t,'string');return de(e)?e:e+''},fe=W,ve=a.document,ye=fe(ve)&&fe(ve.createElement),me=function(t){return ye?ve.createElement(t):{}},ge=me,be=!E&&!u((function(){return 7!=Object.defineProperty(ge('div'),'a',{get:function(){return 7}}).a})),we=E,Te=A,Se=O,Ee=j,Pe=function(t){return V(z(t))},_e=pe,Ae=Bt,Oe=be,xe=Object.getOwnPropertyDescriptor;S.f=we?xe:function(t,e){if(t=Pe(t),e=_e(e),Oe)try{return xe(t,e)}catch(t){}if(Ae(t,e))return Ee(!Te(Se.f,t,e),t[e])};var Ce=u,Re=T,ke=/#|\.prototype\./,Ne=function(t,e){var r=Ie[je(t)];return r==Qe||r!=Le&&(Re(e)?Ce(e):!!e)},je=Ne.normalize=function(t){return String(t).replace(ke,'.').toLowerCase()},Ie=Ne.data={},Le=Ne.NATIVE='N',Qe=Ne.POLYFILL='P',De=Ne,$e=Pt,Me=c,Fe=w(w.bind),Be=function(t,e){return $e(t),void 0===e?t:Me?Fe(t,e):function(){return t.apply(e,arguments)}},qe={},Ue=E&&u((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),He=W,Ve=String,ze=TypeError,Ke=function(t){if(He(t))return t;throw ze(Ve(t)+' is not an object')},We=E,Ge=be,Ye=Ue,Je=Ke,Ze=pe,Xe=TypeError,tr=Object.defineProperty,er=Object.getOwnPropertyDescriptor;qe.f=We?Ye?function(t,e,r){if(Je(t),e=Ze(e),Je(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var o=er(t,e);o&&o.writable&&(t[e]=r.value,r={configurable:'configurable'in r?r.configurable:o.configurable,enumerable:'enumerable'in r?r.enumerable:o.enumerable,writable:!1})}return tr(t,e,r)}:tr:function(t,e,r){if(Je(t),e=Ze(e),Je(r),Ge)try{return tr(t,e,r)}catch(t){}if('get'in r||'set'in r)throw Xe('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var rr=qe,or=j,nr=E?function(t,e,r){return rr.f(t,e,or(1,r))}:function(t,e,r){return t[e]=r,t},ir=a,sr=f,ar=w,ur=T,cr=S.f,hr=De,lr=G,dr=Be,pr=nr,fr=Bt,vr=function(t){var e=function(r,o,n){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,o)}return new t(r,o,n)}return sr(t,this,arguments)};return e.prototype=t.prototype,e},yr=function(t,e){var r,o,n,i,s,a,u,c,h=t.target,l=t.global,d=t.stat,p=t.proto,f=l?ir:d?ir[h]:(ir[h]||{}).prototype,v=l?lr:lr[h]||pr(lr,h,{})[h],y=v.prototype;for(n in e)r=!hr(l?n:h+(d?'.':'#')+n,t.forced)&&f&&fr(f,n),s=v[n],r&&(a=t.dontCallGetSet?(c=cr(f,n))&&c.value:f[n]),i=r&&a?a:e[n],r&&typeof s==typeof i||(u=t.bind&&r?dr(i,ir):t.wrap&&r?vr(i):p&&ur(i)?ar(i):i,(t.sham||i&&i.sham||s&&s.sham)&&pr(u,'sham',!0),pr(v,n,u),p&&(fr(lr,o=h+'Prototype')||pr(lr,o,{}),pr(lr[o],n,i),t.real&&y&&!y[n]&&pr(y,n,i)))},mr='process'==D(a.process),gr=nr,br=(TypeError,w);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=br(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var wr={};wr[oe('toStringTag')]='z';var Tr='[object z]'===String(wr),Sr=Tr,Er=T,Pr=D,_r=oe('toStringTag'),Ar=Object,Or='Arguments'==Pr(function(){return arguments}()),xr=Sr?Pr:function(t){var e,r,o;return void 0===t?'Undefined':null===t?'Null':'string'==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=Ar(t),_r))?r:Or?Pr(e):'Object'==(o=Pr(e))&&Er(e.callee)?'Arguments':o},Cr=xr,Rr=Tr?{}.toString:function(){return'[object '+Cr(this)+']'},kr=Tr,Nr=qe.f,jr=nr,Ir=Bt,Lr=Rr,Qr=oe('toStringTag'),Dr=tt,$r=qe,Mr=E,Fr=oe('species'),Br=et,qr=TypeError,Ur=T,Hr=Lt,Vr=w(Function.toString);Ur(Hr.inspectSource)||(Hr.inspectSource=function(t){return Vr(t)});var zr=Hr.inspectSource,Kr=w,Wr=u,Gr=T,Yr=xr,Jr=zr,Zr=function(){},Xr=[],to=tt('Reflect','construct'),eo=/^\s*(?:class|function)\b/,ro=Kr(eo.exec),oo=!eo.exec(Zr),no=function(t){if(!Gr(t))return!1;try{return to(Zr,Xr,t),!0}catch(t){return!1}},io=function(t){if(!Gr(t))return!1;switch(Yr(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return oo||!!ro(eo,Jr(t))}catch(t){return!0}};io.sham=!0;var so,ao,uo,co,ho=!to||Wr((function(){var t;return no(no.call)||!no(Object)||!no((function(){t=!0}))||t}))?io:no,lo=wt,po=TypeError,fo=Ke,vo=function(t){if(ho(t))return t;throw po(lo(t)+' is not a constructor')},yo=oe('species'),mo=function(t,e){var r,o=fo(t).constructor;return void 0===o||null==(r=fo(o)[yo])?e:vo(r)},go=tt('document','documentElement'),bo=w([].slice),wo=TypeError,To=/(?:ipad|iphone|ipod).*applewebkit/i.test(rt),So=a,Eo=f,Po=Be,_o=T,Ao=Bt,Oo=u,xo=go,Co=bo,Ro=me,ko=function(t,e){if(t<e)throw wo('Not enough arguments');return t},No=To,jo=mr,Io=So.setImmediate,Lo=So.clearImmediate,Qo=So.process,Do=So.Dispatch,$o=So.Function,Mo=So.MessageChannel,Fo=So.String,Bo=0,qo={};try{so=So.location}catch(t){}var Uo=function(t){if(Ao(qo,t)){var e=qo[t];delete qo[t],e()}},Ho=function(t){return function(){Uo(t)}},Vo=function(t){Uo(t.data)},zo=function(t){So.postMessage(Fo(t),so.protocol+'//'+so.host)};Io&&Lo||(Io=function(t){ko(arguments.length,1);var e=_o(t)?t:$o(t),r=Co(arguments,1);return qo[++Bo]=function(){Eo(e,void 0,r)},ao(Bo),Bo},Lo=function(t){delete qo[t]},jo?ao=function(t){Qo.nextTick(Ho(t))}:Do&&Do.now?ao=function(t){Do.now(Ho(t))}:Mo&&!No?(co=(uo=new Mo).port2,uo.port1.onmessage=Vo,ao=Po(co.postMessage,co)):So.addEventListener&&_o(So.postMessage)&&!So.importScripts&&so&&'file:'!==so.protocol&&!Oo(zo)?(ao=zo,So.addEventListener('message',Vo,!1)):ao='onreadystatechange'in Ro('script')?function(t){xo.appendChild(Ro('script')).onreadystatechange=function(){xo.removeChild(this),Uo(t)}}:function(t){setTimeout(Ho(t),0)});var Ko,Wo,Go,Yo,Jo,Zo,Xo,tn,en={set:Io,clear:Lo},rn=a,on=/ipad|iphone|ipod/i.test(rt)&&void 0!==rn.Pebble,nn=/web0s(?!.*chrome)/i.test(rt),sn=a,an=Be,un=S.f,cn=en.set,hn=To,ln=on,dn=nn,pn=mr,fn=sn.MutationObserver||sn.WebKitMutationObserver,vn=sn.document,yn=sn.process,mn=sn.Promise,gn=un(sn,'queueMicrotask'),bn=gn&&gn.value;bn||(Ko=function(){var t,e;for(pn&&(t=yn.domain)&&t.exit();Wo;){e=Wo.fn,Wo=Wo.next;try{e()}catch(t){throw Wo?Yo():Go=void 0,t}}Go=void 0,t&&t.enter()},hn||pn||dn||!fn||!vn?!ln&&mn&&mn.resolve?((Xo=mn.resolve(void 0)).constructor=mn,tn=an(Xo.then,Xo),Yo=function(){tn(Ko)}):pn?Yo=function(){yn.nextTick(Ko)}:(cn=an(cn,sn),Yo=function(){cn(Ko)}):(Jo=!0,Zo=vn.createTextNode(''),new fn(Ko).observe(Zo,{characterData:!0}),Yo=function(){Zo.data=Jo=!Jo}));var wn=bn||function(t){var e={fn:t,next:void 0};Go&&(Go.next=e),Wo||(Wo=e,Yo()),Go=e},Tn=a,Sn=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},En=function(){this.head=null,this.tail=null};En.prototype={add:function(t){var e={item:t,next:null};this.head?this.tail.next=e:this.head=e,this.tail=e},get:function(){var t=this.head;if(t)return this.head=t.next,this.tail===t&&(this.tail=null),t.item}};var Pn,_n,An,On=En,xn=T,Cn=zr,Rn=a.WeakMap,kn=xn(Rn)&&/native code/.test(Cn(Rn)),Nn=kt.exports,jn=zt,In=Nn('keys'),Ln=kn,Qn=a,Dn=w,$n=W,Mn=nr,Fn=Bt,Bn=Lt,qn=function(t){return In[t]||(In[t]=jn(t))},Un=Qn.TypeError,Hn=Qn.WeakMap;if(Ln||Bn.state){var Vn=Bn.state||(Bn.state=new Hn),zn=Dn(Vn.get),Kn=Dn(Vn.has),Wn=Dn(Vn.set);Pn=function(t,e){if(Kn(Vn,t))throw new Un('Object already initialized');return e.facade=t,Wn(Vn,t,e),e},_n=function(t){return zn(Vn,t)||{}},An=function(t){return Kn(Vn,t)}}else{var Gn=qn('state');Pn=function(t,e){if(Fn(t,Gn))throw new Un('Object already initialized');return e.facade=t,Mn(t,Gn,e),e},_n=function(t){return Fn(t,Gn)?t[Gn]:{}},An=function(t){return Fn(t,Gn)}}var Yn={set:Pn,get:_n,has:An,enforce:function(t){return An(t)?_n(t):Pn(t,{})},getterFor:function(t){return function(e){var r;if(!$n(e)||(r=_n(e)).type!==t)throw Un('Incompatible receiver, '+t+' required');return r}}},Jn=a.Promise,Zn='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,Xn=!Zn&&!mr&&'object'==typeof window&&'object'==typeof document,ti=a,ei=Jn,ri=T,oi=De,ni=zr,ii=oe,si=Xn,ai=Zn,ui=ct,ci=ei&&ei.prototype,hi=ii('species'),li=!1,di=ri(ti.PromiseRejectionEvent),pi={CONSTRUCTOR:oi('Promise',(function(){var t=ni(ei),e=t!==String(ei);if(!e&&66===ui)return!0;if(!ci.catch||!ci.finally)return!0;if(!ui||ui<51||!/native code/.test(t)){var r=new ei((function(t){t(1)})),o=function(t){t((function(){}),(function(){}))};if((r.constructor={})[hi]=o,!(li=r.then((function(){}))instanceof o))return!0}return!e&&(si||ai)&&!di})),REJECTION_EVENT:di,SUBCLASSING:li},fi={},vi=Pt,yi=function(t){var e,r;this.promise=new t((function(t,o){if(void 0!==e||void 0!==r)throw TypeError('Bad Promise constructor');e=t,r=o})),this.resolve=vi(e),this.reject=vi(r)};fi.f=function(t){return new yi(t)};var mi,gi,bi=yr,wi=mr,Ti=a,Si=A,Ei=function(t,e,r,o){return o&&o.enumerable?t[e]=r:gr(t,e,r),t},Pi=function(t,e,r,o){if(t){var n=r?t:t.prototype;Ir(n,Qr)||Nr(n,Qr,{configurable:!0,value:e}),o&&!kr&&jr(n,'toString',Lr)}},_i=function(t){var e=Dr(t),r=$r.f;Mr&&e&&!e[Fr]&&r(e,Fr,{configurable:!0,get:function(){return this}})},Ai=Pt,Oi=T,xi=W,Ci=function(t,e){if(Br(e,t))return t;throw qr('Incorrect invocation')},Ri=mo,ki=en.set,Ni=wn,ji=function(t,e){var r=Tn.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ii=Sn,Li=On,Qi=Yn,Di=Jn,$i=fi,Mi=pi.CONSTRUCTOR,Fi=pi.REJECTION_EVENT,Bi=Qi.getterFor('Promise'),qi=Qi.set,Ui=Di&&Di.prototype,Hi=Di,Vi=Ui,zi=Ti.TypeError,Ki=Ti.document,Wi=Ti.process,Gi=$i.f,Yi=Gi,Ji=!!(Ki&&Ki.createEvent&&Ti.dispatchEvent),Zi=function(t){var e;return!(!xi(t)||!Oi(e=t.then))&&e},Xi=function(t,e){var r,o,n,i=e.value,s=1==e.state,a=s?t.ok:t.fail,u=t.resolve,c=t.reject,h=t.domain;try{a?(s||(2===e.rejection&&ns(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),n=!0)),r===t.promise?c(zi('Promise-chain cycle')):(o=Zi(r))?Si(o,r,u,c):u(r)):c(i)}catch(t){h&&!n&&h.exit(),c(t)}},ts=function(t,e){t.notified||(t.notified=!0,Ni((function(){for(var r,o=t.reactions;r=o.get();)Xi(r,t);t.notified=!1,e&&!t.rejection&&rs(t)})))},es=function(t,e,r){var o,n;Ji?((o=Ki.createEvent('Event')).promise=e,o.reason=r,o.initEvent(t,!1,!0),Ti.dispatchEvent(o)):o={promise:e,reason:r},!Fi&&(n=Ti['on'+t])?n(o):'unhandledrejection'===t&&ji('Unhandled promise rejection',r)},rs=function(t){Si(ki,Ti,(function(){var e,r=t.facade,o=t.value;if(os(t)&&(e=Ii((function(){wi?Wi.emit('unhandledRejection',o,r):es('unhandledrejection',r,o)})),t.rejection=wi||os(t)?2:1,e.error))throw e.value}))},os=function(t){return 1!==t.rejection&&!t.parent},ns=function(t){Si(ki,Ti,(function(){var e=t.facade;wi?Wi.emit('rejectionHandled',e):es('rejectionhandled',e,t.value)}))},is=function(t,e,r){return function(o){t(e,o,r)}},ss=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,ts(t,!0))},as=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw zi('Promise can\'t be resolved itself');var o=Zi(e);o?Ni((function(){var r={done:!1};try{Si(o,e,is(as,r,t),is(ss,r,t))}catch(e){ss(r,e,t)}})):(t.value=e,t.state=1,ts(t,!1))}catch(e){ss({done:!1},e,t)}}};Mi&&(Vi=(Hi=function(t){Ci(this,Vi),Ai(t),Si(mi,this);var e=Bi(this);try{t(is(as,e),is(ss,e))}catch(t){ss(e,t)}}).prototype,(mi=function(t){qi(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new Li,rejection:!1,state:0,value:void 0})}).prototype=Ei(Vi,'then',(function(t,e){var r=Bi(this),o=Gi(Ri(this,Hi));return r.parent=!0,o.ok=!Oi(t)||t,o.fail=Oi(e)&&e,o.domain=wi?Wi.domain:void 0,0==r.state?r.reactions.add(o):Ni((function(){Xi(o,r)})),o.promise})),gi=function(){var t=new mi,e=Bi(t);this.promise=t,this.resolve=is(as,e),this.reject=is(ss,e)},$i.f=Gi=function(t){return t===Hi||undefined===t?new gi(t):Yi(t)}),bi({global:!0,constructor:!0,wrap:!0,forced:Mi},{Promise:Hi}),Pi(Hi,'Promise',!1,!0),_i('Promise');var us={},cs=us,hs=oe('iterator'),ls=Array.prototype,ds=Math.ceil,ps=Math.floor,fs=Math.trunc||function(t){var e=+t;return(e>0?ps:ds)(e)},vs=function(t){var e=+t;return e!=e||0===e?0:fs(e)},ys=Math.min,ms=function(t){return t>0?ys(vs(t),9007199254740991):0},gs=xr,bs=At,ws=us,Ts=oe('iterator'),Ss=function(t){if(null!=t)return bs(t,Ts)||bs(t,'@@iterator')||ws[gs(t)]},Es=A,Ps=Pt,_s=Ke,As=wt,Os=Ss,xs=TypeError,Cs=A,Rs=Ke,ks=At,Ns=Be,js=A,Is=Ke,Ls=wt,Qs=function(t){return void 0!==t&&(cs.Array===t||ls[hs]===t)},Ds=function(t){return ms(t.length)},$s=et,Ms=function(t,e){var r=arguments.length<2?Os(t):e;if(Ps(r))return _s(Es(r,t));throw xs(As(t)+' is not iterable')},Fs=Ss,Bs=function(t,e,r){var o,n;Rs(t);try{if(!(o=ks(t,'return'))){if('throw'===e)throw r;return r}o=Cs(o,t)}catch(t){n=!0,o=t}if('throw'===e)throw r;if(n)throw o;return Rs(o),r},qs=TypeError,Us=function(t,e){this.stopped=t,this.result=e},Hs=Us.prototype,Vs=function(t,e,r){var o,n,i,s,a,u,c,h=r&&r.that,l=!(!r||!r.AS_ENTRIES),d=!(!r||!r.IS_RECORD),p=!(!r||!r.IS_ITERATOR),f=!(!r||!r.INTERRUPTED),v=Ns(e,h),y=function(t){return o&&Bs(o,'normal',t),new Us(!0,t)},m=function(t){return l?(Is(t),f?v(t[0],t[1],y):v(t[0],t[1])):f?v(t,y):v(t)};if(d)o=t.iterator;else if(p)o=t;else{if(!(n=Fs(t)))throw qs(Ls(t)+' is not iterable');if(Qs(n)){for(i=0,s=Ds(t);s>i;i++)if((a=m(t[i]))&&$s(Hs,a))return a;return new Us(!1)}o=Ms(t,n)}for(u=d?t.next:o.next;!(c=js(u,o)).done;){try{a=m(c.value)}catch(t){Bs(o,'throw',t)}if('object'==typeof a&&a&&$s(Hs,a))return a}return new Us(!1)},zs=oe('iterator'),Ks=!1;try{var Ws=0,Gs={next:function(){return{done:!!Ws++}},return:function(){Ks=!0}};Gs[zs]=function(){return this},Array.from(Gs,(function(){throw 2}))}catch(t){}var Ys=Jn,Js=pi.CONSTRUCTOR||!function(t,e){if(!e&&!Ks)return!1;var r=!1;try{var o={};o[zs]=function(){return{next:function(){return{done:r=!0}}}},t(o)}catch(t){}return r}((function(t){Ys.all(t).then(void 0,(function(){}))})),Zs=A,Xs=Pt,ta=fi,ea=Sn,ra=Vs;yr({target:'Promise',stat:!0,forced:Js},{all:function(t){var e=this,r=ta.f(e),o=r.resolve,n=r.reject,i=ea((function(){var r=Xs(e.resolve),i=[],s=0,a=1;ra(t,(function(t){var u=s++,c=!1;a++,Zs(r,e,t).then((function(t){c||(c=!0,i[u]=t,--a||o(i))}),n)})),--a||o(i)}));return i.error&&n(i.value),r.promise}});var oa=yr,na=pi.CONSTRUCTOR;Jn&&Jn.prototype,oa({target:'Promise',proto:!0,forced:na,real:!0},{catch:function(t){return this.then(void 0,t)}});var ia=A,sa=Pt,aa=fi,ua=Sn,ca=Vs;yr({target:'Promise',stat:!0,forced:Js},{race:function(t){var e=this,r=aa.f(e),o=r.reject,n=ua((function(){var n=sa(e.resolve);ca(t,(function(t){ia(n,e,t).then(r.resolve,o)}))}));return n.error&&o(n.value),r.promise}});var ha=A,la=fi;yr({target:'Promise',stat:!0,forced:pi.CONSTRUCTOR},{reject:function(t){var e=la.f(this);return ha(e.reject,void 0,t),e.promise}});var da=Ke,pa=W,fa=fi,va=function(t,e){if(da(t),pa(e)&&e.constructor===t)return e;var r=fa.f(t);return(0,r.resolve)(e),r.promise},ya=yr,ma=Jn,ga=pi.CONSTRUCTOR,ba=va,wa=tt('Promise'),Ta=!ga;ya({target:'Promise',stat:!0,forced:true},{resolve:function(t){return ba(Ta&&this===wa?ma:this,t)}});var Sa=yr,Ea=Jn,Pa=u,_a=tt,Aa=T,Oa=mo,xa=va,Ca=Ea&&Ea.prototype;Sa({target:'Promise',proto:!0,real:!0,forced:!!Ea&&Pa((function(){Ca.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=Oa(this,_a('Promise')),r=Aa(t);return this.then(r?function(r){return xa(e,t()).then((function(){return r}))}:t,r?function(r){return xa(e,t()).then((function(){throw r}))}:t)}});var Ra=tt('Promise','finally');const ka=(()=>{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}})();var Na,ja,Ia,La,Qa,Da,$a,Ma={get:t=>function(t){const e=ka?ka.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{ka&&ka.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){ka&&ka.removeItem('_one-stat_'+t)}(t)}};exports.ApiEnv=void 0,(Na=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',Na.VK_ALIAS='vk_alias',Na.VIDEOTEST='videotest',Na.TEST='test',Na.AUTO='auto',exports.Quality=void 0,(ja=exports.Quality||(exports.Quality={})).Q144P='144',ja.Q240P='240',ja.Q360P='360',ja.Q480P='480',ja.Q720P='720',ja.Q1080P='1080',ja.Q1440P='1440',ja.Q2160P='2160',ja.Q4320P='4320',ja.UNKNOWN='unknown',exports.ScreenDestination=void 0,(Ia=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',Ia.APPLE_TV='appletv',Ia.PIP='pip',Ia.HEADPHONES='externalHeadphones',Ia.SCREEN='',exports.ContentType=void 0,(La=exports.ContentType||(exports.ContentType={})).MP4='mp4',La.DASH='dash',La.DASH_SEP='dash_sep',La.ONDEMAND_DASH='ondemand_dash',La.HLS='hls',La.ONDEMAND_HLS='ondemand_hls',La.WEBM='webm',La.RTMP='rtmp',La.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(Qa||(Qa={})),exports.ConnectionType=void 0,(Da=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',Da.HTTP2='http2',Da.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}($a||($a={}));const Fa={[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]:''},Ba={start:1e3,factor:1.5,max:3e5,random:.1};var qa;!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'}(qa||(qa={}));class Ua{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t.ValueSubject(!1),this.params=e;const r=Ma.get('uuid');r?this.uuid=String(r):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let r,o,n=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(n<=2&&(n=33554432+16777216*Math.random()|0),r=15&n,n>>=4,e[o]=t[19===o?3&r|8:r]);return e.join('')}(),Ma.set('uuid',this.uuid))}authorize(t){return n(this,void 0,void 0,(function*(){return this.authToken=null!=t?t:yield this.refreshAuthToken(),this._authorizeWithBackoff()}))}logBeacon(t){const e=this.createLogParams(t),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon('log.externalLog',e,r)||this.logRequest(t)}logRequest(t){var e;return n(this,void 0,void 0,(function*(){const r='log.externalLog',o=this.createLogParams(t),i=null!==(e=this.sessionKey)&&void 0!==e?e:yield this._authorizeWithBackoff();if(!i)return;const s=(t,e=this.params.requestRetryCount)=>n(this,void 0,void 0,(function*(){try{return yield this.params.apiTransport.sendRequest(r,o,i)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${r} error`,thrown:o});const n=null==o?void 0:o.error_code;switch(n){case qa.PARAM_SESSION_EXPIRED:case qa.PARAM_SESSION_KEY:case qa.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?s(t,e-1):void 0;case qa.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),e>0?s(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${n}`,message:`${r} error`,data:o})}}}));return s(t)}))}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=Ra(this.params.refreshAuthToken(),(()=>{this.refreshAuthTokenPromise=void 0}))),this.refreshAuthTokenPromise}))}createLogParams(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:t.map((t=>Object.assign(Object.assign({},t),{time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t.getExponentialDelay(this.consequentAuthErrors,Ba);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{Ra(this._authorize().then(t).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))),(()=>this.backoffTimeoutId=0))}),e))}))}_authorize(){return n(this,void 0,void 0,(function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=Ra(this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((t=>n(this,void 0,void 0,(function*(){this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case qa.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})))),(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}))}}function Ha(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const Va=Ha({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),za=Va?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n=!1}=t;if(!Ha({fetch:e,Request:r,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:n}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty('signal')||n)&&(i=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const n=new r(t,e);return o&&Object.defineProperty(n,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),n},i.prototype=r.prototype);const s=e;return{fetch:(t,e)=>{const r=i&&i.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(r){let o;try{o=new DOMException('Aborted','AbortError')}catch(t){o=new Error('Aborted'),o.name='AbortError'}if(r.aborted)return Promise.reject(o);const n=new Promise(((t,e)=>{r.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([n,s(t,e)])}return s(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ka=Va?za.fetch:window.fetch;Va?za.Request:window.Request;class Wa{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var t;return n(this,void 0,void 0,(function*(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),r=yield Ka(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=yield r.json(),n=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!n)throw new Error('Wrong DNS response');return n}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),Fa[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}))}sendBeacon(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),n=new window.Blob([o.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,n)}catch(r){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:r,data:{method:t,params:e}})}return!1}sendRequest(e,r,o){return n(this,void 0,void 0,(function*(){const n=t.now(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:e,params:r,sessionKey:o,time:t.now()-n}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Ka(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:e,queryParams:r,sessionKey:o})}).then((e=>{var r;const o=0===Number(e.headers.get('content-length')),s=new Date(null!==(r=e.headers.get('date'))&&void 0!==r?r:'').getTime(),a=t.now()-n;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,a),!o)return e.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),i)}),i)}))}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,r])=>e.append(t,'string'==typeof r?r:JSON.stringify(r)))),e}}class Ga{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=o.default((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class Ya{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const r=t-Date.now()-e/2;if(Math.abs(r)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(r);else{const t=.2;this.offset=Math.round(t*r+(1-t)*this.offset)}}}const Ja=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0'),Za=t=>t&&{[e.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[e.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[e.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],Xa=r=>{if(void 0!==r)switch(r){case e.VideoFormat.MPEG:return exports.ContentType.MP4;case e.VideoFormat.DASH:case e.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case e.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case e.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case e.VideoFormat.DASH_WEBM:case e.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case e.VideoFormat.HLS:case e.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case e.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case e.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return t.assertNever(r)}};exports.OneStat=class{constructor(e,r){var o;this.subscription=new t.Subscription,this.timeSynchronisation=new Ya,this.vsid=Ja(),this.fieldBlacklist=[],this.statContext=e,this.config=Object.assign(Object.assign({},null!==(o=r.config)&&void 0!==o?o:{}),{requestRetryCount:1});const n=new t.Subject;this.experimental={error$:n};const i=new Wa({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:Fa[r.apiEnv],apiEnv:r.apiEnv,error$:n,timeSynchronisation:this.timeSynchronisation});this.api=new Ua({apiTransport:i,refreshAuthToken:r.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:n}),this.logger=new Ga({api:this.api,error$:n}),this.subscription.add(t.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext=Object.assign(Object.assign({},this.statContext),t)}attachTo(r){let o;return(new t.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:t})=>{this.logError({errorType:t})}))).add(r.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(r.events.inited$.subscribe((()=>{this.logInited()}))).add(r.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(r.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(r.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(r.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(r.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(r.info.isStalled$.subscribe((e=>{e?o=t.now():(t.isNonNullable(o)&&this.logEmptyBuffer({duration:t.now()-o}),o=void 0)}))).add(r.events.ended$.subscribe((()=>{const e=r.info.throughputEstimation$.getValue();t.isNonNullable(e)&&this.logDownloadSpeed({speed:e/8})}))).add(r.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(r.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:Za(t)})}))).add(r.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(r.info.currentQuality$.subscribe((t=>{var r;this.updateContext({quality:(r=t,r&&{[e.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[e.VideoQuality.Q_144P]:exports.Quality.Q144P,[e.VideoQuality.Q_240P]:exports.Quality.Q240P,[e.VideoQuality.Q_360P]:exports.Quality.Q360P,[e.VideoQuality.Q_480P]:exports.Quality.Q480P,[e.VideoQuality.Q_720P]:exports.Quality.Q720P,[e.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[e.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[e.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[e.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[r])})}))).add(r.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:Xa(t)})}))).add(r.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===e.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=Ja()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),r=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${r}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){const r=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:!0===this.statContext.connectionReused?$a.YES:!1===this.statContext.connectionReused?$a.NO:void 0,stat_type:!0===this.statContext.autoplay?Qa.AUTO:!1===this.statContext.autoplay?Qa.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(o.param=e);for(const t of this.fieldBlacklist)delete o[t];return{operation:t,timestamp:r,custom:o}}};
|
package/es2015.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as t,getExponentialDelay as e,now as r,assertNever as n,Subscription as o,Subject as i,fromEvent as s,merge as a,isNonNullable as u}from'@vkontakte/videoplayer-shared/es2015.esm.js';import{VideoQuality as c,HttpConnectionType as h,VideoFormat as l,ChromecastState as f}from'@vkontakte/videoplayer-core/es2015.esm.js';import d from'lodash/debounce.js';function p(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}var v='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},m=function(t){return t&&t.Math==Math&&t},y=m('object'==typeof globalThis&&globalThis)||m('object'==typeof window&&window)||m('object'==typeof self&&self)||m('object'==typeof v&&v)||function(){return this}()||Function('return this')(),g=function(t){try{return!!t()}catch(t){return!0}},b=!g((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),w=b,S=Function.prototype,T=S.apply,P=S.call,_='object'==typeof Reflect&&Reflect.apply||(w?P.bind(T):function(){return P.apply(T,arguments)}),E=b,A=Function.prototype,O=A.bind,R=A.call,C=E&&O.bind(R,R),k=E?function(t){return t&&C(t)}:function(t){return t&&function(){return R.apply(t,arguments)}},N=function(t){return'function'==typeof t},j={},x=!g((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),I=b,L=Function.prototype.call,$=I?L.bind(L):function(){return L.apply(L,arguments)},D={},M={}.propertyIsEnumerable,B=Object.getOwnPropertyDescriptor,U=B&&!M.call({1:2},1);D.f=U?function(t){var e=B(this,t);return!!e&&e.enumerable}:M;var q,F,H=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},z=k,Q=z({}.toString),K=z(''.slice),W=function(t){return K(Q(t),8,-1)},V=g,G=W,Y=Object,J=k(''.split),Z=V((function(){return!Y('z').propertyIsEnumerable(0)}))?function(t){return'String'==G(t)?J(t,''):Y(t)}:Y,X=TypeError,tt=function(t){if(null==t)throw X('Can\'t call method on '+t);return t},et=Z,rt=tt,nt=N,ot=function(t){return'object'==typeof t?null!==t:nt(t)},it={},st=it,at=y,ut=N,ct=function(t){return ut(t)?t:void 0},ht=function(t,e){return arguments.length<2?ct(st[t])||ct(at[t]):st[t]&&st[t][e]||at[t]&&at[t][e]},lt=k({}.isPrototypeOf),ft=ht('navigator','userAgent')||'',dt=y,pt=ft,vt=dt.process,mt=dt.Deno,yt=vt&&vt.versions||mt&&mt.version,gt=yt&&yt.v8;gt&&(F=(q=gt.split('.'))[0]>0&&q[0]<4?1:+(q[0]+q[1])),!F&&pt&&(!(q=pt.match(/Edge\/(\d+)/))||q[1]>=74)&&(q=pt.match(/Chrome\/(\d+)/))&&(F=+q[1]);var bt=F,wt=bt,St=g,Tt=!!Object.getOwnPropertySymbols&&!St((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&wt&&wt<41})),Pt=Tt&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,_t=ht,Et=N,At=lt,Ot=Object,Rt=Pt?function(t){return'symbol'==typeof t}:function(t){var e=_t('Symbol');return Et(e)&&At(e.prototype,Ot(t))},Ct=String,kt=function(t){try{return Ct(t)}catch(t){return'Object'}},Nt=N,jt=kt,xt=TypeError,It=function(t){if(Nt(t))return t;throw xt(jt(t)+' is not a function')},Lt=It,$t=function(t,e){var r=t[e];return null==r?void 0:Lt(r)},Dt=$,Mt=N,Bt=ot,Ut=TypeError,qt={exports:{}},Ft=y,Ht=Object.defineProperty,zt=function(t,e){try{Ht(Ft,t,{value:e,configurable:!0,writable:!0})}catch(r){Ft[t]=e}return e},Qt=y['__core-js_shared__']||zt('__core-js_shared__',{}),Kt=Qt;(qt.exports=function(t,e){return Kt[t]||(Kt[t]=void 0!==e?e:{})})('versions',[]).push({version:'3.24.1',mode:'pure',copyright:'© 2014-2022 Denis Pushkarev (zloirock.ru)',license:'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',source:'https://github.com/zloirock/core-js'});var Wt=tt,Vt=Object,Gt=function(t){return Vt(Wt(t))},Yt=k({}.hasOwnProperty),Jt=Object.hasOwn||function(t,e){return Yt(Gt(t),e)},Zt=k,Xt=0,te=Math.random(),ee=Zt(1..toString),re=function(t){return'Symbol('+(void 0===t?'':t)+')_'+ee(++Xt+te,36)},ne=y,oe=qt.exports,ie=Jt,se=re,ae=Tt,ue=Pt,ce=oe('wks'),he=ne.Symbol,le=he&&he.for,fe=ue?he:he&&he.withoutSetter||se,de=function(t){if(!ie(ce,t)||!ae&&'string'!=typeof ce[t]){var e='Symbol.'+t;ae&&ie(he,t)?ce[t]=he[t]:ce[t]=ue&&le?le(e):fe(e)}return ce[t]},pe=$,ve=ot,me=Rt,ye=$t,ge=function(t,e){var r,n;if('string'===e&&Mt(r=t.toString)&&!Bt(n=Dt(r,t)))return n;if(Mt(r=t.valueOf)&&!Bt(n=Dt(r,t)))return n;if('string'!==e&&Mt(r=t.toString)&&!Bt(n=Dt(r,t)))return n;throw Ut('Can\'t convert object to primitive value')},be=TypeError,we=de('toPrimitive'),Se=function(t,e){if(!ve(t)||me(t))return t;var r,n=ye(t,we);if(n){if(void 0===e&&(e='default'),r=pe(n,t,e),!ve(r)||me(r))return r;throw be('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),ge(t,e)},Te=Rt,Pe=function(t){var e=Se(t,'string');return Te(e)?e:e+''},_e=ot,Ee=y.document,Ae=_e(Ee)&&_e(Ee.createElement),Oe=function(t){return Ae?Ee.createElement(t):{}},Re=Oe,Ce=!x&&!g((function(){return 7!=Object.defineProperty(Re('div'),'a',{get:function(){return 7}}).a})),ke=x,Ne=$,je=D,xe=H,Ie=function(t){return et(rt(t))},Le=Pe,$e=Jt,De=Ce,Me=Object.getOwnPropertyDescriptor;j.f=ke?Me:function(t,e){if(t=Ie(t),e=Le(e),De)try{return Me(t,e)}catch(t){}if($e(t,e))return xe(!Ne(je.f,t,e),t[e])};var Be=g,Ue=N,qe=/#|\.prototype\./,Fe=function(t,e){var r=ze[He(t)];return r==Ke||r!=Qe&&(Ue(e)?Be(e):!!e)},He=Fe.normalize=function(t){return String(t).replace(qe,'.').toLowerCase()},ze=Fe.data={},Qe=Fe.NATIVE='N',Ke=Fe.POLYFILL='P',We=Fe,Ve=It,Ge=b,Ye=k(k.bind),Je=function(t,e){return Ve(t),void 0===e?t:Ge?Ye(t,e):function(){return t.apply(e,arguments)}},Ze={},Xe=x&&g((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),tr=ot,er=String,rr=TypeError,nr=function(t){if(tr(t))return t;throw rr(er(t)+' is not an object')},or=x,ir=Ce,sr=Xe,ar=nr,ur=Pe,cr=TypeError,hr=Object.defineProperty,lr=Object.getOwnPropertyDescriptor;Ze.f=or?sr?function(t,e,r){if(ar(t),e=ur(e),ar(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var n=lr(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:'configurable'in r?r.configurable:n.configurable,enumerable:'enumerable'in r?r.enumerable:n.enumerable,writable:!1})}return hr(t,e,r)}:hr:function(t,e,r){if(ar(t),e=ur(e),ar(r),ir)try{return hr(t,e,r)}catch(t){}if('get'in r||'set'in r)throw cr('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var fr=Ze,dr=H,pr=x?function(t,e,r){return fr.f(t,e,dr(1,r))}:function(t,e,r){return t[e]=r,t},vr=y,mr=_,yr=k,gr=N,br=j.f,wr=We,Sr=it,Tr=Je,Pr=pr,_r=Jt,Er=function(t){var e=function(r,n,o){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,n)}return new t(r,n,o)}return mr(t,this,arguments)};return e.prototype=t.prototype,e},Ar=function(t,e){var r,n,o,i,s,a,u,c,h=t.target,l=t.global,f=t.stat,d=t.proto,p=l?vr:f?vr[h]:(vr[h]||{}).prototype,v=l?Sr:Sr[h]||Pr(Sr,h,{})[h],m=v.prototype;for(o in e)r=!wr(l?o:h+(f?'.':'#')+o,t.forced)&&p&&_r(p,o),s=v[o],r&&(a=t.dontCallGetSet?(c=br(p,o))&&c.value:p[o]),i=r&&a?a:e[o],r&&typeof s==typeof i||(u=t.bind&&r?Tr(i,vr):t.wrap&&r?Er(i):d&&gr(i)?yr(i):i,(t.sham||i&&i.sham||s&&s.sham)&&Pr(u,'sham',!0),Pr(v,o,u),d&&(_r(Sr,n=h+'Prototype')||Pr(Sr,n,{}),Pr(Sr[n],o,i),t.real&&m&&!m[o]&&Pr(m,o,i)))},Or='process'==W(y.process),Rr=pr,Cr=(TypeError,k);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=Cr(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var kr={};kr[de('toStringTag')]='z';var Nr='[object z]'===String(kr),jr=Nr,xr=N,Ir=W,Lr=de('toStringTag'),$r=Object,Dr='Arguments'==Ir(function(){return arguments}()),Mr=jr?Ir:function(t){var e,r,n;return void 0===t?'Undefined':null===t?'Null':'string'==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=$r(t),Lr))?r:Dr?Ir(e):'Object'==(n=Ir(e))&&xr(e.callee)?'Arguments':n},Br=Mr,Ur=Nr?{}.toString:function(){return'[object '+Br(this)+']'},qr=Nr,Fr=Ze.f,Hr=pr,zr=Jt,Qr=Ur,Kr=de('toStringTag'),Wr=ht,Vr=Ze,Gr=x,Yr=de('species'),Jr=lt,Zr=TypeError,Xr=N,tn=Qt,en=k(Function.toString);Xr(tn.inspectSource)||(tn.inspectSource=function(t){return en(t)});var rn=tn.inspectSource,nn=k,on=g,sn=N,an=Mr,un=rn,cn=function(){},hn=[],ln=ht('Reflect','construct'),fn=/^\s*(?:class|function)\b/,dn=nn(fn.exec),pn=!fn.exec(cn),vn=function(t){if(!sn(t))return!1;try{return ln(cn,hn,t),!0}catch(t){return!1}},mn=function(t){if(!sn(t))return!1;switch(an(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return pn||!!dn(fn,un(t))}catch(t){return!0}};mn.sham=!0;var yn,gn,bn,wn,Sn=!ln||on((function(){var t;return vn(vn.call)||!vn(Object)||!vn((function(){t=!0}))||t}))?mn:vn,Tn=kt,Pn=TypeError,_n=nr,En=function(t){if(Sn(t))return t;throw Pn(Tn(t)+' is not a constructor')},An=de('species'),On=function(t,e){var r,n=_n(t).constructor;return void 0===n||null==(r=_n(n)[An])?e:En(r)},Rn=ht('document','documentElement'),Cn=k([].slice),kn=TypeError,Nn=/(?:ipad|iphone|ipod).*applewebkit/i.test(ft),jn=y,xn=_,In=Je,Ln=N,$n=Jt,Dn=g,Mn=Rn,Bn=Cn,Un=Oe,qn=function(t,e){if(t<e)throw kn('Not enough arguments');return t},Fn=Nn,Hn=Or,zn=jn.setImmediate,Qn=jn.clearImmediate,Kn=jn.process,Wn=jn.Dispatch,Vn=jn.Function,Gn=jn.MessageChannel,Yn=jn.String,Jn=0,Zn={};try{yn=jn.location}catch(t){}var Xn=function(t){if($n(Zn,t)){var e=Zn[t];delete Zn[t],e()}},to=function(t){return function(){Xn(t)}},eo=function(t){Xn(t.data)},ro=function(t){jn.postMessage(Yn(t),yn.protocol+'//'+yn.host)};zn&&Qn||(zn=function(t){qn(arguments.length,1);var e=Ln(t)?t:Vn(t),r=Bn(arguments,1);return Zn[++Jn]=function(){xn(e,void 0,r)},gn(Jn),Jn},Qn=function(t){delete Zn[t]},Hn?gn=function(t){Kn.nextTick(to(t))}:Wn&&Wn.now?gn=function(t){Wn.now(to(t))}:Gn&&!Fn?(wn=(bn=new Gn).port2,bn.port1.onmessage=eo,gn=In(wn.postMessage,wn)):jn.addEventListener&&Ln(jn.postMessage)&&!jn.importScripts&&yn&&'file:'!==yn.protocol&&!Dn(ro)?(gn=ro,jn.addEventListener('message',eo,!1)):gn='onreadystatechange'in Un('script')?function(t){Mn.appendChild(Un('script')).onreadystatechange=function(){Mn.removeChild(this),Xn(t)}}:function(t){setTimeout(to(t),0)});var no,oo,io,so,ao,uo,co,ho,lo={set:zn,clear:Qn},fo=y,po=/ipad|iphone|ipod/i.test(ft)&&void 0!==fo.Pebble,vo=/web0s(?!.*chrome)/i.test(ft),mo=y,yo=Je,go=j.f,bo=lo.set,wo=Nn,So=po,To=vo,Po=Or,_o=mo.MutationObserver||mo.WebKitMutationObserver,Eo=mo.document,Ao=mo.process,Oo=mo.Promise,Ro=go(mo,'queueMicrotask'),Co=Ro&&Ro.value;Co||(no=function(){var t,e;for(Po&&(t=Ao.domain)&&t.exit();oo;){e=oo.fn,oo=oo.next;try{e()}catch(t){throw oo?so():io=void 0,t}}io=void 0,t&&t.enter()},wo||Po||To||!_o||!Eo?!So&&Oo&&Oo.resolve?((co=Oo.resolve(void 0)).constructor=Oo,ho=yo(co.then,co),so=function(){ho(no)}):Po?so=function(){Ao.nextTick(no)}:(bo=yo(bo,mo),so=function(){bo(no)}):(ao=!0,uo=Eo.createTextNode(''),new _o(no).observe(uo,{characterData:!0}),so=function(){uo.data=ao=!ao}));var ko=Co||function(t){var e={fn:t,next:void 0};io&&(io.next=e),oo||(oo=e,so()),io=e},No=y,jo=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},xo=function(){this.head=null,this.tail=null};xo.prototype={add:function(t){var e={item:t,next:null};this.head?this.tail.next=e:this.head=e,this.tail=e},get:function(){var t=this.head;if(t)return this.head=t.next,this.tail===t&&(this.tail=null),t.item}};var Io,Lo,$o,Do=xo,Mo=N,Bo=rn,Uo=y.WeakMap,qo=Mo(Uo)&&/native code/.test(Bo(Uo)),Fo=qt.exports,Ho=re,zo=Fo('keys'),Qo=qo,Ko=y,Wo=k,Vo=ot,Go=pr,Yo=Jt,Jo=Qt,Zo=function(t){return zo[t]||(zo[t]=Ho(t))},Xo=Ko.TypeError,ti=Ko.WeakMap;if(Qo||Jo.state){var ei=Jo.state||(Jo.state=new ti),ri=Wo(ei.get),ni=Wo(ei.has),oi=Wo(ei.set);Io=function(t,e){if(ni(ei,t))throw new Xo('Object already initialized');return e.facade=t,oi(ei,t,e),e},Lo=function(t){return ri(ei,t)||{}},$o=function(t){return ni(ei,t)}}else{var ii=Zo('state');Io=function(t,e){if(Yo(t,ii))throw new Xo('Object already initialized');return e.facade=t,Go(t,ii,e),e},Lo=function(t){return Yo(t,ii)?t[ii]:{}},$o=function(t){return Yo(t,ii)}}var si={set:Io,get:Lo,has:$o,enforce:function(t){return $o(t)?Lo(t):Io(t,{})},getterFor:function(t){return function(e){var r;if(!Vo(e)||(r=Lo(e)).type!==t)throw Xo('Incompatible receiver, '+t+' required');return r}}},ai=y.Promise,ui='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,ci=!ui&&!Or&&'object'==typeof window&&'object'==typeof document,hi=y,li=ai,fi=N,di=We,pi=rn,vi=de,mi=ci,yi=ui,gi=bt,bi=li&&li.prototype,wi=vi('species'),Si=!1,Ti=fi(hi.PromiseRejectionEvent),Pi={CONSTRUCTOR:di('Promise',(function(){var t=pi(li),e=t!==String(li);if(!e&&66===gi)return!0;if(!bi.catch||!bi.finally)return!0;if(!gi||gi<51||!/native code/.test(t)){var r=new li((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};if((r.constructor={})[wi]=n,!(Si=r.then((function(){}))instanceof n))return!0}return!e&&(mi||yi)&&!Ti})),REJECTION_EVENT:Ti,SUBCLASSING:Si},_i={},Ei=It,Ai=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError('Bad Promise constructor');e=t,r=n})),this.resolve=Ei(e),this.reject=Ei(r)};_i.f=function(t){return new Ai(t)};var Oi,Ri,Ci=Ar,ki=Or,Ni=y,ji=$,xi=function(t,e,r,n){return n&&n.enumerable?t[e]=r:Rr(t,e,r),t},Ii=function(t,e,r,n){if(t){var o=r?t:t.prototype;zr(o,Kr)||Fr(o,Kr,{configurable:!0,value:e}),n&&!qr&&Hr(o,'toString',Qr)}},Li=function(t){var e=Wr(t),r=Vr.f;Gr&&e&&!e[Yr]&&r(e,Yr,{configurable:!0,get:function(){return this}})},$i=It,Di=N,Mi=ot,Bi=function(t,e){if(Jr(e,t))return t;throw Zr('Incorrect invocation')},Ui=On,qi=lo.set,Fi=ko,Hi=function(t,e){var r=No.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},zi=jo,Qi=Do,Ki=si,Wi=ai,Vi=_i,Gi=Pi.CONSTRUCTOR,Yi=Pi.REJECTION_EVENT,Ji=Ki.getterFor('Promise'),Zi=Ki.set,Xi=Wi&&Wi.prototype,ts=Wi,es=Xi,rs=Ni.TypeError,ns=Ni.document,os=Ni.process,is=Vi.f,ss=is,as=!!(ns&&ns.createEvent&&Ni.dispatchEvent),us=function(t){var e;return!(!Mi(t)||!Di(e=t.then))&&e},cs=function(t,e){var r,n,o,i=e.value,s=1==e.state,a=s?t.ok:t.fail,u=t.resolve,c=t.reject,h=t.domain;try{a?(s||(2===e.rejection&&ps(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),o=!0)),r===t.promise?c(rs('Promise-chain cycle')):(n=us(r))?ji(n,r,u,c):u(r)):c(i)}catch(t){h&&!o&&h.exit(),c(t)}},hs=function(t,e){t.notified||(t.notified=!0,Fi((function(){for(var r,n=t.reactions;r=n.get();)cs(r,t);t.notified=!1,e&&!t.rejection&&fs(t)})))},ls=function(t,e,r){var n,o;as?((n=ns.createEvent('Event')).promise=e,n.reason=r,n.initEvent(t,!1,!0),Ni.dispatchEvent(n)):n={promise:e,reason:r},!Yi&&(o=Ni['on'+t])?o(n):'unhandledrejection'===t&&Hi('Unhandled promise rejection',r)},fs=function(t){ji(qi,Ni,(function(){var e,r=t.facade,n=t.value;if(ds(t)&&(e=zi((function(){ki?os.emit('unhandledRejection',n,r):ls('unhandledrejection',r,n)})),t.rejection=ki||ds(t)?2:1,e.error))throw e.value}))},ds=function(t){return 1!==t.rejection&&!t.parent},ps=function(t){ji(qi,Ni,(function(){var e=t.facade;ki?os.emit('rejectionHandled',e):ls('rejectionhandled',e,t.value)}))},vs=function(t,e,r){return function(n){t(e,n,r)}},ms=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,hs(t,!0))},ys=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw rs('Promise can\'t be resolved itself');var n=us(e);n?Fi((function(){var r={done:!1};try{ji(n,e,vs(ys,r,t),vs(ms,r,t))}catch(e){ms(r,e,t)}})):(t.value=e,t.state=1,hs(t,!1))}catch(e){ms({done:!1},e,t)}}};Gi&&(es=(ts=function(t){Bi(this,es),$i(t),ji(Oi,this);var e=Ji(this);try{t(vs(ys,e),vs(ms,e))}catch(t){ms(e,t)}}).prototype,(Oi=function(t){Zi(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new Qi,rejection:!1,state:0,value:void 0})}).prototype=xi(es,'then',(function(t,e){var r=Ji(this),n=is(Ui(this,ts));return r.parent=!0,n.ok=!Di(t)||t,n.fail=Di(e)&&e,n.domain=ki?os.domain:void 0,0==r.state?r.reactions.add(n):Fi((function(){cs(n,r)})),n.promise})),Ri=function(){var t=new Oi,e=Ji(t);this.promise=t,this.resolve=vs(ys,e),this.reject=vs(ms,e)},Vi.f=is=function(t){return t===ts||undefined===t?new Ri(t):ss(t)}),Ci({global:!0,constructor:!0,wrap:!0,forced:Gi},{Promise:ts}),Ii(ts,'Promise',!1,!0),Li('Promise');var gs={},bs=gs,ws=de('iterator'),Ss=Array.prototype,Ts=Math.ceil,Ps=Math.floor,_s=Math.trunc||function(t){var e=+t;return(e>0?Ps:Ts)(e)},Es=function(t){var e=+t;return e!=e||0===e?0:_s(e)},As=Math.min,Os=function(t){return t>0?As(Es(t),9007199254740991):0},Rs=Mr,Cs=$t,ks=gs,Ns=de('iterator'),js=function(t){if(null!=t)return Cs(t,Ns)||Cs(t,'@@iterator')||ks[Rs(t)]},xs=$,Is=It,Ls=nr,$s=kt,Ds=js,Ms=TypeError,Bs=$,Us=nr,qs=$t,Fs=Je,Hs=$,zs=nr,Qs=kt,Ks=function(t){return void 0!==t&&(bs.Array===t||Ss[ws]===t)},Ws=function(t){return Os(t.length)},Vs=lt,Gs=function(t,e){var r=arguments.length<2?Ds(t):e;if(Is(r))return Ls(xs(r,t));throw Ms($s(t)+' is not iterable')},Ys=js,Js=function(t,e,r){var n,o;Us(t);try{if(!(n=qs(t,'return'))){if('throw'===e)throw r;return r}n=Bs(n,t)}catch(t){o=!0,n=t}if('throw'===e)throw r;if(o)throw n;return Us(n),r},Zs=TypeError,Xs=function(t,e){this.stopped=t,this.result=e},ta=Xs.prototype,ea=function(t,e,r){var n,o,i,s,a,u,c,h=r&&r.that,l=!(!r||!r.AS_ENTRIES),f=!(!r||!r.IS_RECORD),d=!(!r||!r.IS_ITERATOR),p=!(!r||!r.INTERRUPTED),v=Fs(e,h),m=function(t){return n&&Js(n,'normal',t),new Xs(!0,t)},y=function(t){return l?(zs(t),p?v(t[0],t[1],m):v(t[0],t[1])):p?v(t,m):v(t)};if(f)n=t.iterator;else if(d)n=t;else{if(!(o=Ys(t)))throw Zs(Qs(t)+' is not iterable');if(Ks(o)){for(i=0,s=Ws(t);s>i;i++)if((a=y(t[i]))&&Vs(ta,a))return a;return new Xs(!1)}n=Gs(t,o)}for(u=f?t.next:n.next;!(c=Hs(u,n)).done;){try{a=y(c.value)}catch(t){Js(n,'throw',t)}if('object'==typeof a&&a&&Vs(ta,a))return a}return new Xs(!1)},ra=de('iterator'),na=!1;try{var oa=0,ia={next:function(){return{done:!!oa++}},return:function(){na=!0}};ia[ra]=function(){return this},Array.from(ia,(function(){throw 2}))}catch(t){}var sa=ai,aa=Pi.CONSTRUCTOR||!function(t,e){if(!e&&!na)return!1;var r=!1;try{var n={};n[ra]=function(){return{next:function(){return{done:r=!0}}}},t(n)}catch(t){}return r}((function(t){sa.all(t).then(void 0,(function(){}))})),ua=$,ca=It,ha=_i,la=jo,fa=ea;Ar({target:'Promise',stat:!0,forced:aa},{all:function(t){var e=this,r=ha.f(e),n=r.resolve,o=r.reject,i=la((function(){var r=ca(e.resolve),i=[],s=0,a=1;fa(t,(function(t){var u=s++,c=!1;a++,ua(r,e,t).then((function(t){c||(c=!0,i[u]=t,--a||n(i))}),o)})),--a||n(i)}));return i.error&&o(i.value),r.promise}});var da=Ar,pa=Pi.CONSTRUCTOR;ai&&ai.prototype,da({target:'Promise',proto:!0,forced:pa,real:!0},{catch:function(t){return this.then(void 0,t)}});var va=$,ma=It,ya=_i,ga=jo,ba=ea;Ar({target:'Promise',stat:!0,forced:aa},{race:function(t){var e=this,r=ya.f(e),n=r.reject,o=ga((function(){var o=ma(e.resolve);ba(t,(function(t){va(o,e,t).then(r.resolve,n)}))}));return o.error&&n(o.value),r.promise}});var wa=$,Sa=_i;Ar({target:'Promise',stat:!0,forced:Pi.CONSTRUCTOR},{reject:function(t){var e=Sa.f(this);return wa(e.reject,void 0,t),e.promise}});var Ta=nr,Pa=ot,_a=_i,Ea=function(t,e){if(Ta(t),Pa(e)&&e.constructor===t)return e;var r=_a.f(t);return(0,r.resolve)(e),r.promise},Aa=Ar,Oa=ai,Ra=Pi.CONSTRUCTOR,Ca=Ea,ka=ht('Promise'),Na=!Ra;Aa({target:'Promise',stat:!0,forced:true},{resolve:function(t){return Ca(Na&&this===ka?Oa:this,t)}});var ja=Ar,xa=ai,Ia=g,La=ht,$a=N,Da=On,Ma=Ea,Ba=xa&&xa.prototype;ja({target:'Promise',proto:!0,real:!0,forced:!!xa&&Ia((function(){Ba.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=Da(this,La('Promise')),r=$a(t);return this.then(r?function(r){return Ma(e,t()).then((function(){return r}))}:t,r?function(r){return Ma(e,t()).then((function(){throw r}))}:t)}});var Ua=ht('Promise','finally');const qa=(()=>{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}})();var Fa,Ha,za,Qa,Ka,Wa,Va,Ga={get:t=>function(t){const e=qa?qa.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{qa&&qa.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){qa&&qa.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(Fa||(Fa={})),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'}(Ha||(Ha={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(za||(za={})),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'}(Qa||(Qa={})),function(t){t.AUTO='auto',t.MANUAL=''}(Ka||(Ka={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(Wa||(Wa={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(Va||(Va={}));const Ya={[Fa.PROD]:'https://api.ok.ru',[Fa.VK_ALIAS]:'https://api.mycdn.me',[Fa.VIDEOTEST]:'https://videotestapi.ok.ru/api',[Fa.TEST]:'https://apitest.ok.ru',[Fa.AUTO]:''},Ja={start:1e3,factor:1.5,max:3e5,random:.1};var Za;!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'}(Za||(Za={}));class Xa{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const r=Ga.get('uuid');r?this.uuid=String(r):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let r,n,o=0;for(n=0;n<36;n++)8===n||13===n||18===n||23===n?e[n]='-':14===n?e[n]='4':(o<=2&&(o=33554432+16777216*Math.random()|0),r=15&o,o>>=4,e[n]=t[19===n?3&r|8:r]);return e.join('')}(),Ga.set('uuid',this.uuid))}authorize(t){return p(this,void 0,void 0,(function*(){return this.authToken=null!=t?t:yield this.refreshAuthToken(),this._authorizeWithBackoff()}))}logBeacon(t){const e=this.createLogParams(t),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon('log.externalLog',e,r)||this.logRequest(t)}logRequest(t){var e;return p(this,void 0,void 0,(function*(){const r='log.externalLog',n=this.createLogParams(t),o=null!==(e=this.sessionKey)&&void 0!==e?e:yield this._authorizeWithBackoff();if(!o)return;const i=(t,e=this.params.requestRetryCount)=>p(this,void 0,void 0,(function*(){try{return yield this.params.apiTransport.sendRequest(r,n,o)}catch(n){if(!n||!('error_code'in n))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${r} error`,thrown:n});const o=null==n?void 0:n.error_code;switch(o){case Za.PARAM_SESSION_EXPIRED:case Za.PARAM_SESSION_KEY:case Za.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;case Za.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${r} error`,data:n})}}}));return i(t)}))}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return p(this,void 0,void 0,(function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=Ua(this.params.refreshAuthToken(),(()=>{this.refreshAuthTokenPromise=void 0}))),this.refreshAuthTokenPromise}))}createLogParams(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:t.map((t=>Object.assign(Object.assign({},t),{time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,Ja);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{Ua(this._authorize().then(e).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))),(()=>this.backoffTimeoutId=0))}),t))}))}_authorize(){return p(this,void 0,void 0,(function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=Ua(this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((t=>p(this,void 0,void 0,(function*(){this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case Za.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})))),(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}))}}function tu(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const eu=tu({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ru=eu?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!tu({fetch:e,Request:r,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty('signal')||o)&&(i=function(t,e){let n;e&&e.signal&&(n=e.signal,delete e.signal);const o=new r(t,e);return n&&Object.defineProperty(o,'signal',{writable:!1,enumerable:!1,configurable:!0,value:n}),o},i.prototype=r.prototype);const s=e;return{fetch:(t,e)=>{const r=i&&i.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(r){let n;try{n=new DOMException('Aborted','AbortError')}catch(t){n=new Error('Aborted'),n.name='AbortError'}if(r.aborted)return Promise.reject(n);const o=new Promise(((t,e)=>{r.addEventListener('abort',(()=>e(n)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([o,s(t,e)])}return s(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,nu=eu?ru.fetch:window.fetch;eu?ru.Request:window.Request;class ou{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var t;return p(this,void 0,void 0,(function*(){if(this.apiEnv!==Fa.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),r=yield nu(e,{method:'GET',mode:'cors',cache:'no-cache'}),n=yield r.json(),o=null===(t=null==n?void 0:n.Answer[0])||void 0===t?void 0:t.data;if(!o)throw new Error('Wrong DNS response');return o}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),Ya[Fa.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}))}sendBeacon(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;const n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,o)}catch(r){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:r,data:{method:t,params:e}})}return!1}sendRequest(t,e,n){return p(this,void 0,void 0,(function*(){const o=r(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:t,params:e,sessionKey:n,time:r()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),nu(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:n})}).then((t=>{var e;const n=0===Number(t.headers.get('content-length')),s=new Date(null!==(e=t.headers.get('date'))&&void 0!==e?e:'').getTime(),a=r()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,a),n)return t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),i)}),i)}))}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,r])=>e.append(t,'string'==typeof r?r:JSON.stringify(r)))),e}}class iu{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=d((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class su{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const r=t-Date.now()-e/2;if(Math.abs(r)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(r);else{const t=.2;this.offset=Math.round(t*r+(1-t)*this.offset)}}}const au=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0'),uu=t=>t&&{[h.HTTP1]:Wa.HTTP1,[h.HTTP2]:Wa.HTTP2,[h.QUIC]:Wa.HTTP3}[t],cu=t=>{if(void 0!==t)switch(t){case l.MPEG:return Qa.MP4;case l.DASH:case l.DASH_LIVE:return Qa.DASH;case l.DASH_SEP:return Qa.DASH_SEP;case l.DASH_ONDEMAND:return Qa.ONDEMAND_DASH;case l.DASH_WEBM:case l.DASH_LIVE_WEBM:return Qa.WEBM;case l.HLS:case l.HLS_LIVE:return Qa.HLS;case l.HLS_ONDEMAND:return Qa.ONDEMAND_HLS;case l.WEB_RTC_LIVE:return Qa.RTMP;default:return n(t)}};class hu{constructor(t,e){var r;this.subscription=new o,this.timeSynchronisation=new su,this.vsid=au(),this.fieldBlacklist=[],this.statContext=t,this.config=Object.assign(Object.assign({},null!==(r=e.config)&&void 0!==r?r:{}),{requestRetryCount:1});const n=new i;this.experimental={error$:n};const a=new ou({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:Ya[e.apiEnv],apiEnv:e.apiEnv,error$:n,timeSynchronisation:this.timeSynchronisation});this.api=new Xa({apiTransport:a,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:n}),this.logger=new iu({api:this.api,error$:n}),this.subscription.add(s(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext=Object.assign(Object.assign({},this.statContext),t)}attachTo(t){let e;return(new o).add(a(t.events.started$,t.events.looped$).subscribe((()=>{this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.looped$.subscribe((()=>{this.resetViewSession()}))).add(t.events.seeked$.subscribe((()=>{this.logSeek()}))).add(t.events.willPause$.subscribe((()=>{this.logPause({position:t.info.position$.getValue()})}))).add(t.events.willResume$.subscribe((()=>{this.logPlay()}))).add(t.events.managedError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.inited$.subscribe((()=>{this.logInited()}))).add(t.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(t.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(t.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(t.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(t.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(t.info.isStalled$.subscribe((t=>{t?e=r():(u(e)&&this.logEmptyBuffer({duration:r()-e}),e=void 0)}))).add(t.events.ended$.subscribe((()=>{const e=t.info.throughputEstimation$.getValue();u(e)&&this.logDownloadSpeed({speed:e/8})}))).add(t.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(t.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:uu(t)})}))).add(t.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(t.info.currentQuality$.subscribe((t=>{var e;this.updateContext({quality:(e=t,e&&{[c.INVARIANT]:Ha.UNKNOWN,[c.Q_144P]:Ha.Q144P,[c.Q_240P]:Ha.Q240P,[c.Q_360P]:Ha.Q360P,[c.Q_480P]:Ha.Q480P,[c.Q_720P]:Ha.Q720P,[c.Q_1080P]:Ha.Q1080P,[c.Q_1440P]:Ha.Q1440P,[c.Q_2160P]:Ha.Q2160P,[c.Q_4320P]:Ha.Q4320P}[e])})}))).add(t.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:cu(t)})}))).add(t.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===f.CONNECTED?za.CHROMECAST:za.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=au()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),r=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${r}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){const r=this.timeSynchronisation.now(),n={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:!0===this.statContext.connectionReused?Va.YES:!1===this.statContext.connectionReused?Va.NO:void 0,stat_type:!0===this.statContext.autoplay?Ka.AUTO:!1===this.statContext.autoplay?Ka.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(n.param=e);for(const t of this.fieldBlacklist)delete n[t];return{operation:t,timestamp:r,custom:n}}}export{Fa as ApiEnv,Wa as ConnectionType,Qa as ContentType,hu as OneStat,Ha as Quality,za as ScreenDestination};
|
|
6
|
+
import{ValueSubject as t,getExponentialDelay as e,now as r,assertNever as n,Subscription as o,Subject as i,fromEvent as s,isNonNullable as a}from'@vkontakte/videoplayer-shared/es2015.esm.js';import{VideoQuality as u,HttpConnectionType as c,VideoFormat as h,ChromecastState as l}from'@vkontakte/videoplayer-core/es2015.esm.js';import f from'lodash/debounce.js';function d(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}var p='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},v=function(t){return t&&t.Math==Math&&t},m=v('object'==typeof globalThis&&globalThis)||v('object'==typeof window&&window)||v('object'==typeof self&&self)||v('object'==typeof p&&p)||function(){return this}()||Function('return this')(),y=function(t){try{return!!t()}catch(t){return!0}},g=!y((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),b=g,w=Function.prototype,S=w.apply,T=w.call,P='object'==typeof Reflect&&Reflect.apply||(b?T.bind(S):function(){return T.apply(S,arguments)}),_=g,E=Function.prototype,A=E.bind,O=E.call,R=_&&A.bind(O,O),C=_?function(t){return t&&R(t)}:function(t){return t&&function(){return O.apply(t,arguments)}},k=function(t){return'function'==typeof t},N={},j=!y((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),x=g,I=Function.prototype.call,L=x?I.bind(I):function(){return I.apply(I,arguments)},$={},D={}.propertyIsEnumerable,M=Object.getOwnPropertyDescriptor,B=M&&!D.call({1:2},1);$.f=B?function(t){var e=M(this,t);return!!e&&e.enumerable}:D;var U,q,F=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},H=C,z=H({}.toString),Q=H(''.slice),K=function(t){return Q(z(t),8,-1)},W=y,V=K,G=Object,Y=C(''.split),J=W((function(){return!G('z').propertyIsEnumerable(0)}))?function(t){return'String'==V(t)?Y(t,''):G(t)}:G,Z=TypeError,X=function(t){if(null==t)throw Z('Can\'t call method on '+t);return t},tt=J,et=X,rt=k,nt=function(t){return'object'==typeof t?null!==t:rt(t)},ot={},it=ot,st=m,at=k,ut=function(t){return at(t)?t:void 0},ct=function(t,e){return arguments.length<2?ut(it[t])||ut(st[t]):it[t]&&it[t][e]||st[t]&&st[t][e]},ht=C({}.isPrototypeOf),lt=ct('navigator','userAgent')||'',ft=m,dt=lt,pt=ft.process,vt=ft.Deno,mt=pt&&pt.versions||vt&&vt.version,yt=mt&&mt.v8;yt&&(q=(U=yt.split('.'))[0]>0&&U[0]<4?1:+(U[0]+U[1])),!q&&dt&&(!(U=dt.match(/Edge\/(\d+)/))||U[1]>=74)&&(U=dt.match(/Chrome\/(\d+)/))&&(q=+U[1]);var gt=q,bt=gt,wt=y,St=!!Object.getOwnPropertySymbols&&!wt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&bt&&bt<41})),Tt=St&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,Pt=ct,_t=k,Et=ht,At=Object,Ot=Tt?function(t){return'symbol'==typeof t}:function(t){var e=Pt('Symbol');return _t(e)&&Et(e.prototype,At(t))},Rt=String,Ct=function(t){try{return Rt(t)}catch(t){return'Object'}},kt=k,Nt=Ct,jt=TypeError,xt=function(t){if(kt(t))return t;throw jt(Nt(t)+' is not a function')},It=xt,Lt=function(t,e){var r=t[e];return null==r?void 0:It(r)},$t=L,Dt=k,Mt=nt,Bt=TypeError,Ut={exports:{}},qt=m,Ft=Object.defineProperty,Ht=function(t,e){try{Ft(qt,t,{value:e,configurable:!0,writable:!0})}catch(r){qt[t]=e}return e},zt=m['__core-js_shared__']||Ht('__core-js_shared__',{}),Qt=zt;(Ut.exports=function(t,e){return Qt[t]||(Qt[t]=void 0!==e?e:{})})('versions',[]).push({version:'3.24.1',mode:'pure',copyright:'© 2014-2022 Denis Pushkarev (zloirock.ru)',license:'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',source:'https://github.com/zloirock/core-js'});var Kt=X,Wt=Object,Vt=function(t){return Wt(Kt(t))},Gt=C({}.hasOwnProperty),Yt=Object.hasOwn||function(t,e){return Gt(Vt(t),e)},Jt=C,Zt=0,Xt=Math.random(),te=Jt(1..toString),ee=function(t){return'Symbol('+(void 0===t?'':t)+')_'+te(++Zt+Xt,36)},re=m,ne=Ut.exports,oe=Yt,ie=ee,se=St,ae=Tt,ue=ne('wks'),ce=re.Symbol,he=ce&&ce.for,le=ae?ce:ce&&ce.withoutSetter||ie,fe=function(t){if(!oe(ue,t)||!se&&'string'!=typeof ue[t]){var e='Symbol.'+t;se&&oe(ce,t)?ue[t]=ce[t]:ue[t]=ae&&he?he(e):le(e)}return ue[t]},de=L,pe=nt,ve=Ot,me=Lt,ye=function(t,e){var r,n;if('string'===e&&Dt(r=t.toString)&&!Mt(n=$t(r,t)))return n;if(Dt(r=t.valueOf)&&!Mt(n=$t(r,t)))return n;if('string'!==e&&Dt(r=t.toString)&&!Mt(n=$t(r,t)))return n;throw Bt('Can\'t convert object to primitive value')},ge=TypeError,be=fe('toPrimitive'),we=function(t,e){if(!pe(t)||ve(t))return t;var r,n=me(t,be);if(n){if(void 0===e&&(e='default'),r=de(n,t,e),!pe(r)||ve(r))return r;throw ge('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),ye(t,e)},Se=Ot,Te=function(t){var e=we(t,'string');return Se(e)?e:e+''},Pe=nt,_e=m.document,Ee=Pe(_e)&&Pe(_e.createElement),Ae=function(t){return Ee?_e.createElement(t):{}},Oe=Ae,Re=!j&&!y((function(){return 7!=Object.defineProperty(Oe('div'),'a',{get:function(){return 7}}).a})),Ce=j,ke=L,Ne=$,je=F,xe=function(t){return tt(et(t))},Ie=Te,Le=Yt,$e=Re,De=Object.getOwnPropertyDescriptor;N.f=Ce?De:function(t,e){if(t=xe(t),e=Ie(e),$e)try{return De(t,e)}catch(t){}if(Le(t,e))return je(!ke(Ne.f,t,e),t[e])};var Me=y,Be=k,Ue=/#|\.prototype\./,qe=function(t,e){var r=He[Fe(t)];return r==Qe||r!=ze&&(Be(e)?Me(e):!!e)},Fe=qe.normalize=function(t){return String(t).replace(Ue,'.').toLowerCase()},He=qe.data={},ze=qe.NATIVE='N',Qe=qe.POLYFILL='P',Ke=qe,We=xt,Ve=g,Ge=C(C.bind),Ye=function(t,e){return We(t),void 0===e?t:Ve?Ge(t,e):function(){return t.apply(e,arguments)}},Je={},Ze=j&&y((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),Xe=nt,tr=String,er=TypeError,rr=function(t){if(Xe(t))return t;throw er(tr(t)+' is not an object')},nr=j,or=Re,ir=Ze,sr=rr,ar=Te,ur=TypeError,cr=Object.defineProperty,hr=Object.getOwnPropertyDescriptor;Je.f=nr?ir?function(t,e,r){if(sr(t),e=ar(e),sr(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var n=hr(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:'configurable'in r?r.configurable:n.configurable,enumerable:'enumerable'in r?r.enumerable:n.enumerable,writable:!1})}return cr(t,e,r)}:cr:function(t,e,r){if(sr(t),e=ar(e),sr(r),or)try{return cr(t,e,r)}catch(t){}if('get'in r||'set'in r)throw ur('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var lr=Je,fr=F,dr=j?function(t,e,r){return lr.f(t,e,fr(1,r))}:function(t,e,r){return t[e]=r,t},pr=m,vr=P,mr=C,yr=k,gr=N.f,br=Ke,wr=ot,Sr=Ye,Tr=dr,Pr=Yt,_r=function(t){var e=function(r,n,o){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,n)}return new t(r,n,o)}return vr(t,this,arguments)};return e.prototype=t.prototype,e},Er=function(t,e){var r,n,o,i,s,a,u,c,h=t.target,l=t.global,f=t.stat,d=t.proto,p=l?pr:f?pr[h]:(pr[h]||{}).prototype,v=l?wr:wr[h]||Tr(wr,h,{})[h],m=v.prototype;for(o in e)r=!br(l?o:h+(f?'.':'#')+o,t.forced)&&p&&Pr(p,o),s=v[o],r&&(a=t.dontCallGetSet?(c=gr(p,o))&&c.value:p[o]),i=r&&a?a:e[o],r&&typeof s==typeof i||(u=t.bind&&r?Sr(i,pr):t.wrap&&r?_r(i):d&&yr(i)?mr(i):i,(t.sham||i&&i.sham||s&&s.sham)&&Tr(u,'sham',!0),Tr(v,o,u),d&&(Pr(wr,n=h+'Prototype')||Tr(wr,n,{}),Tr(wr[n],o,i),t.real&&m&&!m[o]&&Tr(m,o,i)))},Ar='process'==K(m.process),Or=dr,Rr=(TypeError,C);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=Rr(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var Cr={};Cr[fe('toStringTag')]='z';var kr='[object z]'===String(Cr),Nr=kr,jr=k,xr=K,Ir=fe('toStringTag'),Lr=Object,$r='Arguments'==xr(function(){return arguments}()),Dr=Nr?xr:function(t){var e,r,n;return void 0===t?'Undefined':null===t?'Null':'string'==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=Lr(t),Ir))?r:$r?xr(e):'Object'==(n=xr(e))&&jr(e.callee)?'Arguments':n},Mr=Dr,Br=kr?{}.toString:function(){return'[object '+Mr(this)+']'},Ur=kr,qr=Je.f,Fr=dr,Hr=Yt,zr=Br,Qr=fe('toStringTag'),Kr=ct,Wr=Je,Vr=j,Gr=fe('species'),Yr=ht,Jr=TypeError,Zr=k,Xr=zt,tn=C(Function.toString);Zr(Xr.inspectSource)||(Xr.inspectSource=function(t){return tn(t)});var en=Xr.inspectSource,rn=C,nn=y,on=k,sn=Dr,an=en,un=function(){},cn=[],hn=ct('Reflect','construct'),ln=/^\s*(?:class|function)\b/,fn=rn(ln.exec),dn=!ln.exec(un),pn=function(t){if(!on(t))return!1;try{return hn(un,cn,t),!0}catch(t){return!1}},vn=function(t){if(!on(t))return!1;switch(sn(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return dn||!!fn(ln,an(t))}catch(t){return!0}};vn.sham=!0;var mn,yn,gn,bn,wn=!hn||nn((function(){var t;return pn(pn.call)||!pn(Object)||!pn((function(){t=!0}))||t}))?vn:pn,Sn=Ct,Tn=TypeError,Pn=rr,_n=function(t){if(wn(t))return t;throw Tn(Sn(t)+' is not a constructor')},En=fe('species'),An=function(t,e){var r,n=Pn(t).constructor;return void 0===n||null==(r=Pn(n)[En])?e:_n(r)},On=ct('document','documentElement'),Rn=C([].slice),Cn=TypeError,kn=/(?:ipad|iphone|ipod).*applewebkit/i.test(lt),Nn=m,jn=P,xn=Ye,In=k,Ln=Yt,$n=y,Dn=On,Mn=Rn,Bn=Ae,Un=function(t,e){if(t<e)throw Cn('Not enough arguments');return t},qn=kn,Fn=Ar,Hn=Nn.setImmediate,zn=Nn.clearImmediate,Qn=Nn.process,Kn=Nn.Dispatch,Wn=Nn.Function,Vn=Nn.MessageChannel,Gn=Nn.String,Yn=0,Jn={};try{mn=Nn.location}catch(t){}var Zn=function(t){if(Ln(Jn,t)){var e=Jn[t];delete Jn[t],e()}},Xn=function(t){return function(){Zn(t)}},to=function(t){Zn(t.data)},eo=function(t){Nn.postMessage(Gn(t),mn.protocol+'//'+mn.host)};Hn&&zn||(Hn=function(t){Un(arguments.length,1);var e=In(t)?t:Wn(t),r=Mn(arguments,1);return Jn[++Yn]=function(){jn(e,void 0,r)},yn(Yn),Yn},zn=function(t){delete Jn[t]},Fn?yn=function(t){Qn.nextTick(Xn(t))}:Kn&&Kn.now?yn=function(t){Kn.now(Xn(t))}:Vn&&!qn?(bn=(gn=new Vn).port2,gn.port1.onmessage=to,yn=xn(bn.postMessage,bn)):Nn.addEventListener&&In(Nn.postMessage)&&!Nn.importScripts&&mn&&'file:'!==mn.protocol&&!$n(eo)?(yn=eo,Nn.addEventListener('message',to,!1)):yn='onreadystatechange'in Bn('script')?function(t){Dn.appendChild(Bn('script')).onreadystatechange=function(){Dn.removeChild(this),Zn(t)}}:function(t){setTimeout(Xn(t),0)});var ro,no,oo,io,so,ao,uo,co,ho={set:Hn,clear:zn},lo=m,fo=/ipad|iphone|ipod/i.test(lt)&&void 0!==lo.Pebble,po=/web0s(?!.*chrome)/i.test(lt),vo=m,mo=Ye,yo=N.f,go=ho.set,bo=kn,wo=fo,So=po,To=Ar,Po=vo.MutationObserver||vo.WebKitMutationObserver,_o=vo.document,Eo=vo.process,Ao=vo.Promise,Oo=yo(vo,'queueMicrotask'),Ro=Oo&&Oo.value;Ro||(ro=function(){var t,e;for(To&&(t=Eo.domain)&&t.exit();no;){e=no.fn,no=no.next;try{e()}catch(t){throw no?io():oo=void 0,t}}oo=void 0,t&&t.enter()},bo||To||So||!Po||!_o?!wo&&Ao&&Ao.resolve?((uo=Ao.resolve(void 0)).constructor=Ao,co=mo(uo.then,uo),io=function(){co(ro)}):To?io=function(){Eo.nextTick(ro)}:(go=mo(go,vo),io=function(){go(ro)}):(so=!0,ao=_o.createTextNode(''),new Po(ro).observe(ao,{characterData:!0}),io=function(){ao.data=so=!so}));var Co=Ro||function(t){var e={fn:t,next:void 0};oo&&(oo.next=e),no||(no=e,io()),oo=e},ko=m,No=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},jo=function(){this.head=null,this.tail=null};jo.prototype={add:function(t){var e={item:t,next:null};this.head?this.tail.next=e:this.head=e,this.tail=e},get:function(){var t=this.head;if(t)return this.head=t.next,this.tail===t&&(this.tail=null),t.item}};var xo,Io,Lo,$o=jo,Do=k,Mo=en,Bo=m.WeakMap,Uo=Do(Bo)&&/native code/.test(Mo(Bo)),qo=Ut.exports,Fo=ee,Ho=qo('keys'),zo=Uo,Qo=m,Ko=C,Wo=nt,Vo=dr,Go=Yt,Yo=zt,Jo=function(t){return Ho[t]||(Ho[t]=Fo(t))},Zo=Qo.TypeError,Xo=Qo.WeakMap;if(zo||Yo.state){var ti=Yo.state||(Yo.state=new Xo),ei=Ko(ti.get),ri=Ko(ti.has),ni=Ko(ti.set);xo=function(t,e){if(ri(ti,t))throw new Zo('Object already initialized');return e.facade=t,ni(ti,t,e),e},Io=function(t){return ei(ti,t)||{}},Lo=function(t){return ri(ti,t)}}else{var oi=Jo('state');xo=function(t,e){if(Go(t,oi))throw new Zo('Object already initialized');return e.facade=t,Vo(t,oi,e),e},Io=function(t){return Go(t,oi)?t[oi]:{}},Lo=function(t){return Go(t,oi)}}var ii={set:xo,get:Io,has:Lo,enforce:function(t){return Lo(t)?Io(t):xo(t,{})},getterFor:function(t){return function(e){var r;if(!Wo(e)||(r=Io(e)).type!==t)throw Zo('Incompatible receiver, '+t+' required');return r}}},si=m.Promise,ai='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,ui=!ai&&!Ar&&'object'==typeof window&&'object'==typeof document,ci=m,hi=si,li=k,fi=Ke,di=en,pi=fe,vi=ui,mi=ai,yi=gt,gi=hi&&hi.prototype,bi=pi('species'),wi=!1,Si=li(ci.PromiseRejectionEvent),Ti={CONSTRUCTOR:fi('Promise',(function(){var t=di(hi),e=t!==String(hi);if(!e&&66===yi)return!0;if(!gi.catch||!gi.finally)return!0;if(!yi||yi<51||!/native code/.test(t)){var r=new hi((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};if((r.constructor={})[bi]=n,!(wi=r.then((function(){}))instanceof n))return!0}return!e&&(vi||mi)&&!Si})),REJECTION_EVENT:Si,SUBCLASSING:wi},Pi={},_i=xt,Ei=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError('Bad Promise constructor');e=t,r=n})),this.resolve=_i(e),this.reject=_i(r)};Pi.f=function(t){return new Ei(t)};var Ai,Oi,Ri=Er,Ci=Ar,ki=m,Ni=L,ji=function(t,e,r,n){return n&&n.enumerable?t[e]=r:Or(t,e,r),t},xi=function(t,e,r,n){if(t){var o=r?t:t.prototype;Hr(o,Qr)||qr(o,Qr,{configurable:!0,value:e}),n&&!Ur&&Fr(o,'toString',zr)}},Ii=function(t){var e=Kr(t),r=Wr.f;Vr&&e&&!e[Gr]&&r(e,Gr,{configurable:!0,get:function(){return this}})},Li=xt,$i=k,Di=nt,Mi=function(t,e){if(Yr(e,t))return t;throw Jr('Incorrect invocation')},Bi=An,Ui=ho.set,qi=Co,Fi=function(t,e){var r=ko.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Hi=No,zi=$o,Qi=ii,Ki=si,Wi=Pi,Vi=Ti.CONSTRUCTOR,Gi=Ti.REJECTION_EVENT,Yi=Qi.getterFor('Promise'),Ji=Qi.set,Zi=Ki&&Ki.prototype,Xi=Ki,ts=Zi,es=ki.TypeError,rs=ki.document,ns=ki.process,os=Wi.f,is=os,ss=!!(rs&&rs.createEvent&&ki.dispatchEvent),as=function(t){var e;return!(!Di(t)||!$i(e=t.then))&&e},us=function(t,e){var r,n,o,i=e.value,s=1==e.state,a=s?t.ok:t.fail,u=t.resolve,c=t.reject,h=t.domain;try{a?(s||(2===e.rejection&&ds(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),o=!0)),r===t.promise?c(es('Promise-chain cycle')):(n=as(r))?Ni(n,r,u,c):u(r)):c(i)}catch(t){h&&!o&&h.exit(),c(t)}},cs=function(t,e){t.notified||(t.notified=!0,qi((function(){for(var r,n=t.reactions;r=n.get();)us(r,t);t.notified=!1,e&&!t.rejection&&ls(t)})))},hs=function(t,e,r){var n,o;ss?((n=rs.createEvent('Event')).promise=e,n.reason=r,n.initEvent(t,!1,!0),ki.dispatchEvent(n)):n={promise:e,reason:r},!Gi&&(o=ki['on'+t])?o(n):'unhandledrejection'===t&&Fi('Unhandled promise rejection',r)},ls=function(t){Ni(Ui,ki,(function(){var e,r=t.facade,n=t.value;if(fs(t)&&(e=Hi((function(){Ci?ns.emit('unhandledRejection',n,r):hs('unhandledrejection',r,n)})),t.rejection=Ci||fs(t)?2:1,e.error))throw e.value}))},fs=function(t){return 1!==t.rejection&&!t.parent},ds=function(t){Ni(Ui,ki,(function(){var e=t.facade;Ci?ns.emit('rejectionHandled',e):hs('rejectionhandled',e,t.value)}))},ps=function(t,e,r){return function(n){t(e,n,r)}},vs=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,cs(t,!0))},ms=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw es('Promise can\'t be resolved itself');var n=as(e);n?qi((function(){var r={done:!1};try{Ni(n,e,ps(ms,r,t),ps(vs,r,t))}catch(e){vs(r,e,t)}})):(t.value=e,t.state=1,cs(t,!1))}catch(e){vs({done:!1},e,t)}}};Vi&&(ts=(Xi=function(t){Mi(this,ts),Li(t),Ni(Ai,this);var e=Yi(this);try{t(ps(ms,e),ps(vs,e))}catch(t){vs(e,t)}}).prototype,(Ai=function(t){Ji(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new zi,rejection:!1,state:0,value:void 0})}).prototype=ji(ts,'then',(function(t,e){var r=Yi(this),n=os(Bi(this,Xi));return r.parent=!0,n.ok=!$i(t)||t,n.fail=$i(e)&&e,n.domain=Ci?ns.domain:void 0,0==r.state?r.reactions.add(n):qi((function(){us(n,r)})),n.promise})),Oi=function(){var t=new Ai,e=Yi(t);this.promise=t,this.resolve=ps(ms,e),this.reject=ps(vs,e)},Wi.f=os=function(t){return t===Xi||undefined===t?new Oi(t):is(t)}),Ri({global:!0,constructor:!0,wrap:!0,forced:Vi},{Promise:Xi}),xi(Xi,'Promise',!1,!0),Ii('Promise');var ys={},gs=ys,bs=fe('iterator'),ws=Array.prototype,Ss=Math.ceil,Ts=Math.floor,Ps=Math.trunc||function(t){var e=+t;return(e>0?Ts:Ss)(e)},_s=function(t){var e=+t;return e!=e||0===e?0:Ps(e)},Es=Math.min,As=function(t){return t>0?Es(_s(t),9007199254740991):0},Os=Dr,Rs=Lt,Cs=ys,ks=fe('iterator'),Ns=function(t){if(null!=t)return Rs(t,ks)||Rs(t,'@@iterator')||Cs[Os(t)]},js=L,xs=xt,Is=rr,Ls=Ct,$s=Ns,Ds=TypeError,Ms=L,Bs=rr,Us=Lt,qs=Ye,Fs=L,Hs=rr,zs=Ct,Qs=function(t){return void 0!==t&&(gs.Array===t||ws[bs]===t)},Ks=function(t){return As(t.length)},Ws=ht,Vs=function(t,e){var r=arguments.length<2?$s(t):e;if(xs(r))return Is(js(r,t));throw Ds(Ls(t)+' is not iterable')},Gs=Ns,Ys=function(t,e,r){var n,o;Bs(t);try{if(!(n=Us(t,'return'))){if('throw'===e)throw r;return r}n=Ms(n,t)}catch(t){o=!0,n=t}if('throw'===e)throw r;if(o)throw n;return Bs(n),r},Js=TypeError,Zs=function(t,e){this.stopped=t,this.result=e},Xs=Zs.prototype,ta=function(t,e,r){var n,o,i,s,a,u,c,h=r&&r.that,l=!(!r||!r.AS_ENTRIES),f=!(!r||!r.IS_RECORD),d=!(!r||!r.IS_ITERATOR),p=!(!r||!r.INTERRUPTED),v=qs(e,h),m=function(t){return n&&Ys(n,'normal',t),new Zs(!0,t)},y=function(t){return l?(Hs(t),p?v(t[0],t[1],m):v(t[0],t[1])):p?v(t,m):v(t)};if(f)n=t.iterator;else if(d)n=t;else{if(!(o=Gs(t)))throw Js(zs(t)+' is not iterable');if(Qs(o)){for(i=0,s=Ks(t);s>i;i++)if((a=y(t[i]))&&Ws(Xs,a))return a;return new Zs(!1)}n=Vs(t,o)}for(u=f?t.next:n.next;!(c=Fs(u,n)).done;){try{a=y(c.value)}catch(t){Ys(n,'throw',t)}if('object'==typeof a&&a&&Ws(Xs,a))return a}return new Zs(!1)},ea=fe('iterator'),ra=!1;try{var na=0,oa={next:function(){return{done:!!na++}},return:function(){ra=!0}};oa[ea]=function(){return this},Array.from(oa,(function(){throw 2}))}catch(t){}var ia=si,sa=Ti.CONSTRUCTOR||!function(t,e){if(!e&&!ra)return!1;var r=!1;try{var n={};n[ea]=function(){return{next:function(){return{done:r=!0}}}},t(n)}catch(t){}return r}((function(t){ia.all(t).then(void 0,(function(){}))})),aa=L,ua=xt,ca=Pi,ha=No,la=ta;Er({target:'Promise',stat:!0,forced:sa},{all:function(t){var e=this,r=ca.f(e),n=r.resolve,o=r.reject,i=ha((function(){var r=ua(e.resolve),i=[],s=0,a=1;la(t,(function(t){var u=s++,c=!1;a++,aa(r,e,t).then((function(t){c||(c=!0,i[u]=t,--a||n(i))}),o)})),--a||n(i)}));return i.error&&o(i.value),r.promise}});var fa=Er,da=Ti.CONSTRUCTOR;si&&si.prototype,fa({target:'Promise',proto:!0,forced:da,real:!0},{catch:function(t){return this.then(void 0,t)}});var pa=L,va=xt,ma=Pi,ya=No,ga=ta;Er({target:'Promise',stat:!0,forced:sa},{race:function(t){var e=this,r=ma.f(e),n=r.reject,o=ya((function(){var o=va(e.resolve);ga(t,(function(t){pa(o,e,t).then(r.resolve,n)}))}));return o.error&&n(o.value),r.promise}});var ba=L,wa=Pi;Er({target:'Promise',stat:!0,forced:Ti.CONSTRUCTOR},{reject:function(t){var e=wa.f(this);return ba(e.reject,void 0,t),e.promise}});var Sa=rr,Ta=nt,Pa=Pi,_a=function(t,e){if(Sa(t),Ta(e)&&e.constructor===t)return e;var r=Pa.f(t);return(0,r.resolve)(e),r.promise},Ea=Er,Aa=si,Oa=Ti.CONSTRUCTOR,Ra=_a,Ca=ct('Promise'),ka=!Oa;Ea({target:'Promise',stat:!0,forced:true},{resolve:function(t){return Ra(ka&&this===Ca?Aa:this,t)}});var Na=Er,ja=si,xa=y,Ia=ct,La=k,$a=An,Da=_a,Ma=ja&&ja.prototype;Na({target:'Promise',proto:!0,real:!0,forced:!!ja&&xa((function(){Ma.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=$a(this,Ia('Promise')),r=La(t);return this.then(r?function(r){return Da(e,t()).then((function(){return r}))}:t,r?function(r){return Da(e,t()).then((function(){throw r}))}:t)}});var Ba=ct('Promise','finally');const Ua=(()=>{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}})();var qa,Fa,Ha,za,Qa,Ka,Wa,Va={get:t=>function(t){const e=Ua?Ua.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{Ua&&Ua.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){Ua&&Ua.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(qa||(qa={})),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'}(Fa||(Fa={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(Ha||(Ha={})),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'}(za||(za={})),function(t){t.AUTO='auto',t.MANUAL=''}(Qa||(Qa={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(Ka||(Ka={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(Wa||(Wa={}));const Ga={[qa.PROD]:'https://api.ok.ru',[qa.VK_ALIAS]:'https://api.mycdn.me',[qa.VIDEOTEST]:'https://videotestapi.ok.ru/api',[qa.TEST]:'https://apitest.ok.ru',[qa.AUTO]:''},Ya={start:1e3,factor:1.5,max:3e5,random:.1};var Ja;!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'}(Ja||(Ja={}));class Za{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const r=Va.get('uuid');r?this.uuid=String(r):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let r,n,o=0;for(n=0;n<36;n++)8===n||13===n||18===n||23===n?e[n]='-':14===n?e[n]='4':(o<=2&&(o=33554432+16777216*Math.random()|0),r=15&o,o>>=4,e[n]=t[19===n?3&r|8:r]);return e.join('')}(),Va.set('uuid',this.uuid))}authorize(t){return d(this,void 0,void 0,(function*(){return this.authToken=null!=t?t:yield this.refreshAuthToken(),this._authorizeWithBackoff()}))}logBeacon(t){const e=this.createLogParams(t),r=this.sessionKey;if(!r)return;this.params.apiTransport.sendBeacon('log.externalLog',e,r)||this.logRequest(t)}logRequest(t){var e;return d(this,void 0,void 0,(function*(){const r='log.externalLog',n=this.createLogParams(t),o=null!==(e=this.sessionKey)&&void 0!==e?e:yield this._authorizeWithBackoff();if(!o)return;const i=(t,e=this.params.requestRetryCount)=>d(this,void 0,void 0,(function*(){try{return yield this.params.apiTransport.sendRequest(r,n,o)}catch(n){if(!n||!('error_code'in n))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${r} error`,thrown:n});const o=null==n?void 0:n.error_code;switch(o){case Ja.PARAM_SESSION_EXPIRED:case Ja.PARAM_SESSION_KEY:case Ja.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;case Ja.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=yield this.refreshAuthToken(),this.sessionKey=yield this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${r} error`,data:n})}}}));return i(t)}))}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}refreshAuthToken(){return d(this,void 0,void 0,(function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=Ba(this.params.refreshAuthToken(),(()=>{this.refreshAuthTokenPromise=void 0}))),this.refreshAuthTokenPromise}))}createLogParams(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:t.map((t=>Object.assign(Object.assign({},t),{time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,Ya);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{Ba(this._authorize().then(e).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))),(()=>this.backoffTimeoutId=0))}),t))}))}_authorize(){return d(this,void 0,void 0,(function*(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=Ba(this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((t=>d(this,void 0,void 0,(function*(){this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case Ja.AUTH_LOGIN:return this.authToken=yield this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})))),(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}))}}function Xa(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const tu=Xa({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),eu=tu?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:r=e.Request,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=t;if(!Xa({fetch:e,Request:r,AbortController:n,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:i};let i=r;(i&&!i.prototype.hasOwnProperty('signal')||o)&&(i=function(t,e){let n;e&&e.signal&&(n=e.signal,delete e.signal);const o=new r(t,e);return n&&Object.defineProperty(o,'signal',{writable:!1,enumerable:!1,configurable:!0,value:n}),o},i.prototype=r.prototype);const s=e;return{fetch:(t,e)=>{const r=i&&i.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(r){let n;try{n=new DOMException('Aborted','AbortError')}catch(t){n=new Error('Aborted'),n.name='AbortError'}if(r.aborted)return Promise.reject(n);const o=new Promise(((t,e)=>{r.addEventListener('abort',(()=>e(n)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([o,s(t,e)])}return s(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,ru=tu?eu.fetch:window.fetch;tu?eu.Request:window.Request;class nu{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var t;return d(this,void 0,void 0,(function*(){if(this.apiEnv!==qa.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),r=yield ru(e,{method:'GET',mode:'cors',cache:'no-cache'}),n=yield r.json(),o=null===(t=null==n?void 0:n.Answer[0])||void 0===t?void 0:t.data;if(!o)throw new Error('Wrong DNS response');return o}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),Ga[qa.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}))}sendBeacon(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;const n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,o)}catch(r){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:r,data:{method:t,params:e}})}return!1}sendRequest(t,e,n){return d(this,void 0,void 0,(function*(){const o=r(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:t,params:e,sessionKey:n,time:r()-o}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),ru(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:n})}).then((t=>{var e;const n=0===Number(t.headers.get('content-length')),s=new Date(null!==(e=t.headers.get('date'))&&void 0!==e?e:'').getTime(),a=r()-o;if(isFinite(s)&&this.timeSynchronisation.addServerTime(s,a),!n)return t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),i)}),i)}))}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,r])=>e.append(t,'string'==typeof r?r:JSON.stringify(r)))),e}}class ou{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=f((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class iu{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const r=t-Date.now()-e/2;if(Math.abs(r)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(r);else{const t=.2;this.offset=Math.round(t*r+(1-t)*this.offset)}}}const su=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0'),au=t=>t&&{[c.HTTP1]:Ka.HTTP1,[c.HTTP2]:Ka.HTTP2,[c.QUIC]:Ka.HTTP3}[t],uu=t=>{if(void 0!==t)switch(t){case h.MPEG:return za.MP4;case h.DASH:case h.DASH_LIVE:return za.DASH;case h.DASH_SEP:return za.DASH_SEP;case h.DASH_ONDEMAND:return za.ONDEMAND_DASH;case h.DASH_WEBM:case h.DASH_LIVE_WEBM:return za.WEBM;case h.HLS:case h.HLS_LIVE:return za.HLS;case h.HLS_ONDEMAND:return za.ONDEMAND_HLS;case h.WEB_RTC_LIVE:return za.RTMP;default:return n(t)}};class cu{constructor(t,e){var r;this.subscription=new o,this.timeSynchronisation=new iu,this.vsid=su(),this.fieldBlacklist=[],this.statContext=t,this.config=Object.assign(Object.assign({},null!==(r=e.config)&&void 0!==r?r:{}),{requestRetryCount:1});const n=new i;this.experimental={error$:n};const a=new nu({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:Ga[e.apiEnv],apiEnv:e.apiEnv,error$:n,timeSynchronisation:this.timeSynchronisation});this.api=new Za({apiTransport:a,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:n}),this.logger=new ou({api:this.api,error$:n}),this.subscription.add(s(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext=Object.assign(Object.assign({},this.statContext),t)}attachTo(t){let e;return(new o).add(t.events.started$.subscribe((()=>{this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.looped$.subscribe((()=>{this.resetViewSession(),this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.seeked$.subscribe((()=>{this.logSeek()}))).add(t.events.willPause$.subscribe((()=>{this.logPause({position:t.info.position$.getValue()})}))).add(t.events.willResume$.subscribe((()=>{this.logPlay()}))).add(t.events.managedError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.inited$.subscribe((()=>{this.logInited()}))).add(t.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(t.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(t.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(t.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(t.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(t.info.isStalled$.subscribe((t=>{t?e=r():(a(e)&&this.logEmptyBuffer({duration:r()-e}),e=void 0)}))).add(t.events.ended$.subscribe((()=>{const e=t.info.throughputEstimation$.getValue();a(e)&&this.logDownloadSpeed({speed:e/8})}))).add(t.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(t.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:au(t)})}))).add(t.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(t.info.currentQuality$.subscribe((t=>{var e;this.updateContext({quality:(e=t,e&&{[u.INVARIANT]:Fa.UNKNOWN,[u.Q_144P]:Fa.Q144P,[u.Q_240P]:Fa.Q240P,[u.Q_360P]:Fa.Q360P,[u.Q_480P]:Fa.Q480P,[u.Q_720P]:Fa.Q720P,[u.Q_1080P]:Fa.Q1080P,[u.Q_1440P]:Fa.Q1440P,[u.Q_2160P]:Fa.Q2160P,[u.Q_4320P]:Fa.Q4320P}[e])})}))).add(t.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:uu(t)})}))).add(t.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===l.CONNECTED?Ha.CHROMECAST:Ha.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=su()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),r=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${r}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){const r=this.timeSynchronisation.now(),n={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:!0===this.statContext.connectionReused?Wa.YES:!1===this.statContext.connectionReused?Wa.NO:void 0,stat_type:!0===this.statContext.autoplay?Qa.AUTO:!1===this.statContext.autoplay?Qa.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(n.param=e);for(const t of this.fieldBlacklist)delete n[t];return{operation:t,timestamp:r,custom:n}}}export{qa as ApiEnv,Ka as ConnectionType,za as ContentType,cu as OneStat,Fa as Quality,Ha as ScreenDestination};
|
package/es2018.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var e=require('@vkontakte/videoplayer-shared/es2018.cjs.js'),t=require('@vkontakte/videoplayer-core/es2018.cjs.js');function s(e){return e&&'object'==typeof e&&'default'in e?e:{default:e}}var o=s(require('lodash/debounce.js'));const i=(()=>{try{const e=Date.now().toString(),t=window.localStorage;t.setItem(e,e);const s=t.getItem(e)===e;return t.removeItem(e),s?t:null}catch(e){return null}})();var r,n,a,h,u,d,l,p={get:e=>function(e){const t=i?i.getItem('_one-stat_'+e):null;if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}(e)||null,set(e,t){!function(e,t){try{i&&i.setItem('_one-stat_'+e,JSON.stringify(t))}catch(e){}}(e,t)},remove(e){!function(e){i&&i.removeItem('_one-stat_'+e)}(e)}};exports.ApiEnv=void 0,(r=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',r.VK_ALIAS='vk_alias',r.VIDEOTEST='videotest',r.TEST='test',r.AUTO='auto',exports.Quality=void 0,(n=exports.Quality||(exports.Quality={})).Q144P='144',n.Q240P='240',n.Q360P='360',n.Q480P='480',n.Q720P='720',n.Q1080P='1080',n.Q1440P='1440',n.Q2160P='2160',n.Q4320P='4320',n.UNKNOWN='unknown',exports.ScreenDestination=void 0,(a=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',a.APPLE_TV='appletv',a.PIP='pip',a.HEADPHONES='externalHeadphones',a.SCREEN='',exports.ContentType=void 0,(h=exports.ContentType||(exports.ContentType={})).MP4='mp4',h.DASH='dash',h.DASH_SEP='dash_sep',h.ONDEMAND_DASH='ondemand_dash',h.HLS='hls',h.ONDEMAND_HLS='ondemand_hls',h.WEBM='webm',h.RTMP='rtmp',h.UNKNOWN='unknown',function(e){e.AUTO='auto',e.MANUAL=''}(u||(u={})),exports.ConnectionType=void 0,(d=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',d.HTTP2='http2',d.HTTP3='http3',function(e){e[e.YES=1]='YES',e[e.NO=0]='NO'}(l||(l={}));const c={[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]:''},m={start:1e3,factor:1.5,max:3e5,random:.1};var f;!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'}(f||(f={}));class y{constructor(t){this.consequentAuthErrors=0,this.authorized$=new e.ValueSubject(!1),this.params=t;const s=p.get('uuid');s?this.uuid=String(s):(this.uuid=function(){const e='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),t=new Array(36);let s,o,i=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?t[o]='-':14===o?t[o]='4':(i<=2&&(i=33554432+16777216*Math.random()|0),s=15&i,i>>=4,t[o]=e[19===o?3&s|8:s]);return t.join('')}(),p.set('uuid',this.uuid))}async authorize(e){return this.authToken=null!=e?e:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const t=this.createLogParams(e),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',t,s)||this.logRequest(e)}async logRequest(e){var t;const s='log.externalLog',o=this.createLogParams(e),i=null!==(t=this.sessionKey)&&void 0!==t?t:await this._authorizeWithBackoff();if(!i)return;const r=async(e,t=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const i=null==o?void 0:o.error_code;switch(i){case f.PARAM_SESSION_EXPIRED:case f.PARAM_SESSION_KEY:case f.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),t>0?r(e,t-1):void 0;case f.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),t>0?r(e,t-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${i}`,message:`${s} error`,data:o})}}};return r(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:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:e.map((e=>({...e,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e.getExponentialDelay(this.consequentAuthErrors,m);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(e).catch((e=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:e}))).finally((()=>this.backoffTimeoutId=0))}),t))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(e.session_data.auth_token=this.authToken,e.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',e).then((e=>{var t;return e&&e.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:e}),this.sessionKey=null!==(t=null==e?void 0:e.session_key)&&void 0!==t?t:void 0,this.sessionKey})).catch((async e=>{this.sessionKey=void 0;const t=null==e?void 0:e.error_code;switch(t){case f.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}t?this.params.error$.next({id:`Authorize#${t}`,message:'authorize error',data:e}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:e})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function g(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof e.Request&&!e.Request.prototype.hasOwnProperty('signal')||!e.AbortController}const v=g({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),A=v?function(e){'function'==typeof e&&(e={fetch:e});const{fetch:t,Request:s=t.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=e;if(!g({fetch:t,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:t,Request:r};let r=s;(r&&!r.prototype.hasOwnProperty('signal')||i)&&(r=function(e,t){let o;t&&t.signal&&(o=t.signal,delete t.signal);const i=new s(e,t);return o&&Object.defineProperty(i,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),i},r.prototype=s.prototype);const n=t;return{fetch:(e,t)=>{const s=r&&r.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(e){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const i=new Promise(((e,t)=>{s.addEventListener('abort',(()=>t(o)),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([i,n(e,t)])}return n(e,t)},Request:r}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,_=v?A.fetch:window.fetch;v?A.Request:window.Request;class T{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 t=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),s=await _(t,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),i=null===(e=null==o?void 0:o.Answer[0])||void 0===e?void 0:e.data;if(!i)throw new Error('Wrong DNS response');return i}catch(e){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:e}),c[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:t,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(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:e,params:t}})}return!1}async sendRequest(t,s,o){const i=e.now(),r=r=>{r instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(r.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:r}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:r,data:{method:t,params:s,sessionKey:o,time:e.now()-i}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),_(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:s,sessionKey:o})}).then((t=>{var s;const o=0===Number(t.headers.get('content-length')),n=new Date(null!==(s=t.headers.get('date'))&&void 0!==s?s:'').getTime(),a=e.now()-i;if(isFinite(n)&&this.timeSynchronisation.addServerTime(n,a),o)return t.json().then((e=>Object.prototype.hasOwnProperty.call(e,'error_msg')?Promise.reject(e):e),r)}),r)}_prepareQueryParams(e){const t=new URLSearchParams({format:'JSON',method:e.method,application_key:this.apiKey});return void 0!==e.sessionKey&&t.append('session_key',e.sessionKey),Object.entries(e.queryParams).forEach((([e,s])=>t.append(e,'string'==typeof s?s:JSON.stringify(s)))),t}}class S{constructor(e){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=o.default((()=>{var e;try{this.flush()}catch(t){this.error$.next({id:'LoggerError',message:null!==(e=String(t))&&void 0!==e?e:'Unknown logger error',thrown:t})}}),3e3,{maxWait:15e3}),this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe((e=>{e&&this.debouncedFlush()}))}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){0!==this.requestQueue.length&&(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{constructor(e){this.offset=void 0,this.offset=e}getOffset(){var e;return null!==(e=this.offset)&&void 0!==e?e:0}setOffset(e){this.offset=e}now(){var e;return Date.now()+(null!==(e=this.offset)&&void 0!==e?e:0)}date(e=new Date){var t;return e.setTime(e.getTime()+(null!==(t=this.offset)&&void 0!==t?t:0)),e}addServerTime(e,t){const s=e-Date.now()-t/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const e=.2;this.offset=Math.round(e*s+(1-e)*this.offset)}}}const b=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),E=e=>e&&{[t.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[t.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[t.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[e],P=s=>{if(void 0!==s)switch(s){case t.VideoFormat.MPEG:return exports.ContentType.MP4;case t.VideoFormat.DASH:case t.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case t.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case t.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case t.VideoFormat.DASH_WEBM:case t.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case t.VideoFormat.HLS:case t.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case t.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case t.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return e.assertNever(s)}};exports.OneStat=class{constructor(t,s){var o;this.subscription=new e.Subscription,this.timeSynchronisation=new w,this.vsid=b(),this.fieldBlacklist=[],this.statContext=t,this.config={...null!==(o=s.config)&&void 0!==o?o:{},requestRetryCount:1};const i=new e.Subject;this.experimental={error$:i};const r=new T({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:c[s.apiEnv],apiEnv:s.apiEnv,error$:i,timeSynchronisation:this.timeSynchronisation});this.api=new y({apiTransport:r,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:i}),this.logger=new S({api:this.api,error$:i}),this.subscription.add(e.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(s){let o;return(new e.Subscription).add(e.merge(s.events.started$,s.events.looped$).subscribe((()=>{this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.looped$.subscribe((()=>{this.resetViewSession()}))).add(s.events.seeked$.subscribe((()=>{this.logSeek()}))).add(s.events.willPause$.subscribe((()=>{this.logPause({position:s.info.position$.getValue()})}))).add(s.events.willResume$.subscribe((()=>{this.logPlay()}))).add(s.events.managedError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.fatalError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.inited$.subscribe((()=>{this.logInited()}))).add(s.events.canplay$.subscribe((e=>{this.logReady({time:e})}))).add(s.events.firstBytes$.subscribe((e=>{this.logFirstBytes({time:e})}))).add(s.events.firstFrame$.subscribe((e=>{this.logFirstFrame({time:e})}))).add(s.events.watchCoverageRecord$.subscribe((e=>{this.logWatchCoverageRecord(e)}))).add(s.events.watchCoverageLive$.subscribe((e=>{this.logWatchCoverageLive(e)}))).add(s.info.isStalled$.subscribe((t=>{t?o=e.now():(e.isNonNullable(o)&&this.logEmptyBuffer({duration:e.now()-o}),o=void 0)}))).add(s.events.ended$.subscribe((()=>{const t=s.info.throughputEstimation$.getValue();e.isNonNullable(t)&&this.logDownloadSpeed({speed:t/8})}))).add(s.info.hostname$.subscribe((e=>{this.updateContext({cdnHostname:e})}))).add(s.info.httpConnectionType$.subscribe((e=>{this.updateContext({connectionType:E(e)})}))).add(s.info.httpConnectionReused$.subscribe((e=>{this.updateContext({connectionReused:e})}))).add(s.info.currentQuality$.subscribe((e=>{var s;this.updateContext({quality:(s=e,s&&{[t.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[t.VideoQuality.Q_144P]:exports.Quality.Q144P,[t.VideoQuality.Q_240P]:exports.Quality.Q240P,[t.VideoQuality.Q_360P]:exports.Quality.Q360P,[t.VideoQuality.Q_480P]:exports.Quality.Q480P,[t.VideoQuality.Q_720P]:exports.Quality.Q720P,[t.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[t.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[t.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[t.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[s])})}))).add(s.info.currentFormat$.subscribe((e=>{this.updateContext({contentType:P(e)})}))).add(s.info.chromecastState$.subscribe((e=>{this.updateContext({destination:e===t.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=b()}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 t=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${t}-${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 t=this.createLogItem(e);this.logger.log(t)}createLogItem({operation:e,param:t}){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:!0===this.statContext.connectionReused?l.YES:!1===this.statContext.connectionReused?l.NO:void 0,stat_type:!0===this.statContext.autoplay?u.AUTO:!1===this.statContext.autoplay?u.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==t&&(o.param=t);for(const e of this.fieldBlacklist)delete o[e];return{operation:e,timestamp:s,custom:o}}};
|
|
6
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/es2018.cjs.js'),e=require('@vkontakte/videoplayer-core/es2018.cjs.js');function s(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var o=s(require('lodash/debounce.js'));const i=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const s=e.getItem(t)===t;return e.removeItem(t),s?e:null}catch(t){return null}})();var r,n,a,h,u,d,l,p={get:t=>function(t){const e=i?i.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{i&&i.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){i&&i.removeItem('_one-stat_'+t)}(t)}};exports.ApiEnv=void 0,(r=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',r.VK_ALIAS='vk_alias',r.VIDEOTEST='videotest',r.TEST='test',r.AUTO='auto',exports.Quality=void 0,(n=exports.Quality||(exports.Quality={})).Q144P='144',n.Q240P='240',n.Q360P='360',n.Q480P='480',n.Q720P='720',n.Q1080P='1080',n.Q1440P='1440',n.Q2160P='2160',n.Q4320P='4320',n.UNKNOWN='unknown',exports.ScreenDestination=void 0,(a=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',a.APPLE_TV='appletv',a.PIP='pip',a.HEADPHONES='externalHeadphones',a.SCREEN='',exports.ContentType=void 0,(h=exports.ContentType||(exports.ContentType={})).MP4='mp4',h.DASH='dash',h.DASH_SEP='dash_sep',h.ONDEMAND_DASH='ondemand_dash',h.HLS='hls',h.ONDEMAND_HLS='ondemand_hls',h.WEBM='webm',h.RTMP='rtmp',h.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(u||(u={})),exports.ConnectionType=void 0,(d=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',d.HTTP2='http2',d.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(l||(l={}));const c={[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]:''},m={start:1e3,factor:1.5,max:3e5,random:.1};var f;!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'}(f||(f={}));class y{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t.ValueSubject(!1),this.params=e;const s=p.get('uuid');s?this.uuid=String(s):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,i=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(i<=2&&(i=33554432+16777216*Math.random()|0),s=15&i,i>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),p.set('uuid',this.uuid))}async authorize(t){return this.authToken=null!=t?t:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(t){const e=this.createLogParams(t),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',e,s)||this.logRequest(t)}async logRequest(t){var e;const s='log.externalLog',o=this.createLogParams(t),i=null!==(e=this.sessionKey)&&void 0!==e?e:await this._authorizeWithBackoff();if(!i)return;const r=async(t,e=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const i=null==o?void 0:o.error_code;switch(i){case f.PARAM_SESSION_EXPIRED:case f.PARAM_SESSION_KEY:case f.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;case f.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${i}`,message:`${s} error`,data:o})}}};return r(t)}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(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t.getExponentialDelay(this.consequentAuthErrors,m);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(t).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))).finally((()=>this.backoffTimeoutId=0))}),e))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((async t=>{this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case f.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function g(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const v=g({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),A=v?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!g({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:r};let r=s;(r&&!r.prototype.hasOwnProperty('signal')||i)&&(r=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const i=new s(t,e);return o&&Object.defineProperty(i,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),i},r.prototype=s.prototype);const n=e;return{fetch:(t,e)=>{const s=r&&r.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(t){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const i=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([i,n(t,e)])}return n(t,e)},Request:r}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,_=v?A.fetch:window.fetch;v?A.Request:window.Request;class T{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var t;if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),s=await _(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),i=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!i)throw new Error('Wrong DNS response');return i}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),c[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(t,e,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:e,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(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:t,params:e}})}return!1}async sendRequest(e,s,o){const i=t.now(),r=r=>{r instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(r.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:r}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:r,data:{method:e,params:s,sessionKey:o,time:t.now()-i}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),_(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:e,queryParams:s,sessionKey:o})}).then((e=>{var s;const o=0===Number(e.headers.get('content-length')),n=new Date(null!==(s=e.headers.get('date'))&&void 0!==s?s:'').getTime(),a=t.now()-i;if(isFinite(n)&&this.timeSynchronisation.addServerTime(n,a),!o)return e.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r)}),r)}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,s])=>e.append(t,'string'==typeof s?s:JSON.stringify(s)))),e}}class S{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=o.default((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||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{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const s=t-Date.now()-e/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const t=.2;this.offset=Math.round(t*s+(1-t)*this.offset)}}}const b=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),E=t=>t&&{[e.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[e.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[e.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[t],P=s=>{if(void 0!==s)switch(s){case e.VideoFormat.MPEG:return exports.ContentType.MP4;case e.VideoFormat.DASH:case e.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case e.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case e.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case e.VideoFormat.DASH_WEBM:case e.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case e.VideoFormat.HLS:case e.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case e.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case e.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return t.assertNever(s)}};exports.OneStat=class{constructor(e,s){var o;this.subscription=new t.Subscription,this.timeSynchronisation=new w,this.vsid=b(),this.fieldBlacklist=[],this.statContext=e,this.config={...null!==(o=s.config)&&void 0!==o?o:{},requestRetryCount:1};const i=new t.Subject;this.experimental={error$:i};const r=new T({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:c[s.apiEnv],apiEnv:s.apiEnv,error$:i,timeSynchronisation:this.timeSynchronisation});this.api=new y({apiTransport:r,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:i}),this.logger=new S({api:this.api,error$:i}),this.subscription.add(t.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}attachTo(s){let o;return(new t.Subscription).add(s.events.started$.subscribe((()=>{this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.looped$.subscribe((()=>{this.resetViewSession(),this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.seeked$.subscribe((()=>{this.logSeek()}))).add(s.events.willPause$.subscribe((()=>{this.logPause({position:s.info.position$.getValue()})}))).add(s.events.willResume$.subscribe((()=>{this.logPlay()}))).add(s.events.managedError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(s.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(s.events.inited$.subscribe((()=>{this.logInited()}))).add(s.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(s.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(s.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(s.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(s.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(s.info.isStalled$.subscribe((e=>{e?o=t.now():(t.isNonNullable(o)&&this.logEmptyBuffer({duration:t.now()-o}),o=void 0)}))).add(s.events.ended$.subscribe((()=>{const e=s.info.throughputEstimation$.getValue();t.isNonNullable(e)&&this.logDownloadSpeed({speed:e/8})}))).add(s.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(s.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:E(t)})}))).add(s.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(s.info.currentQuality$.subscribe((t=>{var s;this.updateContext({quality:(s=t,s&&{[e.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[e.VideoQuality.Q_144P]:exports.Quality.Q144P,[e.VideoQuality.Q_240P]:exports.Quality.Q240P,[e.VideoQuality.Q_360P]:exports.Quality.Q360P,[e.VideoQuality.Q_480P]:exports.Quality.Q480P,[e.VideoQuality.Q_720P]:exports.Quality.Q720P,[e.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[e.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[e.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[e.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[s])})}))).add(s.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:P(t)})}))).add(s.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===e.ChromecastState.CONNECTED?exports.ScreenDestination.CHROMECAST:exports.ScreenDestination.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=b()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),s=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){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:!0===this.statContext.connectionReused?l.YES:!1===this.statContext.connectionReused?l.NO:void 0,stat_type:!0===this.statContext.autoplay?u.AUTO:!1===this.statContext.autoplay?u.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(o.param=e);for(const t of this.fieldBlacklist)delete o[t];return{operation:t,timestamp:s,custom:o}}};
|
package/es2018.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as t,getExponentialDelay as e,now as s,assertNever as o,Subscription as i,Subject as r,fromEvent as a,merge as n,isNonNullable as h}from'@vkontakte/videoplayer-shared/es2018.esm.js';import{VideoQuality as u,HttpConnectionType as d,VideoFormat as c,ChromecastState as l}from'@vkontakte/videoplayer-core/es2018.esm.js';import p from'lodash/debounce.js';const m=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const s=e.getItem(t)===t;return e.removeItem(t),s?e:null}catch(t){return null}})();var f,g,y,v,A,_,w,S={get:t=>function(t){const e=m?m.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{m&&m.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){m&&m.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(f||(f={})),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'}(g||(g={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(y||(y={})),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'}(v||(v={})),function(t){t.AUTO='auto',t.MANUAL=''}(A||(A={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(_||(_={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(w||(w={}));const b={[f.PROD]:'https://api.ok.ru',[f.VK_ALIAS]:'https://api.mycdn.me',[f.VIDEOTEST]:'https://videotestapi.ok.ru/api',[f.TEST]:'https://apitest.ok.ru',[f.AUTO]:''},P={start:1e3,factor:1.5,max:3e5,random:.1};var T;!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'}(T||(T={}));class E{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const s=S.get('uuid');s?this.uuid=String(s):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,i=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(i<=2&&(i=33554432+16777216*Math.random()|0),s=15&i,i>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),S.set('uuid',this.uuid))}async authorize(t){return this.authToken=null!=t?t:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(t){const e=this.createLogParams(t),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',e,s)||this.logRequest(t)}async logRequest(t){var e;const s='log.externalLog',o=this.createLogParams(t),i=null!==(e=this.sessionKey)&&void 0!==e?e:await this._authorizeWithBackoff();if(!i)return;const r=async(t,e=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const i=null==o?void 0:o.error_code;switch(i){case T.PARAM_SESSION_EXPIRED:case T.PARAM_SESSION_KEY:case T.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;case T.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${i}`,message:`${s} error`,data:o})}}};return r(t)}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(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,P);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(e).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))).finally((()=>this.backoffTimeoutId=0))}),t))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((async t=>{this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case T.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function R(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const O=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),k=O?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!R({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:r};let r=s;(r&&!r.prototype.hasOwnProperty('signal')||i)&&(r=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const i=new s(t,e);return o&&Object.defineProperty(i,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),i},r.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=r&&r.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(t){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const i=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([i,a(t,e)])}return a(t,e)},Request:r}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=O?k.fetch:window.fetch;O?k.Request:window.Request;class L{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var t;if(this.apiEnv!==f.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),s=await C(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),i=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!i)throw new Error('Wrong DNS response');return i}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),b[f.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(t,e,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:e,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(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:t,params:e}})}return!1}async sendRequest(t,e,o){const i=s(),r=r=>{r instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(r.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:r}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:r,data:{method:t,params:e,sessionKey:o,time:s()-i}})};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:t,queryParams:e,sessionKey:o})}).then((t=>{var e;const o=0===Number(t.headers.get('content-length')),a=new Date(null!==(e=t.headers.get('date'))&&void 0!==e?e:'').getTime(),n=s()-i;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,n),o)return t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r)}),r)}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,s])=>e.append(t,'string'==typeof s?s:JSON.stringify(s)))),e}}class N{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=p((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class I{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const s=t-Date.now()-e/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const t=.2;this.offset=Math.round(t*s+(1-t)*this.offset)}}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),x=t=>t&&{[d.HTTP1]:_.HTTP1,[d.HTTP2]:_.HTTP2,[d.QUIC]:_.HTTP3}[t],B=t=>{if(void 0!==t)switch(t){case c.MPEG:return v.MP4;case c.DASH:case c.DASH_LIVE:return v.DASH;case c.DASH_SEP:return v.DASH_SEP;case c.DASH_ONDEMAND:return v.ONDEMAND_DASH;case c.DASH_WEBM:case c.DASH_LIVE_WEBM:return v.WEBM;case c.HLS:case c.HLS_LIVE:return v.HLS;case c.HLS_ONDEMAND:return v.ONDEMAND_HLS;case c.WEB_RTC_LIVE:return v.RTMP;default:return o(t)}};class q{constructor(t,e){var s;this.subscription=new i,this.timeSynchronisation=new I,this.vsid=$(),this.fieldBlacklist=[],this.statContext=t,this.config={...null!==(s=e.config)&&void 0!==s?s:{},requestRetryCount:1};const o=new r;this.experimental={error$:o};const n=new L({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:b[e.apiEnv],apiEnv:e.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new E({apiTransport:n,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new N({api:this.api,error$:o}),this.subscription.add(a(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}attachTo(t){let e;return(new i).add(n(t.events.started$,t.events.looped$).subscribe((()=>{this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.looped$.subscribe((()=>{this.resetViewSession()}))).add(t.events.seeked$.subscribe((()=>{this.logSeek()}))).add(t.events.willPause$.subscribe((()=>{this.logPause({position:t.info.position$.getValue()})}))).add(t.events.willResume$.subscribe((()=>{this.logPlay()}))).add(t.events.managedError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.inited$.subscribe((()=>{this.logInited()}))).add(t.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(t.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(t.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(t.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(t.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(t.info.isStalled$.subscribe((t=>{t?e=s():(h(e)&&this.logEmptyBuffer({duration:s()-e}),e=void 0)}))).add(t.events.ended$.subscribe((()=>{const e=t.info.throughputEstimation$.getValue();h(e)&&this.logDownloadSpeed({speed:e/8})}))).add(t.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(t.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:x(t)})}))).add(t.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(t.info.currentQuality$.subscribe((t=>{var e;this.updateContext({quality:(e=t,e&&{[u.INVARIANT]:g.UNKNOWN,[u.Q_144P]:g.Q144P,[u.Q_240P]:g.Q240P,[u.Q_360P]:g.Q360P,[u.Q_480P]:g.Q480P,[u.Q_720P]:g.Q720P,[u.Q_1080P]:g.Q1080P,[u.Q_1440P]:g.Q1440P,[u.Q_2160P]:g.Q2160P,[u.Q_4320P]:g.Q4320P}[e])})}))).add(t.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:B(t)})}))).add(t.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===l.CONNECTED?y.CHROMECAST:y.SCREEN})})))}authorize(t){return this.api.authorize(t)}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(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),s=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){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:!0===this.statContext.connectionReused?w.YES:!1===this.statContext.connectionReused?w.NO:void 0,stat_type:!0===this.statContext.autoplay?A.AUTO:!1===this.statContext.autoplay?A.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(o.param=e);for(const t of this.fieldBlacklist)delete o[t];return{operation:t,timestamp:s,custom:o}}}export{f as ApiEnv,_ as ConnectionType,v as ContentType,q as OneStat,g as Quality,y as ScreenDestination};
|
|
6
|
+
import{ValueSubject as t,getExponentialDelay as e,now as s,assertNever as o,Subscription as i,Subject as r,fromEvent as a,isNonNullable as n}from'@vkontakte/videoplayer-shared/es2018.esm.js';import{VideoQuality as h,HttpConnectionType as u,VideoFormat as d,ChromecastState as c}from'@vkontakte/videoplayer-core/es2018.esm.js';import l from'lodash/debounce.js';const p=(()=>{try{const t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);const s=e.getItem(t)===t;return e.removeItem(t),s?e:null}catch(t){return null}})();var m,f,g,y,A,v,_,w={get:t=>function(t){const e=p?p.getItem('_one-stat_'+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null,set(t,e){!function(t,e){try{p&&p.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){p&&p.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(m||(m={})),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'}(f||(f={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(g||(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'}(y||(y={})),function(t){t.AUTO='auto',t.MANUAL=''}(A||(A={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(v||(v={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(_||(_={}));const S={[m.PROD]:'https://api.ok.ru',[m.VK_ALIAS]:'https://api.mycdn.me',[m.VIDEOTEST]:'https://videotestapi.ok.ru/api',[m.TEST]:'https://apitest.ok.ru',[m.AUTO]:''},b={start:1e3,factor:1.5,max:3e5,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 T{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const s=w.get('uuid');s?this.uuid=String(s):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,i=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(i<=2&&(i=33554432+16777216*Math.random()|0),s=15&i,i>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),w.set('uuid',this.uuid))}async authorize(t){return this.authToken=null!=t?t:await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(t){const e=this.createLogParams(t),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',e,s)||this.logRequest(t)}async logRequest(t){var e;const s='log.externalLog',o=this.createLogParams(t),i=null!==(e=this.sessionKey)&&void 0!==e?e:await this._authorizeWithBackoff();if(!i)return;const r=async(t,e=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,i)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const i=null==o?void 0:o.error_code;switch(i){case P.PARAM_SESSION_EXPIRED:case P.PARAM_SESSION_KEY:case P.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;case P.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),e>0?r(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${i}`,message:`${s} error`,data:o})}}};return r(t)}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(t){return{collector:'ok.mobile.apps.video',data:JSON.stringify({application:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,b);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(e).catch((t=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:t}))).finally((()=>this.backoffTimeoutId=0))}),t))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',t).then((t=>{var e;return t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=null!==(e=null==t?void 0:t.session_key)&&void 0!==e?e:void 0,this.sessionKey})).catch((async t=>{this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case P.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}e?this.params.error$.next({id:`Authorize#${e}`,message:'authorize error',data:t}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:t})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function E(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof t.Request&&!t.Request.prototype.hasOwnProperty('signal')||!t.AbortController}const R=E({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),O=R?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=t;if(!E({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:e,Request:r};let r=s;(r&&!r.prototype.hasOwnProperty('signal')||i)&&(r=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const i=new s(t,e);return o&&Object.defineProperty(i,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),i},r.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=r&&r.prototype.isPrototypeOf(t)?t.signal:e?e.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(t){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const i=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([i,a(t,e)])}return a(t,e)},Request:r}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,k=R?O.fetch:window.fetch;R?O.Request:window.Request;class C{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var t;if(this.apiEnv!==m.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),s=await k(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),i=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!i)throw new Error('Wrong DNS response');return i}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),S[m.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(t,e,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:e,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(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:t,params:e}})}return!1}async sendRequest(t,e,o){const i=s(),r=r=>{r instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(r.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:r}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:r,data:{method:t,params:e,sessionKey:o,time:s()-i}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),k(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:o})}).then((t=>{var e;const o=0===Number(t.headers.get('content-length')),a=new Date(null!==(e=t.headers.get('date'))&&void 0!==e?e:'').getTime(),n=s()-i;if(isFinite(a)&&this.timeSynchronisation.addServerTime(a,n),!o)return t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r)}),r)}_prepareQueryParams(t){const e=new URLSearchParams({format:'JSON',method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append('session_key',t.sessionKey),Object.entries(t.queryParams).forEach((([t,s])=>e.append(t,'string'==typeof s?s:JSON.stringify(s)))),e}}class L{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=l((()=>{var t;try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:null!==(t=String(e))&&void 0!==t?t:'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3}),this.api=t.api,this.error$=t.error$,this.subscription=this.api.authorized$.subscribe((t=>{t&&this.debouncedFlush()}))}log(t){this.requestQueue.push(t),this.isPaused||this.debouncedFlush()}flush(t=!1){0!==this.requestQueue.length&&(this.api.authorized$.getValue()?(t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[]):t||this.api.authorize(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe()}}class N{constructor(t){this.offset=void 0,this.offset=t}getOffset(){var t;return null!==(t=this.offset)&&void 0!==t?t:0}setOffset(t){this.offset=t}now(){var t;return Date.now()+(null!==(t=this.offset)&&void 0!==t?t:0)}date(t=new Date){var e;return t.setTime(t.getTime()+(null!==(e=this.offset)&&void 0!==e?e:0)),t}addServerTime(t,e){const s=t-Date.now()-e/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const t=.2;this.offset=Math.round(t*s+(1-t)*this.offset)}}}const I=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),$=t=>t&&{[u.HTTP1]:v.HTTP1,[u.HTTP2]:v.HTTP2,[u.QUIC]:v.HTTP3}[t],x=t=>{if(void 0!==t)switch(t){case d.MPEG:return y.MP4;case d.DASH:case d.DASH_LIVE:return y.DASH;case d.DASH_SEP:return y.DASH_SEP;case d.DASH_ONDEMAND:return y.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return y.WEBM;case d.HLS:case d.HLS_LIVE:return y.HLS;case d.HLS_ONDEMAND:return y.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return y.RTMP;default:return o(t)}};class B{constructor(t,e){var s;this.subscription=new i,this.timeSynchronisation=new N,this.vsid=I(),this.fieldBlacklist=[],this.statContext=t,this.config={...null!==(s=e.config)&&void 0!==s?s:{},requestRetryCount:1};const o=new r;this.experimental={error$:o};const n=new C({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:S[e.apiEnv],apiEnv:e.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new T({apiTransport:n,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new L({api:this.api,error$:o}),this.subscription.add(a(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}attachTo(t){let e;return(new i).add(t.events.started$.subscribe((()=>{this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.looped$.subscribe((()=>{this.resetViewSession(),this.logStarted({position:t.info.position$.getValue()})}))).add(t.events.seeked$.subscribe((()=>{this.logSeek()}))).add(t.events.willPause$.subscribe((()=>{this.logPause({position:t.info.position$.getValue()})}))).add(t.events.willResume$.subscribe((()=>{this.logPlay()}))).add(t.events.managedError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.fatalError$.subscribe((({id:t})=>{this.logError({errorType:t})}))).add(t.events.inited$.subscribe((()=>{this.logInited()}))).add(t.events.canplay$.subscribe((t=>{this.logReady({time:t})}))).add(t.events.firstBytes$.subscribe((t=>{this.logFirstBytes({time:t})}))).add(t.events.firstFrame$.subscribe((t=>{this.logFirstFrame({time:t})}))).add(t.events.watchCoverageRecord$.subscribe((t=>{this.logWatchCoverageRecord(t)}))).add(t.events.watchCoverageLive$.subscribe((t=>{this.logWatchCoverageLive(t)}))).add(t.info.isStalled$.subscribe((t=>{t?e=s():(n(e)&&this.logEmptyBuffer({duration:s()-e}),e=void 0)}))).add(t.events.ended$.subscribe((()=>{const e=t.info.throughputEstimation$.getValue();n(e)&&this.logDownloadSpeed({speed:e/8})}))).add(t.info.hostname$.subscribe((t=>{this.updateContext({cdnHostname:t})}))).add(t.info.httpConnectionType$.subscribe((t=>{this.updateContext({connectionType:$(t)})}))).add(t.info.httpConnectionReused$.subscribe((t=>{this.updateContext({connectionReused:t})}))).add(t.info.currentQuality$.subscribe((t=>{var e;this.updateContext({quality:(e=t,e&&{[h.INVARIANT]:f.UNKNOWN,[h.Q_144P]:f.Q144P,[h.Q_240P]:f.Q240P,[h.Q_360P]:f.Q360P,[h.Q_480P]:f.Q480P,[h.Q_720P]:f.Q720P,[h.Q_1080P]:f.Q1080P,[h.Q_1440P]:f.Q1440P,[h.Q_2160P]:f.Q2160P,[h.Q_4320P]:f.Q4320P}[e])})}))).add(t.info.currentFormat$.subscribe((t=>{this.updateContext({contentType:x(t)})}))).add(t.info.chromecastState$.subscribe((t=>{this.updateContext({destination:t===c.CONNECTED?g.CHROMECAST:g.SCREEN})})))}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause()}resume(){this.logger.resume()}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.vsid=I()}setFieldBlacklist(t=[]){this.fieldBlacklist=t}logInited(){this.log({operation:'init'})}logReady(t){this.log({operation:'player_ready',param:String(t.time)})}logStarted(t){this.log({operation:'play',param:String(Math.round(t.position))})}logPlay(){this.log({operation:'play_toggle'})}logPause(t){this.log({operation:'pause',param:String(Math.round(t.position))})}logSeek(){this.log({operation:'seek'})}logFirstBytes(t){this.log({operation:'first_bytes',param:String(t.time)})}logFirstFrame(t){this.log({operation:'first_frame',param:String(t.time)})}logError(t){this.log({operation:'error',param:t.errorType})}logWatchCoverageRecord(t){this.log({operation:'watch_coverage_record',param:`${t.start}-${t.end}`}),this.logger.flush(!0)}logWatchCoverageLive(t){const e=t.start+this.timeSynchronisation.getOffset(),s=t.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${e}-${s}`}),this.logger.flush(!0)}logEmptyBuffer(t){this.log({operation:'empty_buffer',param:String(t.duration)})}logDownloadSpeed(t){this.log({operation:'download_speed',param:String(t.speed)})}logAdSlotRequest(){this.log({operation:'adv',param:'slot_request'})}logAdStarted(t){this.log({operation:'adv',param:t})}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(t){const e=this.createLogItem(t);this.logger.log(e)}createLogItem({operation:t,param:e}){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:!0===this.statContext.connectionReused?_.YES:!1===this.statContext.connectionReused?_.NO:void 0,stat_type:!0===this.statContext.autoplay?A.AUTO:!1===this.statContext.autoplay?A.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==e&&(o.param=e);for(const t of this.fieldBlacklist)delete o[t];return{operation:t,timestamp:s,custom:o}}}export{m as ApiEnv,v as ConnectionType,y as ContentType,B as OneStat,f as Quality,g as ScreenDestination};
|
package/esnext.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var e=require('@vkontakte/videoplayer-shared/esnext.cjs.js'),t=require('@vkontakte/videoplayer-core/esnext.cjs.js');function s(e){return e&&'object'==typeof e&&'default'in e?e:{default:e}}var o=s(require('lodash/debounce.js'));const r=(()=>{try{const e=Date.now().toString(),t=window.localStorage;t.setItem(e,e);const s=t.getItem(e)===e;return t.removeItem(e),s?t:null}catch(e){return null}})();var i,n,a,h,u,d,p,c={get:e=>function(e){const t=r?r.getItem('_one-stat_'+e):null;if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}(e)||null,set(e,t){!function(e,t){try{r&&r.setItem('_one-stat_'+e,JSON.stringify(t))}catch(e){}}(e,t)},remove(e){!function(e){r&&r.removeItem('_one-stat_'+e)}(e)}};exports.ApiEnv=void 0,(i=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',i.VK_ALIAS='vk_alias',i.VIDEOTEST='videotest',i.TEST='test',i.AUTO='auto',exports.Quality=void 0,(n=exports.Quality||(exports.Quality={})).Q144P='144',n.Q240P='240',n.Q360P='360',n.Q480P='480',n.Q720P='720',n.Q1080P='1080',n.Q1440P='1440',n.Q2160P='2160',n.Q4320P='4320',n.UNKNOWN='unknown',exports.ScreenDestination=void 0,(a=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',a.APPLE_TV='appletv',a.PIP='pip',a.HEADPHONES='externalHeadphones',a.SCREEN='',exports.ContentType=void 0,(h=exports.ContentType||(exports.ContentType={})).MP4='mp4',h.DASH='dash',h.DASH_SEP='dash_sep',h.ONDEMAND_DASH='ondemand_dash',h.HLS='hls',h.ONDEMAND_HLS='ondemand_hls',h.WEBM='webm',h.RTMP='rtmp',h.UNKNOWN='unknown',function(e){e.AUTO='auto',e.MANUAL=''}(u||(u={})),exports.ConnectionType=void 0,(d=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',d.HTTP2='http2',d.HTTP3='http3',function(e){e[e.YES=1]='YES',e[e.NO=0]='NO'}(p||(p={}));const l={[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]:''},m={start:1e3,factor:1.5,max:3e5,random:.1};var f;!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'}(f||(f={}));class y{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new e.ValueSubject(!1);backoffTimeoutId;constructor(e){this.params=e;const t=c.get('uuid');t?this.uuid=String(t):(this.uuid=function(){const e='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),t=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?t[o]='-':14===o?t[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,t[o]=e[19===o?3&s|8:s]);return t.join('')}(),c.set('uuid',this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const t=this.createLogParams(e),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',t,s)||this.logRequest(e)}async logRequest(e){const t='log.externalLog',s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(e,i=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(t,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${t} error`,thrown:s});const o=s?.error_code;switch(o){case f.PARAM_SESSION_EXPIRED:case f.PARAM_SESSION_KEY:case f.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;case f.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${t} error`,data:s})}}};return r(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:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:e.map((e=>({...e,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e.getExponentialDelay(this.consequentAuthErrors,m);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(e).catch((e=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:e}))).finally((()=>this.backoffTimeoutId=0))}),t))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(e.session_data.auth_token=this.authToken,e.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',e).then((e=>(e&&e.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:e}),this.sessionKey=e?.session_key??void 0,this.sessionKey))).catch((async e=>{this.sessionKey=void 0;const t=e?.error_code;switch(t){case f.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}t?this.params.error$.next({id:`Authorize#${t}`,message:'authorize error',data:e}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:e})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function g(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof e.Request&&!e.Request.prototype.hasOwnProperty('signal')||!e.AbortController}const A=g({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),T=A?function(e){'function'==typeof e&&(e={fetch:e});const{fetch:t,Request:s=t.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=e;if(!g({fetch:t,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(e,t){let o;t&&t.signal&&(o=t.signal,delete t.signal);const r=new s(e,t);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const n=t;return{fetch:(e,t)=>{const s=i&&i.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(e){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const r=new Promise(((e,t)=>{s.addEventListener('abort',(()=>t(o)),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([r,n(e,t)])}return n(e,t)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,_=A?T.fetch:window.fetch;A?T.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='),t=await _(e,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await t.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}catch(e){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:e}),l[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:t,sessionKey:s}),r=new window.Blob([o.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,r)}catch(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:e,params:t}})}return!1}async sendRequest(t,s,o){const r=e.now(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:t,params:s,sessionKey:o,time:e.now()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),_(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:s,sessionKey:o})}).then((t=>{const s=0===Number(t.headers.get('content-length')),o=new Date(t.headers.get('date')??'').getTime(),n=e.now()-r;if(isFinite(o)&&this.timeSynchronisation.addServerTime(o,n),s)return t.json().then((e=>Object.prototype.hasOwnProperty.call(e,'error_msg')?Promise.reject(e):e),i)}),i)}_prepareQueryParams(e){const t=new URLSearchParams({format:'JSON',method:e.method,application_key:this.apiKey});return void 0!==e.sessionKey&&t.append('session_key',e.sessionKey),Object.entries(e.queryParams).forEach((([e,s])=>t.append(e,'string'==typeof s?s:JSON.stringify(s)))),t}}class S{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=o.default((()=>{try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:String(e)??'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe((e=>{e&&this.debouncedFlush()}))}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){0!==this.requestQueue.length&&(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,t){const s=e-Date.now()-t/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const e=.2;this.offset=Math.round(e*s+(1-e)*this.offset)}}}const b=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),E=e=>e&&{[t.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[t.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[t.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[e],P=s=>{if(void 0!==s)switch(s){case t.VideoFormat.MPEG:return exports.ContentType.MP4;case t.VideoFormat.DASH:case t.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case t.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case t.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case t.VideoFormat.DASH_WEBM:case t.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case t.VideoFormat.HLS:case t.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case t.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case t.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return e.assertNever(s)}};exports.OneStat=class{api;logger;config;subscription=new e.Subscription;timeSynchronisation=new w;experimental;statContext;vsid=b();fieldBlacklist=[];constructor(t,s){this.statContext=t,this.config={...s.config??{},requestRetryCount:1};const o=new e.Subject;this.experimental={error$:o};const r=new v({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:l[s.apiEnv],apiEnv:s.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new y({apiTransport:r,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new S({api:this.api,error$:o}),this.subscription.add(e.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(s){let o;return(new e.Subscription).add(e.merge(s.events.started$,s.events.looped$).subscribe((()=>{this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.looped$.subscribe((()=>{this.resetViewSession()}))).add(s.events.seeked$.subscribe((()=>{this.logSeek()}))).add(s.events.willPause$.subscribe((()=>{this.logPause({position:s.info.position$.getValue()})}))).add(s.events.willResume$.subscribe((()=>{this.logPlay()}))).add(s.events.managedError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.fatalError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.inited$.subscribe((()=>{this.logInited()}))).add(s.events.canplay$.subscribe((e=>{this.logReady({time:e})}))).add(s.events.firstBytes$.subscribe((e=>{this.logFirstBytes({time:e})}))).add(s.events.firstFrame$.subscribe((e=>{this.logFirstFrame({time:e})}))).add(s.events.watchCoverageRecord$.subscribe((e=>{this.logWatchCoverageRecord(e)}))).add(s.events.watchCoverageLive$.subscribe((e=>{this.logWatchCoverageLive(e)}))).add(s.info.isStalled$.subscribe((t=>{t?o=e.now():(e.isNonNullable(o)&&this.logEmptyBuffer({duration:e.now()-o}),o=void 0)}))).add(s.events.ended$.subscribe((()=>{const t=s.info.throughputEstimation$.getValue();e.isNonNullable(t)&&this.logDownloadSpeed({speed:t/8})}))).add(s.info.hostname$.subscribe((e=>{this.updateContext({cdnHostname:e})}))).add(s.info.httpConnectionType$.subscribe((e=>{this.updateContext({connectionType:E(e)})}))).add(s.info.httpConnectionReused$.subscribe((e=>{this.updateContext({connectionReused:e})}))).add(s.info.currentQuality$.subscribe((e=>{var s;this.updateContext({quality:(s=e,s&&{[t.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[t.VideoQuality.Q_144P]:exports.Quality.Q144P,[t.VideoQuality.Q_240P]:exports.Quality.Q240P,[t.VideoQuality.Q_360P]:exports.Quality.Q360P,[t.VideoQuality.Q_480P]:exports.Quality.Q480P,[t.VideoQuality.Q_720P]:exports.Quality.Q720P,[t.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[t.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[t.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[t.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[s])})}))).add(s.info.currentFormat$.subscribe((e=>{this.updateContext({contentType:P(e)})}))).add(s.info.chromecastState$.subscribe((e=>{this.updateContext({destination:e===t.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=b()}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 t=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${t}-${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 t=this.createLogItem(e);this.logger.log(t)}createLogItem({operation:e,param:t}){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:!0===this.statContext.connectionReused?p.YES:!1===this.statContext.connectionReused?p.NO:void 0,stat_type:!0===this.statContext.autoplay?u.AUTO:!1===this.statContext.autoplay?u.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==t&&(o.param=t);for(const e of this.fieldBlacklist)delete o[e];return{operation:e,timestamp:s,custom:o}}};
|
|
6
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var e=require('@vkontakte/videoplayer-shared/esnext.cjs.js'),t=require('@vkontakte/videoplayer-core/esnext.cjs.js');function s(e){return e&&'object'==typeof e&&'default'in e?e:{default:e}}var o=s(require('lodash/debounce.js'));const i=(()=>{try{const e=Date.now().toString(),t=window.localStorage;t.setItem(e,e);const s=t.getItem(e)===e;return t.removeItem(e),s?t:null}catch(e){return null}})();var r,n,a,h,u,d,p,c={get:e=>function(e){const t=i?i.getItem('_one-stat_'+e):null;if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}(e)||null,set(e,t){!function(e,t){try{i&&i.setItem('_one-stat_'+e,JSON.stringify(t))}catch(e){}}(e,t)},remove(e){!function(e){i&&i.removeItem('_one-stat_'+e)}(e)}};exports.ApiEnv=void 0,(r=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',r.VK_ALIAS='vk_alias',r.VIDEOTEST='videotest',r.TEST='test',r.AUTO='auto',exports.Quality=void 0,(n=exports.Quality||(exports.Quality={})).Q144P='144',n.Q240P='240',n.Q360P='360',n.Q480P='480',n.Q720P='720',n.Q1080P='1080',n.Q1440P='1440',n.Q2160P='2160',n.Q4320P='4320',n.UNKNOWN='unknown',exports.ScreenDestination=void 0,(a=exports.ScreenDestination||(exports.ScreenDestination={})).CHROMECAST='chromecast',a.APPLE_TV='appletv',a.PIP='pip',a.HEADPHONES='externalHeadphones',a.SCREEN='',exports.ContentType=void 0,(h=exports.ContentType||(exports.ContentType={})).MP4='mp4',h.DASH='dash',h.DASH_SEP='dash_sep',h.ONDEMAND_DASH='ondemand_dash',h.HLS='hls',h.ONDEMAND_HLS='ondemand_hls',h.WEBM='webm',h.RTMP='rtmp',h.UNKNOWN='unknown',function(e){e.AUTO='auto',e.MANUAL=''}(u||(u={})),exports.ConnectionType=void 0,(d=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',d.HTTP2='http2',d.HTTP3='http3',function(e){e[e.YES=1]='YES',e[e.NO=0]='NO'}(p||(p={}));const l={[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]:''},m={start:1e3,factor:1.5,max:3e5,random:.1};var f;!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'}(f||(f={}));class y{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new e.ValueSubject(!1);backoffTimeoutId;constructor(e){this.params=e;const t=c.get('uuid');t?this.uuid=String(t):(this.uuid=function(){const e='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),t=new Array(36);let s,o,i=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?t[o]='-':14===o?t[o]='4':(i<=2&&(i=33554432+16777216*Math.random()|0),s=15&i,i>>=4,t[o]=e[19===o?3&s|8:s]);return t.join('')}(),c.set('uuid',this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const t=this.createLogParams(e),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',t,s)||this.logRequest(e)}async logRequest(e){const t='log.externalLog',s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const i=async(e,r=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(t,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${t} error`,thrown:s});const o=s?.error_code;switch(o){case f.PARAM_SESSION_EXPIRED:case f.PARAM_SESSION_KEY:case f.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),r>0?i(e,r-1):void 0;case f.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),r>0?i(e,r-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${t} error`,data:s})}}};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:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:e.map((e=>({...e,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e.getExponentialDelay(this.consequentAuthErrors,m);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(e).catch((e=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:e}))).finally((()=>this.backoffTimeoutId=0))}),t))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(e.session_data.auth_token=this.authToken,e.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',e).then((e=>(e&&e.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:e}),this.sessionKey=e?.session_key??void 0,this.sessionKey))).catch((async e=>{this.sessionKey=void 0;const t=e?.error_code;switch(t){case f.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}t?this.params.error$.next({id:`Authorize#${t}`,message:'authorize error',data:e}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:e})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function g(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof e.Request&&!e.Request.prototype.hasOwnProperty('signal')||!e.AbortController}const A=g({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),T=A?function(e){'function'==typeof e&&(e={fetch:e});const{fetch:t,Request:s=t.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i=!1}=e;if(!g({fetch:t,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:i}))return{fetch:t,Request:r};let r=s;(r&&!r.prototype.hasOwnProperty('signal')||i)&&(r=function(e,t){let o;t&&t.signal&&(o=t.signal,delete t.signal);const i=new s(e,t);return o&&Object.defineProperty(i,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),i},r.prototype=s.prototype);const n=t;return{fetch:(e,t)=>{const s=r&&r.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(e){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const i=new Promise(((e,t)=>{s.addEventListener('abort',(()=>t(o)),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([i,n(e,t)])}return n(e,t)},Request:r}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,_=A?T.fetch:window.fetch;A?T.Request:window.Request;class S{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='),t=await _(e,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await t.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}catch(e){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:e}),l[exports.ApiEnv.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:t,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(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:e,params:t}})}return!1}async sendRequest(t,s,o){const i=e.now(),r=r=>{r instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(r.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:r}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:r,data:{method:t,params:s,sessionKey:o,time:e.now()-i}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),_(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:s,sessionKey:o})}).then((t=>{const s=0===Number(t.headers.get('content-length')),o=new Date(t.headers.get('date')??'').getTime(),n=e.now()-i;if(isFinite(o)&&this.timeSynchronisation.addServerTime(o,n),!s)return t.json().then((e=>Object.prototype.hasOwnProperty.call(e,'error_msg')?Promise.reject(e):e),r)}),r)}_prepareQueryParams(e){const t=new URLSearchParams({format:'JSON',method:e.method,application_key:this.apiKey});return void 0!==e.sessionKey&&t.append('session_key',e.sessionKey),Object.entries(e.queryParams).forEach((([e,s])=>t.append(e,'string'==typeof s?s:JSON.stringify(s)))),t}}class v{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=o.default((()=>{try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:String(e)??'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe((e=>{e&&this.debouncedFlush()}))}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){0!==this.requestQueue.length&&(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,t){const s=e-Date.now()-t/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const e=.2;this.offset=Math.round(e*s+(1-e)*this.offset)}}}const b=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),E=e=>e&&{[t.HttpConnectionType.HTTP1]:exports.ConnectionType.HTTP1,[t.HttpConnectionType.HTTP2]:exports.ConnectionType.HTTP2,[t.HttpConnectionType.QUIC]:exports.ConnectionType.HTTP3}[e],P=s=>{if(void 0!==s)switch(s){case t.VideoFormat.MPEG:return exports.ContentType.MP4;case t.VideoFormat.DASH:case t.VideoFormat.DASH_LIVE:return exports.ContentType.DASH;case t.VideoFormat.DASH_SEP:return exports.ContentType.DASH_SEP;case t.VideoFormat.DASH_ONDEMAND:return exports.ContentType.ONDEMAND_DASH;case t.VideoFormat.DASH_WEBM:case t.VideoFormat.DASH_LIVE_WEBM:return exports.ContentType.WEBM;case t.VideoFormat.HLS:case t.VideoFormat.HLS_LIVE:return exports.ContentType.HLS;case t.VideoFormat.HLS_ONDEMAND:return exports.ContentType.ONDEMAND_HLS;case t.VideoFormat.WEB_RTC_LIVE:return exports.ContentType.RTMP;default:return e.assertNever(s)}};exports.OneStat=class{api;logger;config;subscription=new e.Subscription;timeSynchronisation=new w;experimental;statContext;vsid=b();fieldBlacklist=[];constructor(t,s){this.statContext=t,this.config={...s.config??{},requestRetryCount:1};const o=new e.Subject;this.experimental={error$:o};const i=new S({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:l[s.apiEnv],apiEnv:s.apiEnv,error$:o,timeSynchronisation:this.timeSynchronisation});this.api=new y({apiTransport:i,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new v({api:this.api,error$:o}),this.subscription.add(e.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(s){let o;return(new e.Subscription).add(s.events.started$.subscribe((()=>{this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.looped$.subscribe((()=>{this.resetViewSession(),this.logStarted({position:s.info.position$.getValue()})}))).add(s.events.seeked$.subscribe((()=>{this.logSeek()}))).add(s.events.willPause$.subscribe((()=>{this.logPause({position:s.info.position$.getValue()})}))).add(s.events.willResume$.subscribe((()=>{this.logPlay()}))).add(s.events.managedError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.fatalError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(s.events.inited$.subscribe((()=>{this.logInited()}))).add(s.events.canplay$.subscribe((e=>{this.logReady({time:e})}))).add(s.events.firstBytes$.subscribe((e=>{this.logFirstBytes({time:e})}))).add(s.events.firstFrame$.subscribe((e=>{this.logFirstFrame({time:e})}))).add(s.events.watchCoverageRecord$.subscribe((e=>{this.logWatchCoverageRecord(e)}))).add(s.events.watchCoverageLive$.subscribe((e=>{this.logWatchCoverageLive(e)}))).add(s.info.isStalled$.subscribe((t=>{t?o=e.now():(e.isNonNullable(o)&&this.logEmptyBuffer({duration:e.now()-o}),o=void 0)}))).add(s.events.ended$.subscribe((()=>{const t=s.info.throughputEstimation$.getValue();e.isNonNullable(t)&&this.logDownloadSpeed({speed:t/8})}))).add(s.info.hostname$.subscribe((e=>{this.updateContext({cdnHostname:e})}))).add(s.info.httpConnectionType$.subscribe((e=>{this.updateContext({connectionType:E(e)})}))).add(s.info.httpConnectionReused$.subscribe((e=>{this.updateContext({connectionReused:e})}))).add(s.info.currentQuality$.subscribe((e=>{var s;this.updateContext({quality:(s=e,s&&{[t.VideoQuality.INVARIANT]:exports.Quality.UNKNOWN,[t.VideoQuality.Q_144P]:exports.Quality.Q144P,[t.VideoQuality.Q_240P]:exports.Quality.Q240P,[t.VideoQuality.Q_360P]:exports.Quality.Q360P,[t.VideoQuality.Q_480P]:exports.Quality.Q480P,[t.VideoQuality.Q_720P]:exports.Quality.Q720P,[t.VideoQuality.Q_1080P]:exports.Quality.Q1080P,[t.VideoQuality.Q_1440P]:exports.Quality.Q1440P,[t.VideoQuality.Q_2160P]:exports.Quality.Q2160P,[t.VideoQuality.Q_4320P]:exports.Quality.Q4320P}[s])})}))).add(s.info.currentFormat$.subscribe((e=>{this.updateContext({contentType:P(e)})}))).add(s.info.chromecastState$.subscribe((e=>{this.updateContext({destination:e===t.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=b()}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 t=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${t}-${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 t=this.createLogItem(e);this.logger.log(t)}createLogItem({operation:e,param:t}){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:!0===this.statContext.connectionReused?p.YES:!1===this.statContext.connectionReused?p.NO:void 0,stat_type:!0===this.statContext.autoplay?u.AUTO:!1===this.statContext.autoplay?u.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==t&&(o.param=t);for(const e of this.fieldBlacklist)delete o[e];return{operation:e,timestamp:s,custom:o}}};
|
package/esnext.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.28
|
|
3
|
+
* Fri, 09 Dec 2022 14:28:31 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-28/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as e,getExponentialDelay as t,now as s,assertNever as o,Subscription as r,Subject as i,fromEvent as a,merge as n,isNonNullable as h}from'@vkontakte/videoplayer-shared/esnext.esm.js';import{VideoQuality as u,HttpConnectionType as d,VideoFormat as c,ChromecastState as l}from'@vkontakte/videoplayer-core/esnext.esm.js';import p from'lodash/debounce.js';const m=(()=>{try{const e=Date.now().toString(),t=window.localStorage;t.setItem(e,e);const s=t.getItem(e)===e;return t.removeItem(e),s?t:null}catch(e){return null}})();var f,g,y,A,_,w,S,b={get:e=>function(e){const t=m?m.getItem('_one-stat_'+e):null;if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}(e)||null,set(e,t){!function(e,t){try{m&&m.setItem('_one-stat_'+e,JSON.stringify(t))}catch(e){}}(e,t)},remove(e){!function(e){m&&m.removeItem('_one-stat_'+e)}(e)}};!function(e){e.PROD='prod',e.VK_ALIAS='vk_alias',e.VIDEOTEST='videotest',e.TEST='test',e.AUTO='auto'}(f||(f={})),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'}(g||(g={})),function(e){e.CHROMECAST='chromecast',e.APPLE_TV='appletv',e.PIP='pip',e.HEADPHONES='externalHeadphones',e.SCREEN=''}(y||(y={})),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'}(A||(A={})),function(e){e.AUTO='auto',e.MANUAL=''}(_||(_={})),function(e){e.HTTP1='http1',e.HTTP2='http2',e.HTTP3='http3'}(w||(w={})),function(e){e[e.YES=1]='YES',e[e.NO=0]='NO'}(S||(S={}));const P={[f.PROD]:'https://api.ok.ru',[f.VK_ALIAS]:'https://api.mycdn.me',[f.VIDEOTEST]:'https://videotestapi.ok.ru/api',[f.TEST]:'https://apitest.ok.ru',[f.AUTO]:''},T={start:1e3,factor:1.5,max:3e5,random:.1};var v;!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'}(v||(v={}));class E{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new e(!1);backoffTimeoutId;constructor(e){this.params=e;const t=b.get('uuid');t?this.uuid=String(t):(this.uuid=function(){const e='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),t=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?t[o]='-':14===o?t[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,t[o]=e[19===o?3&s|8:s]);return t.join('')}(),b.set('uuid',this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const t=this.createLogParams(e),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',t,s)||this.logRequest(e)}async logRequest(e){const t='log.externalLog',s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(e,i=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(t,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${t} error`,thrown:s});const o=s?.error_code;switch(o){case v.PARAM_SESSION_EXPIRED:case v.PARAM_SESSION_KEY:case v.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;case v.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${t} error`,data:s})}}};return r(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:'@vkontakte/videoplayer-statistics:1.0.27',platform:'WEB',items:e.map((e=>({...e,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t(this.consequentAuthErrors,T);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(t).catch((e=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:e}))).finally((()=>this.backoffTimeoutId=0))}),e))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e={session_data:{version:2,device_id:this.uuid,client_version:'1.0.27'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(e.session_data.auth_token=this.authToken,e.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',e).then((e=>(e&&e.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:e}),this.sessionKey=e?.session_key??void 0,this.sessionKey))).catch((async e=>{this.sessionKey=void 0;const t=e?.error_code;switch(t){case v.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}t?this.params.error$.next({id:`Authorize#${t}`,message:'authorize error',data:e}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:e})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function R(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof e.Request&&!e.Request.prototype.hasOwnProperty('signal')||!e.AbortController}const k=R({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),O=k?function(e){'function'==typeof e&&(e={fetch:e});const{fetch:t,Request:s=t.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=e;if(!R({fetch:t,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(e,t){let o;t&&t.signal&&(o=t.signal,delete t.signal);const r=new s(e,t);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=t;return{fetch:(e,t)=>{const s=i&&i.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(e){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const r=new Promise(((e,t)=>{s.addEventListener('abort',(()=>t(o)),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([r,a(e,t)])}return a(e,t)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,C=k?O.fetch:window.fetch;k?O.Request:window.Request;class L{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!==f.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),t=await C(e,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await t.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}catch(e){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:e}),P[f.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:t,sessionKey:s}),r=new window.Blob([o.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,r)}catch(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:e,params:t}})}return!1}async sendRequest(e,t,o){const r=s(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:e,params:t,sessionKey:o,time:s()-r}})};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:t,sessionKey:o})}).then((e=>{const t=0===Number(e.headers.get('content-length')),o=new Date(e.headers.get('date')??'').getTime(),a=s()-r;if(isFinite(o)&&this.timeSynchronisation.addServerTime(o,a),t)return e.json().then((e=>Object.prototype.hasOwnProperty.call(e,'error_msg')?Promise.reject(e):e),i)}),i)}_prepareQueryParams(e){const t=new URLSearchParams({format:'JSON',method:e.method,application_key:this.apiKey});return void 0!==e.sessionKey&&t.append('session_key',e.sessionKey),Object.entries(e.queryParams).forEach((([e,s])=>t.append(e,'string'==typeof s?s:JSON.stringify(s)))),t}}class N{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=p((()=>{try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:String(e)??'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe((e=>{e&&this.debouncedFlush()}))}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){0!==this.requestQueue.length&&(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 I{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,t){const s=e-Date.now()-t/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const e=.2;this.offset=Math.round(e*s+(1-e)*this.offset)}}}const $=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),x=e=>e&&{[d.HTTP1]:w.HTTP1,[d.HTTP2]:w.HTTP2,[d.QUIC]:w.HTTP3}[e],B=e=>{if(void 0!==e)switch(e){case c.MPEG:return A.MP4;case c.DASH:case c.DASH_LIVE:return A.DASH;case c.DASH_SEP:return A.DASH_SEP;case c.DASH_ONDEMAND:return A.ONDEMAND_DASH;case c.DASH_WEBM:case c.DASH_LIVE_WEBM:return A.WEBM;case c.HLS:case c.HLS_LIVE:return A.HLS;case c.HLS_ONDEMAND:return A.ONDEMAND_HLS;case c.WEB_RTC_LIVE:return A.RTMP;default:return o(e)}};class q{api;logger;config;subscription=new r;timeSynchronisation=new I;experimental;statContext;vsid=$();fieldBlacklist=[];constructor(e,t){this.statContext=e,this.config={...t.config??{},requestRetryCount:1};const s=new i;this.experimental={error$:s};const o=new L({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:P[t.apiEnv],apiEnv:t.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new E({apiTransport:o,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new N({api:this.api,error$:s}),this.subscription.add(a(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let t;return(new r).add(n(e.events.started$,e.events.looped$).subscribe((()=>{this.logStarted({position:e.info.position$.getValue()})}))).add(e.events.looped$.subscribe((()=>{this.resetViewSession()}))).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:e})=>{this.logError({errorType:e})}))).add(e.events.fatalError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(e.events.inited$.subscribe((()=>{this.logInited()}))).add(e.events.canplay$.subscribe((e=>{this.logReady({time:e})}))).add(e.events.firstBytes$.subscribe((e=>{this.logFirstBytes({time:e})}))).add(e.events.firstFrame$.subscribe((e=>{this.logFirstFrame({time:e})}))).add(e.events.watchCoverageRecord$.subscribe((e=>{this.logWatchCoverageRecord(e)}))).add(e.events.watchCoverageLive$.subscribe((e=>{this.logWatchCoverageLive(e)}))).add(e.info.isStalled$.subscribe((e=>{e?t=s():(h(t)&&this.logEmptyBuffer({duration:s()-t}),t=void 0)}))).add(e.events.ended$.subscribe((()=>{const t=e.info.throughputEstimation$.getValue();h(t)&&this.logDownloadSpeed({speed:t/8})}))).add(e.info.hostname$.subscribe((e=>{this.updateContext({cdnHostname:e})}))).add(e.info.httpConnectionType$.subscribe((e=>{this.updateContext({connectionType:x(e)})}))).add(e.info.httpConnectionReused$.subscribe((e=>{this.updateContext({connectionReused:e})}))).add(e.info.currentQuality$.subscribe((e=>{var t;this.updateContext({quality:(t=e,t&&{[u.INVARIANT]:g.UNKNOWN,[u.Q_144P]:g.Q144P,[u.Q_240P]:g.Q240P,[u.Q_360P]:g.Q360P,[u.Q_480P]:g.Q480P,[u.Q_720P]:g.Q720P,[u.Q_1080P]:g.Q1080P,[u.Q_1440P]:g.Q1440P,[u.Q_2160P]:g.Q2160P,[u.Q_4320P]:g.Q4320P}[t])})}))).add(e.info.currentFormat$.subscribe((e=>{this.updateContext({contentType:B(e)})}))).add(e.info.chromecastState$.subscribe((e=>{this.updateContext({destination:e===l.CONNECTED?y.CHROMECAST:y.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 t=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${t}-${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 t=this.createLogItem(e);this.logger.log(t)}createLogItem({operation:e,param:t}){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:!0===this.statContext.connectionReused?S.YES:!1===this.statContext.connectionReused?S.NO:void 0,stat_type:!0===this.statContext.autoplay?_.AUTO:!1===this.statContext.autoplay?_.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==t&&(o.param=t);for(const e of this.fieldBlacklist)delete o[e];return{operation:e,timestamp:s,custom:o}}}export{f as ApiEnv,w as ConnectionType,A as ContentType,q as OneStat,g as Quality,y as ScreenDestination};
|
|
6
|
+
import{ValueSubject as e,getExponentialDelay as t,now as s,assertNever as o,Subscription as r,Subject as i,fromEvent as a,isNonNullable as n}from'@vkontakte/videoplayer-shared/esnext.esm.js';import{VideoQuality as h,HttpConnectionType as u,VideoFormat as d,ChromecastState as c}from'@vkontakte/videoplayer-core/esnext.esm.js';import l from'lodash/debounce.js';const p=(()=>{try{const e=Date.now().toString(),t=window.localStorage;t.setItem(e,e);const s=t.getItem(e)===e;return t.removeItem(e),s?t:null}catch(e){return null}})();var m,f,g,y,A,_,S,w={get:e=>function(e){const t=p?p.getItem('_one-stat_'+e):null;if(null===t)return null;try{return JSON.parse(t)}catch(e){return null}}(e)||null,set(e,t){!function(e,t){try{p&&p.setItem('_one-stat_'+e,JSON.stringify(t))}catch(e){}}(e,t)},remove(e){!function(e){p&&p.removeItem('_one-stat_'+e)}(e)}};!function(e){e.PROD='prod',e.VK_ALIAS='vk_alias',e.VIDEOTEST='videotest',e.TEST='test',e.AUTO='auto'}(m||(m={})),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'}(f||(f={})),function(e){e.CHROMECAST='chromecast',e.APPLE_TV='appletv',e.PIP='pip',e.HEADPHONES='externalHeadphones',e.SCREEN=''}(g||(g={})),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'}(y||(y={})),function(e){e.AUTO='auto',e.MANUAL=''}(A||(A={})),function(e){e.HTTP1='http1',e.HTTP2='http2',e.HTTP3='http3'}(_||(_={})),function(e){e[e.YES=1]='YES',e[e.NO=0]='NO'}(S||(S={}));const b={[m.PROD]:'https://api.ok.ru',[m.VK_ALIAS]:'https://api.mycdn.me',[m.VIDEOTEST]:'https://videotestapi.ok.ru/api',[m.TEST]:'https://apitest.ok.ru',[m.AUTO]:''},P={start:1e3,factor:1.5,max:3e5,random:.1};var T;!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'}(T||(T={}));class v{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new e(!1);backoffTimeoutId;constructor(e){this.params=e;const t=w.get('uuid');t?this.uuid=String(t):(this.uuid=function(){const e='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),t=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?t[o]='-':14===o?t[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,t[o]=e[19===o?3&s|8:s]);return t.join('')}(),w.set('uuid',this.uuid))}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){const t=this.createLogParams(e),s=this.sessionKey;if(!s)return;this.params.apiTransport.sendBeacon('log.externalLog',t,s)||this.logRequest(e)}async logRequest(e){const t='log.externalLog',s=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(e,i=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(t,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${t} error`,thrown:s});const o=s?.error_code;switch(o){case T.PARAM_SESSION_EXPIRED:case T.PARAM_SESSION_KEY:case T.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;case T.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(e,i-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${t} error`,data:s})}}};return r(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:'@vkontakte/videoplayer-statistics:1.0.28',platform:'WEB',items:e.map((e=>({...e,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t(this.consequentAuthErrors,P);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{this._authorize().then(t).catch((e=>this.params.error$.next({id:'AuthorizeBackoff',message:'Otherwise unhandle errror in authrization',thrown:e}))).finally((()=>this.backoffTimeoutId=0))}),e))}))}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const e={session_data:{version:2,device_id:this.uuid,client_version:'1.0.28'.split('-')[0],client_type:'SDK_JS'}};return void 0!==this.authToken&&(e.session_data.auth_token=this.authToken,e.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest('auth.anonymLogin',e).then((e=>(e&&e.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:e}),this.sessionKey=e?.session_key??void 0,this.sessionKey))).catch((async e=>{this.sessionKey=void 0;const t=e?.error_code;switch(t){case T.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}t?this.params.error$.next({id:`Authorize#${t}`,message:'authorize error',data:e}):this.params.error$.next({id:'AuthorizeUnknown',message:'authorize error',thrown:e})})).finally((()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(void 0!==this.sessionKey)})),this.authorizePromise}}function E(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'),!0):'function'==typeof e.Request&&!e.Request.prototype.hasOwnProperty('signal')||!e.AbortController}const R=E({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),k=R?function(e){'function'==typeof e&&(e={fetch:e});const{fetch:t,Request:s=t.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=e;if(!E({fetch:t,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:t,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(e,t){let o;t&&t.signal&&(o=t.signal,delete t.signal);const r=new s(e,t);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=t;return{fetch:(e,t)=>{const s=i&&i.prototype.isPrototypeOf(e)?e.signal:t?t.signal:void 0;if(s){let o;try{o=new DOMException('Aborted','AbortError')}catch(e){o=new Error('Aborted'),o.name='AbortError'}if(s.aborted)return Promise.reject(o);const r=new Promise(((e,t)=>{s.addEventListener('abort',(()=>t(o)),{once:!0})}));return t&&t.signal&&delete t.signal,Promise.race([r,a(e,t)])}return a(e,t)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,O=R?k.fetch:window.fetch;R?k.Request:window.Request;class C{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!==m.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),t=await O(e,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await t.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}catch(e){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:e}),b[m.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:e,queryParams:t,sessionKey:s}),r=new window.Blob([o.toString()],{type:'application/x-www-form-urlencoded'});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,r)}catch(s){this.params.error$.next({id:'OneStat:ApiTransport:sendBeacon',message:'Unhandled beacon error',thrown:s,data:{method:e,params:t}})}return!1}async sendRequest(e,t,o){const r=s(),i=i=>{i instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(i.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:i}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:i,data:{method:e,params:t,sessionKey:o,time:s()-r}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),O(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:e,queryParams:t,sessionKey:o})}).then((e=>{const t=0===Number(e.headers.get('content-length')),o=new Date(e.headers.get('date')??'').getTime(),a=s()-r;if(isFinite(o)&&this.timeSynchronisation.addServerTime(o,a),!t)return e.json().then((e=>Object.prototype.hasOwnProperty.call(e,'error_msg')?Promise.reject(e):e),i)}),i)}_prepareQueryParams(e){const t=new URLSearchParams({format:'JSON',method:e.method,application_key:this.apiKey});return void 0!==e.sessionKey&&t.append('session_key',e.sessionKey),Object.entries(e.queryParams).forEach((([e,s])=>t.append(e,'string'==typeof s?s:JSON.stringify(s)))),t}}class L{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=l((()=>{try{this.flush()}catch(e){this.error$.next({id:'LoggerError',message:String(e)??'Unknown logger error',thrown:e})}}),3e3,{maxWait:15e3});constructor(e){this.api=e.api,this.error$=e.error$,this.subscription=this.api.authorized$.subscribe((e=>{e&&this.debouncedFlush()}))}log(e){this.requestQueue.push(e),this.isPaused||this.debouncedFlush()}flush(e=!1){0!==this.requestQueue.length&&(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 N{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,t){const s=e-Date.now()-t/2;if(Math.abs(s)<1e3)this.offset=0;else if(void 0===this.offset)this.offset=Math.round(s);else{const e=.2;this.offset=Math.round(e*s+(1-e)*this.offset)}}}const I=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0'),$=e=>e&&{[u.HTTP1]:_.HTTP1,[u.HTTP2]:_.HTTP2,[u.QUIC]:_.HTTP3}[e],x=e=>{if(void 0!==e)switch(e){case d.MPEG:return y.MP4;case d.DASH:case d.DASH_LIVE:return y.DASH;case d.DASH_SEP:return y.DASH_SEP;case d.DASH_ONDEMAND:return y.ONDEMAND_DASH;case d.DASH_WEBM:case d.DASH_LIVE_WEBM:return y.WEBM;case d.HLS:case d.HLS_LIVE:return y.HLS;case d.HLS_ONDEMAND:return y.ONDEMAND_HLS;case d.WEB_RTC_LIVE:return y.RTMP;default:return o(e)}};class B{api;logger;config;subscription=new r;timeSynchronisation=new N;experimental;statContext;vsid=I();fieldBlacklist=[];constructor(e,t){this.statContext=e,this.config={...t.config??{},requestRetryCount:1};const s=new i;this.experimental={error$:s};const o=new C({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:b[t.apiEnv],apiEnv:t.apiEnv,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new v({apiTransport:o,refreshAuthToken:t.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new L({api:this.api,error$:s}),this.subscription.add(a(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let t;return(new r).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:e})=>{this.logError({errorType:e})}))).add(e.events.fatalError$.subscribe((({id:e})=>{this.logError({errorType:e})}))).add(e.events.inited$.subscribe((()=>{this.logInited()}))).add(e.events.canplay$.subscribe((e=>{this.logReady({time:e})}))).add(e.events.firstBytes$.subscribe((e=>{this.logFirstBytes({time:e})}))).add(e.events.firstFrame$.subscribe((e=>{this.logFirstFrame({time:e})}))).add(e.events.watchCoverageRecord$.subscribe((e=>{this.logWatchCoverageRecord(e)}))).add(e.events.watchCoverageLive$.subscribe((e=>{this.logWatchCoverageLive(e)}))).add(e.info.isStalled$.subscribe((e=>{e?t=s():(n(t)&&this.logEmptyBuffer({duration:s()-t}),t=void 0)}))).add(e.events.ended$.subscribe((()=>{const t=e.info.throughputEstimation$.getValue();n(t)&&this.logDownloadSpeed({speed:t/8})}))).add(e.info.hostname$.subscribe((e=>{this.updateContext({cdnHostname:e})}))).add(e.info.httpConnectionType$.subscribe((e=>{this.updateContext({connectionType:$(e)})}))).add(e.info.httpConnectionReused$.subscribe((e=>{this.updateContext({connectionReused:e})}))).add(e.info.currentQuality$.subscribe((e=>{var t;this.updateContext({quality:(t=e,t&&{[h.INVARIANT]:f.UNKNOWN,[h.Q_144P]:f.Q144P,[h.Q_240P]:f.Q240P,[h.Q_360P]:f.Q360P,[h.Q_480P]:f.Q480P,[h.Q_720P]:f.Q720P,[h.Q_1080P]:f.Q1080P,[h.Q_1440P]:f.Q1440P,[h.Q_2160P]:f.Q2160P,[h.Q_4320P]:f.Q4320P}[t])})}))).add(e.info.currentFormat$.subscribe((e=>{this.updateContext({contentType:x(e)})}))).add(e.info.chromecastState$.subscribe((e=>{this.updateContext({destination:e===c.CONNECTED?g.CHROMECAST:g.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=I()}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 t=e.start+this.timeSynchronisation.getOffset(),s=e.end+this.timeSynchronisation.getOffset();this.log({operation:'watch_coverage_live',param:`${t}-${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 t=this.createLogItem(e);this.logger.log(t)}createLogItem({operation:e,param:t}){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:!0===this.statContext.connectionReused?S.YES:!1===this.statContext.connectionReused?S.NO:void 0,stat_type:!0===this.statContext.autoplay?A.AUTO:!1===this.statContext.autoplay?A.MANUAL:void 0,vk_playlist_id:this.statContext.vkPlaylistId,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode};void 0!==t&&(o.param=t);for(const e of this.fieldBlacklist)delete o[e];return{operation:e,timestamp:s,custom:o}}}export{m as ApiEnv,_ as ConnectionType,y as ContentType,B as OneStat,f as Quality,g as ScreenDestination};
|