@vkontakte/videoplayer-statistics 1.0.26 → 1.0.27-beta.0
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/ApiTransport.d.ts +3 -0
- package/OneStat.d.ts +6 -2
- 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 +4 -1
- package/utils/coreMappers.d.ts +5 -0
- package/utils/timeSynchronisation.d.ts +10 -0
package/ApiTransport.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { IError, ISubject } from '@vkontakte/videoplayer-shared';
|
|
2
2
|
import { ApiEnv } from './types';
|
|
3
|
+
import type { TimeSynchronisation } from './utils/timeSynchronisation';
|
|
3
4
|
export interface IApiTransportParams {
|
|
4
5
|
apiKey: string;
|
|
5
6
|
apiBaseUrl: string;
|
|
6
7
|
apiEnv: ApiEnv;
|
|
7
8
|
error$: ISubject<IError>;
|
|
9
|
+
timeSynchronisation: TimeSynchronisation;
|
|
8
10
|
}
|
|
9
11
|
export interface IApiTransport {
|
|
10
12
|
sendBeacon(method: string, params: Record<string, unknown>, sessionKey?: string): boolean;
|
|
@@ -14,6 +16,7 @@ export default class ApiTransport implements IApiTransport {
|
|
|
14
16
|
private apiKey;
|
|
15
17
|
private apiBaseUrl;
|
|
16
18
|
private apiEnv;
|
|
19
|
+
private timeSynchronisation;
|
|
17
20
|
private isApiBaseUrlFetched;
|
|
18
21
|
private params;
|
|
19
22
|
constructor(params: IApiTransportParams);
|
package/OneStat.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IError, IObservable, Milliseconds, Seconds } from '@vkontakte/videoplayer-shared';
|
|
1
|
+
import { IError, IObservable, ISubscription, Milliseconds, Seconds } from '@vkontakte/videoplayer-shared';
|
|
2
|
+
import type { IPlayer } from '@vkontakte/videoplayer-core';
|
|
2
3
|
import { ILogCustomData } from './Api';
|
|
3
4
|
import { ApiEnv, ConnectionType, ContentType, Quality, ScreenDestination } from './types';
|
|
4
5
|
export interface IOneStat {
|
|
@@ -13,6 +14,7 @@ export interface IOneStat {
|
|
|
13
14
|
* Обновляет общие параметры событий
|
|
14
15
|
*/
|
|
15
16
|
updateContext(context: Partial<IStatContext>): void;
|
|
17
|
+
attachTo(player: IPlayer): ISubscription;
|
|
16
18
|
/**
|
|
17
19
|
* Ставит отправку событий на паузу. Они будут накапливаться до вызова `resume()`
|
|
18
20
|
*/
|
|
@@ -185,6 +187,7 @@ export declare class OneStat implements IOneStat {
|
|
|
185
187
|
private logger;
|
|
186
188
|
private config;
|
|
187
189
|
private subscription;
|
|
190
|
+
private timeSynchronisation;
|
|
188
191
|
experimental: {
|
|
189
192
|
error$: IObservable<IError>;
|
|
190
193
|
};
|
|
@@ -193,6 +196,7 @@ export declare class OneStat implements IOneStat {
|
|
|
193
196
|
private fieldBlacklist;
|
|
194
197
|
constructor(statContext: IStatContext, params: IConstructorParams);
|
|
195
198
|
updateContext(newContext: Partial<IStatContext>): void;
|
|
199
|
+
attachTo(player: IPlayer): ISubscription;
|
|
196
200
|
authorize(authToken?: string): Promise<unknown>;
|
|
197
201
|
pause(): void;
|
|
198
202
|
resume(): void;
|
|
@@ -220,5 +224,5 @@ export declare class OneStat implements IOneStat {
|
|
|
220
224
|
logAdSkipped(): void;
|
|
221
225
|
logAdClicked(): void;
|
|
222
226
|
private log;
|
|
223
|
-
private
|
|
227
|
+
private createLogItem;
|
|
224
228
|
}
|
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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/es2015.cjs.js');function e(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var r=e(require('lodash/debounce.js'));function n(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 o='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},i=function(t){return t&&t.Math==Math&&t},s=i('object'==typeof globalThis&&globalThis)||i('object'==typeof window&&window)||i('object'==typeof self&&self)||i('object'==typeof o&&o)||function(){return this}()||Function('return this')(),a=function(t){try{return!!t()}catch(t){return!0}},u=!a((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),c=u,h=Function.prototype,l=h.apply,f=h.call,p='object'==typeof Reflect&&Reflect.apply||(c?f.bind(l):function(){return f.apply(l,arguments)}),d=u,v=Function.prototype,y=v.bind,m=v.call,g=d&&y.bind(m,m),b=d?function(t){return t&&g(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},w=function(t){return'function'==typeof t},A={},T=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),S=u,E=Function.prototype.call,_=S?E.bind(E):function(){return E.apply(E,arguments)},O={},P={}.propertyIsEnumerable,R=Object.getOwnPropertyDescriptor,x=R&&!P.call({1:2},1);O.f=x?function(t){var e=R(this,t);return!!e&&e.enumerable}:P;var j,k,C=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},I=b,N=I({}.toString),L=I(''.slice),q=function(t){return L(N(t),8,-1)},U=a,B=q,M=Object,z=b(''.split),D=U((function(){return!M('z').propertyIsEnumerable(0)}))?function(t){return'String'==B(t)?z(t,''):M(t)}:M,F=TypeError,$=function(t){if(null==t)throw F('Can\'t call method on '+t);return t},K=D,Q=$,H=w,W=function(t){return'object'==typeof t?null!==t:H(t)},G={},V=G,Y=s,J=w,Z=function(t){return J(t)?t:void 0},X=function(t,e){return arguments.length<2?Z(V[t])||Z(Y[t]):V[t]&&V[t][e]||Y[t]&&Y[t][e]},tt=b({}.isPrototypeOf),et=X('navigator','userAgent')||'',rt=s,nt=et,ot=rt.process,it=rt.Deno,st=ot&&ot.versions||it&&it.version,at=st&&st.v8;at&&(k=(j=at.split('.'))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!k&&nt&&(!(j=nt.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=nt.match(/Chrome\/(\d+)/))&&(k=+j[1]);var ut=k,ct=ut,ht=a,lt=!!Object.getOwnPropertySymbols&&!ht((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&ct&&ct<41})),ft=lt&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,pt=X,dt=w,vt=tt,yt=Object,mt=ft?function(t){return'symbol'==typeof t}:function(t){var e=pt('Symbol');return dt(e)&&vt(e.prototype,yt(t))},gt=String,bt=function(t){try{return gt(t)}catch(t){return'Object'}},wt=w,At=bt,Tt=TypeError,St=function(t){if(wt(t))return t;throw Tt(At(t)+' is not a function')},Et=St,_t=function(t,e){var r=t[e];return null==r?void 0:Et(r)},Ot=_,Pt=w,Rt=W,xt=TypeError,jt={exports:{}},kt=s,Ct=Object.defineProperty,It=function(t,e){try{Ct(kt,t,{value:e,configurable:!0,writable:!0})}catch(r){kt[t]=e}return e},Nt=s['__core-js_shared__']||It('__core-js_shared__',{}),Lt=Nt;(jt.exports=function(t,e){return Lt[t]||(Lt[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 qt=$,Ut=Object,Bt=function(t){return Ut(qt(t))},Mt=b({}.hasOwnProperty),zt=Object.hasOwn||function(t,e){return Mt(Bt(t),e)},Dt=b,Ft=0,$t=Math.random(),Kt=Dt(1..toString),Qt=function(t){return'Symbol('+(void 0===t?'':t)+')_'+Kt(++Ft+$t,36)},Ht=s,Wt=jt.exports,Gt=zt,Vt=Qt,Yt=lt,Jt=ft,Zt=Wt('wks'),Xt=Ht.Symbol,te=Xt&&Xt.for,ee=Jt?Xt:Xt&&Xt.withoutSetter||Vt,re=function(t){if(!Gt(Zt,t)||!Yt&&'string'!=typeof Zt[t]){var e='Symbol.'+t;Yt&&Gt(Xt,t)?Zt[t]=Xt[t]:Zt[t]=Jt&&te?te(e):ee(e)}return Zt[t]},ne=_,oe=W,ie=mt,se=_t,ae=function(t,e){var r,n;if('string'===e&&Pt(r=t.toString)&&!Rt(n=Ot(r,t)))return n;if(Pt(r=t.valueOf)&&!Rt(n=Ot(r,t)))return n;if('string'!==e&&Pt(r=t.toString)&&!Rt(n=Ot(r,t)))return n;throw xt('Can\'t convert object to primitive value')},ue=TypeError,ce=re('toPrimitive'),he=function(t,e){if(!oe(t)||ie(t))return t;var r,n=se(t,ce);if(n){if(void 0===e&&(e='default'),r=ne(n,t,e),!oe(r)||ie(r))return r;throw ue('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),ae(t,e)},le=mt,fe=function(t){var e=he(t,'string');return le(e)?e:e+''},pe=W,de=s.document,ve=pe(de)&&pe(de.createElement),ye=function(t){return ve?de.createElement(t):{}},me=ye,ge=!T&&!a((function(){return 7!=Object.defineProperty(me('div'),'a',{get:function(){return 7}}).a})),be=T,we=_,Ae=O,Te=C,Se=function(t){return K(Q(t))},Ee=fe,_e=zt,Oe=ge,Pe=Object.getOwnPropertyDescriptor;A.f=be?Pe:function(t,e){if(t=Se(t),e=Ee(e),Oe)try{return Pe(t,e)}catch(t){}if(_e(t,e))return Te(!we(Ae.f,t,e),t[e])};var Re=a,xe=w,je=/#|\.prototype\./,ke=function(t,e){var r=Ie[Ce(t)];return r==Le||r!=Ne&&(xe(e)?Re(e):!!e)},Ce=ke.normalize=function(t){return String(t).replace(je,'.').toLowerCase()},Ie=ke.data={},Ne=ke.NATIVE='N',Le=ke.POLYFILL='P',qe=ke,Ue=St,Be=u,Me=b(b.bind),ze=function(t,e){return Ue(t),void 0===e?t:Be?Me(t,e):function(){return t.apply(e,arguments)}},De={},Fe=T&&a((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),$e=W,Ke=String,Qe=TypeError,He=function(t){if($e(t))return t;throw Qe(Ke(t)+' is not an object')},We=T,Ge=ge,Ve=Fe,Ye=He,Je=fe,Ze=TypeError,Xe=Object.defineProperty,tr=Object.getOwnPropertyDescriptor;De.f=We?Ve?function(t,e,r){if(Ye(t),e=Je(e),Ye(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var n=tr(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 Xe(t,e,r)}:Xe:function(t,e,r){if(Ye(t),e=Je(e),Ye(r),Ge)try{return Xe(t,e,r)}catch(t){}if('get'in r||'set'in r)throw Ze('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var er=De,rr=C,nr=T?function(t,e,r){return er.f(t,e,rr(1,r))}:function(t,e,r){return t[e]=r,t},or=s,ir=p,sr=b,ar=w,ur=A.f,cr=qe,hr=G,lr=ze,fr=nr,pr=zt,dr=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 ir(t,this,arguments)};return e.prototype=t.prototype,e},vr=function(t,e){var r,n,o,i,s,a,u,c,h=t.target,l=t.global,f=t.stat,p=t.proto,d=l?or:f?or[h]:(or[h]||{}).prototype,v=l?hr:hr[h]||fr(hr,h,{})[h],y=v.prototype;for(o in e)r=!cr(l?o:h+(f?'.':'#')+o,t.forced)&&d&&pr(d,o),s=v[o],r&&(a=t.dontCallGetSet?(c=ur(d,o))&&c.value:d[o]),i=r&&a?a:e[o],r&&typeof s==typeof i||(u=t.bind&&r?lr(i,or):t.wrap&&r?dr(i):p&&ar(i)?sr(i):i,(t.sham||i&&i.sham||s&&s.sham)&&fr(u,'sham',!0),fr(v,o,u),p&&(pr(hr,n=h+'Prototype')||fr(hr,n,{}),fr(hr[n],o,i),t.real&&y&&!y[o]&&fr(y,o,i)))},yr='process'==q(s.process),mr=nr,gr=(TypeError,b);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=gr(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var br={};br[re('toStringTag')]='z';var wr='[object z]'===String(br),Ar=wr,Tr=w,Sr=q,Er=re('toStringTag'),_r=Object,Or='Arguments'==Sr(function(){return arguments}()),Pr=Ar?Sr: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),Er))?r:Or?Sr(e):'Object'==(n=Sr(e))&&Tr(e.callee)?'Arguments':n},Rr=Pr,xr=wr?{}.toString:function(){return'[object '+Rr(this)+']'},jr=wr,kr=De.f,Cr=nr,Ir=zt,Nr=xr,Lr=re('toStringTag'),qr=X,Ur=De,Br=T,Mr=re('species'),zr=tt,Dr=TypeError,Fr=w,$r=Nt,Kr=b(Function.toString);Fr($r.inspectSource)||($r.inspectSource=function(t){return Kr(t)});var Qr=$r.inspectSource,Hr=b,Wr=a,Gr=w,Vr=Pr,Yr=Qr,Jr=function(){},Zr=[],Xr=X('Reflect','construct'),tn=/^\s*(?:class|function)\b/,en=Hr(tn.exec),rn=!tn.exec(Jr),nn=function(t){if(!Gr(t))return!1;try{return Xr(Jr,Zr,t),!0}catch(t){return!1}},on=function(t){if(!Gr(t))return!1;switch(Vr(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return rn||!!en(tn,Yr(t))}catch(t){return!0}};on.sham=!0;var sn,an,un,cn,hn=!Xr||Wr((function(){var t;return nn(nn.call)||!nn(Object)||!nn((function(){t=!0}))||t}))?on:nn,ln=bt,fn=TypeError,pn=He,dn=function(t){if(hn(t))return t;throw fn(ln(t)+' is not a constructor')},vn=re('species'),yn=function(t,e){var r,n=pn(t).constructor;return void 0===n||null==(r=pn(n)[vn])?e:dn(r)},mn=X('document','documentElement'),gn=b([].slice),bn=TypeError,wn=/(?:ipad|iphone|ipod).*applewebkit/i.test(et),An=s,Tn=p,Sn=ze,En=w,_n=zt,On=a,Pn=mn,Rn=gn,xn=ye,jn=function(t,e){if(t<e)throw bn('Not enough arguments');return t},kn=wn,Cn=yr,In=An.setImmediate,Nn=An.clearImmediate,Ln=An.process,qn=An.Dispatch,Un=An.Function,Bn=An.MessageChannel,Mn=An.String,zn=0,Dn={};try{sn=An.location}catch(t){}var Fn=function(t){if(_n(Dn,t)){var e=Dn[t];delete Dn[t],e()}},$n=function(t){return function(){Fn(t)}},Kn=function(t){Fn(t.data)},Qn=function(t){An.postMessage(Mn(t),sn.protocol+'//'+sn.host)};In&&Nn||(In=function(t){jn(arguments.length,1);var e=En(t)?t:Un(t),r=Rn(arguments,1);return Dn[++zn]=function(){Tn(e,void 0,r)},an(zn),zn},Nn=function(t){delete Dn[t]},Cn?an=function(t){Ln.nextTick($n(t))}:qn&&qn.now?an=function(t){qn.now($n(t))}:Bn&&!kn?(cn=(un=new Bn).port2,un.port1.onmessage=Kn,an=Sn(cn.postMessage,cn)):An.addEventListener&&En(An.postMessage)&&!An.importScripts&&sn&&'file:'!==sn.protocol&&!On(Qn)?(an=Qn,An.addEventListener('message',Kn,!1)):an='onreadystatechange'in xn('script')?function(t){Pn.appendChild(xn('script')).onreadystatechange=function(){Pn.removeChild(this),Fn(t)}}:function(t){setTimeout($n(t),0)});var Hn,Wn,Gn,Vn,Yn,Jn,Zn,Xn,to={set:In,clear:Nn},eo=s,ro=/ipad|iphone|ipod/i.test(et)&&void 0!==eo.Pebble,no=/web0s(?!.*chrome)/i.test(et),oo=s,io=ze,so=A.f,ao=to.set,uo=wn,co=ro,ho=no,lo=yr,fo=oo.MutationObserver||oo.WebKitMutationObserver,po=oo.document,vo=oo.process,yo=oo.Promise,mo=so(oo,'queueMicrotask'),go=mo&&mo.value;go||(Hn=function(){var t,e;for(lo&&(t=vo.domain)&&t.exit();Wn;){e=Wn.fn,Wn=Wn.next;try{e()}catch(t){throw Wn?Vn():Gn=void 0,t}}Gn=void 0,t&&t.enter()},uo||lo||ho||!fo||!po?!co&&yo&&yo.resolve?((Zn=yo.resolve(void 0)).constructor=yo,Xn=io(Zn.then,Zn),Vn=function(){Xn(Hn)}):lo?Vn=function(){vo.nextTick(Hn)}:(ao=io(ao,oo),Vn=function(){ao(Hn)}):(Yn=!0,Jn=po.createTextNode(''),new fo(Hn).observe(Jn,{characterData:!0}),Vn=function(){Jn.data=Yn=!Yn}));var bo=go||function(t){var e={fn:t,next:void 0};Gn&&(Gn.next=e),Wn||(Wn=e,Vn()),Gn=e},wo=s,Ao=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},To=function(){this.head=null,this.tail=null};To.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 So,Eo,_o,Oo=To,Po=w,Ro=Qr,xo=s.WeakMap,jo=Po(xo)&&/native code/.test(Ro(xo)),ko=jt.exports,Co=Qt,Io=ko('keys'),No=jo,Lo=s,qo=b,Uo=W,Bo=nr,Mo=zt,zo=Nt,Do=function(t){return Io[t]||(Io[t]=Co(t))},Fo=Lo.TypeError,$o=Lo.WeakMap;if(No||zo.state){var Ko=zo.state||(zo.state=new $o),Qo=qo(Ko.get),Ho=qo(Ko.has),Wo=qo(Ko.set);So=function(t,e){if(Ho(Ko,t))throw new Fo('Object already initialized');return e.facade=t,Wo(Ko,t,e),e},Eo=function(t){return Qo(Ko,t)||{}},_o=function(t){return Ho(Ko,t)}}else{var Go=Do('state');So=function(t,e){if(Mo(t,Go))throw new Fo('Object already initialized');return e.facade=t,Bo(t,Go,e),e},Eo=function(t){return Mo(t,Go)?t[Go]:{}},_o=function(t){return Mo(t,Go)}}var Vo={set:So,get:Eo,has:_o,enforce:function(t){return _o(t)?Eo(t):So(t,{})},getterFor:function(t){return function(e){var r;if(!Uo(e)||(r=Eo(e)).type!==t)throw Fo('Incompatible receiver, '+t+' required');return r}}},Yo=s.Promise,Jo='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,Zo=!Jo&&!yr&&'object'==typeof window&&'object'==typeof document,Xo=s,ti=Yo,ei=w,ri=qe,ni=Qr,oi=re,ii=Zo,si=Jo,ai=ut,ui=ti&&ti.prototype,ci=oi('species'),hi=!1,li=ei(Xo.PromiseRejectionEvent),fi={CONSTRUCTOR:ri('Promise',(function(){var t=ni(ti),e=t!==String(ti);if(!e&&66===ai)return!0;if(!ui.catch||!ui.finally)return!0;if(!ai||ai<51||!/native code/.test(t)){var r=new ti((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};if((r.constructor={})[ci]=n,!(hi=r.then((function(){}))instanceof n))return!0}return!e&&(ii||si)&&!li})),REJECTION_EVENT:li,SUBCLASSING:hi},pi={},di=St,vi=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=di(e),this.reject=di(r)};pi.f=function(t){return new vi(t)};var yi,mi,gi=vr,bi=yr,wi=s,Ai=_,Ti=function(t,e,r,n){return n&&n.enumerable?t[e]=r:mr(t,e,r),t},Si=function(t,e,r,n){if(t){var o=r?t:t.prototype;Ir(o,Lr)||kr(o,Lr,{configurable:!0,value:e}),n&&!jr&&Cr(o,'toString',Nr)}},Ei=function(t){var e=qr(t),r=Ur.f;Br&&e&&!e[Mr]&&r(e,Mr,{configurable:!0,get:function(){return this}})},_i=St,Oi=w,Pi=W,Ri=function(t,e){if(zr(e,t))return t;throw Dr('Incorrect invocation')},xi=yn,ji=to.set,ki=bo,Ci=function(t,e){var r=wo.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ii=Ao,Ni=Oo,Li=Vo,qi=Yo,Ui=pi,Bi=fi.CONSTRUCTOR,Mi=fi.REJECTION_EVENT,zi=Li.getterFor('Promise'),Di=Li.set,Fi=qi&&qi.prototype,$i=qi,Ki=Fi,Qi=wi.TypeError,Hi=wi.document,Wi=wi.process,Gi=Ui.f,Vi=Gi,Yi=!!(Hi&&Hi.createEvent&&wi.dispatchEvent),Ji=function(t){var e;return!(!Pi(t)||!Oi(e=t.then))&&e},Zi=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&&ns(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),o=!0)),r===t.promise?c(Qi('Promise-chain cycle')):(n=Ji(r))?Ai(n,r,u,c):u(r)):c(i)}catch(t){h&&!o&&h.exit(),c(t)}},Xi=function(t,e){t.notified||(t.notified=!0,ki((function(){for(var r,n=t.reactions;r=n.get();)Zi(r,t);t.notified=!1,e&&!t.rejection&&es(t)})))},ts=function(t,e,r){var n,o;Yi?((n=Hi.createEvent('Event')).promise=e,n.reason=r,n.initEvent(t,!1,!0),wi.dispatchEvent(n)):n={promise:e,reason:r},!Mi&&(o=wi['on'+t])?o(n):'unhandledrejection'===t&&Ci('Unhandled promise rejection',r)},es=function(t){Ai(ji,wi,(function(){var e,r=t.facade,n=t.value;if(rs(t)&&(e=Ii((function(){bi?Wi.emit('unhandledRejection',n,r):ts('unhandledrejection',r,n)})),t.rejection=bi||rs(t)?2:1,e.error))throw e.value}))},rs=function(t){return 1!==t.rejection&&!t.parent},ns=function(t){Ai(ji,wi,(function(){var e=t.facade;bi?Wi.emit('rejectionHandled',e):ts('rejectionhandled',e,t.value)}))},os=function(t,e,r){return function(n){t(e,n,r)}},is=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,Xi(t,!0))},ss=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw Qi('Promise can\'t be resolved itself');var n=Ji(e);n?ki((function(){var r={done:!1};try{Ai(n,e,os(ss,r,t),os(is,r,t))}catch(e){is(r,e,t)}})):(t.value=e,t.state=1,Xi(t,!1))}catch(e){is({done:!1},e,t)}}};Bi&&(Ki=($i=function(t){Ri(this,Ki),_i(t),Ai(yi,this);var e=zi(this);try{t(os(ss,e),os(is,e))}catch(t){is(e,t)}}).prototype,(yi=function(t){Di(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new Ni,rejection:!1,state:0,value:void 0})}).prototype=Ti(Ki,'then',(function(t,e){var r=zi(this),n=Gi(xi(this,$i));return r.parent=!0,n.ok=!Oi(t)||t,n.fail=Oi(e)&&e,n.domain=bi?Wi.domain:void 0,0==r.state?r.reactions.add(n):ki((function(){Zi(n,r)})),n.promise})),mi=function(){var t=new yi,e=zi(t);this.promise=t,this.resolve=os(ss,e),this.reject=os(is,e)},Ui.f=Gi=function(t){return t===$i||undefined===t?new mi(t):Vi(t)}),gi({global:!0,constructor:!0,wrap:!0,forced:Bi},{Promise:$i}),Si($i,'Promise',!1,!0),Ei('Promise');var as={},us=as,cs=re('iterator'),hs=Array.prototype,ls=Math.ceil,fs=Math.floor,ps=Math.trunc||function(t){var e=+t;return(e>0?fs:ls)(e)},ds=function(t){var e=+t;return e!=e||0===e?0:ps(e)},vs=Math.min,ys=function(t){return t>0?vs(ds(t),9007199254740991):0},ms=Pr,gs=_t,bs=as,ws=re('iterator'),As=function(t){if(null!=t)return gs(t,ws)||gs(t,'@@iterator')||bs[ms(t)]},Ts=_,Ss=St,Es=He,_s=bt,Os=As,Ps=TypeError,Rs=_,xs=He,js=_t,ks=ze,Cs=_,Is=He,Ns=bt,Ls=function(t){return void 0!==t&&(us.Array===t||hs[cs]===t)},qs=function(t){return ys(t.length)},Us=tt,Bs=function(t,e){var r=arguments.length<2?Os(t):e;if(Ss(r))return Es(Ts(r,t));throw Ps(_s(t)+' is not iterable')},Ms=As,zs=function(t,e,r){var n,o;xs(t);try{if(!(n=js(t,'return'))){if('throw'===e)throw r;return r}n=Rs(n,t)}catch(t){o=!0,n=t}if('throw'===e)throw r;if(o)throw n;return xs(n),r},Ds=TypeError,Fs=function(t,e){this.stopped=t,this.result=e},$s=Fs.prototype,Ks=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),p=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=ks(e,h),y=function(t){return n&&zs(n,'normal',t),new Fs(!0,t)},m=function(t){return l?(Is(t),d?v(t[0],t[1],y):v(t[0],t[1])):d?v(t,y):v(t)};if(f)n=t.iterator;else if(p)n=t;else{if(!(o=Ms(t)))throw Ds(Ns(t)+' is not iterable');if(Ls(o)){for(i=0,s=qs(t);s>i;i++)if((a=m(t[i]))&&Us($s,a))return a;return new Fs(!1)}n=Bs(t,o)}for(u=f?t.next:n.next;!(c=Cs(u,n)).done;){try{a=m(c.value)}catch(t){zs(n,'throw',t)}if('object'==typeof a&&a&&Us($s,a))return a}return new Fs(!1)},Qs=re('iterator'),Hs=!1;try{var Ws=0,Gs={next:function(){return{done:!!Ws++}},return:function(){Hs=!0}};Gs[Qs]=function(){return this},Array.from(Gs,(function(){throw 2}))}catch(t){}var Vs=Yo,Ys=fi.CONSTRUCTOR||!function(t,e){if(!e&&!Hs)return!1;var r=!1;try{var n={};n[Qs]=function(){return{next:function(){return{done:r=!0}}}},t(n)}catch(t){}return r}((function(t){Vs.all(t).then(void 0,(function(){}))})),Js=_,Zs=St,Xs=pi,ta=Ao,ea=Ks;vr({target:'Promise',stat:!0,forced:Ys},{all:function(t){var e=this,r=Xs.f(e),n=r.resolve,o=r.reject,i=ta((function(){var r=Zs(e.resolve),i=[],s=0,a=1;ea(t,(function(t){var u=s++,c=!1;a++,Js(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 ra=vr,na=fi.CONSTRUCTOR;Yo&&Yo.prototype,ra({target:'Promise',proto:!0,forced:na,real:!0},{catch:function(t){return this.then(void 0,t)}});var oa=_,ia=St,sa=pi,aa=Ao,ua=Ks;vr({target:'Promise',stat:!0,forced:Ys},{race:function(t){var e=this,r=sa.f(e),n=r.reject,o=aa((function(){var o=ia(e.resolve);ua(t,(function(t){oa(o,e,t).then(r.resolve,n)}))}));return o.error&&n(o.value),r.promise}});var ca=_,ha=pi;vr({target:'Promise',stat:!0,forced:fi.CONSTRUCTOR},{reject:function(t){var e=ha.f(this);return ca(e.reject,void 0,t),e.promise}});var la=He,fa=W,pa=pi,da=function(t,e){if(la(t),fa(e)&&e.constructor===t)return e;var r=pa.f(t);return(0,r.resolve)(e),r.promise},va=vr,ya=Yo,ma=fi.CONSTRUCTOR,ga=da,ba=X('Promise'),wa=!ma;va({target:'Promise',stat:!0,forced:true},{resolve:function(t){return ga(wa&&this===ba?ya:this,t)}});var Aa=vr,Ta=Yo,Sa=a,Ea=X,_a=w,Oa=yn,Pa=da,Ra=Ta&&Ta.prototype;Aa({target:'Promise',proto:!0,real:!0,forced:!!Ta&&Sa((function(){Ra.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=Oa(this,Ea('Promise')),r=_a(t);return this.then(r?function(r){return Pa(e,t()).then((function(){return r}))}:t,r?function(r){return Pa(e,t()).then((function(){throw r}))}:t)}});var xa=X('Promise','finally');const ja=(()=>{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 ka,Ca,Ia,Na,La,qa,Ua,Ba={get:t=>function(t){const e=ja?ja.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{ja&&ja.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){ja&&ja.removeItem('_one-stat_'+t)}(t)}};exports.ApiEnv=void 0,(ka=exports.ApiEnv||(exports.ApiEnv={})).PROD='prod',ka.VK_ALIAS='vk_alias',ka.VIDEOTEST='videotest',ka.TEST='test',ka.AUTO='auto',exports.Quality=void 0,(Ca=exports.Quality||(exports.Quality={})).Q144P='144',Ca.Q240P='240',Ca.Q360P='360',Ca.Q480P='480',Ca.Q720P='720',Ca.Q1080P='1080',Ca.Q1440P='1440',Ca.Q2160P='2160',Ca.Q4320P='4320',Ca.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,(Na=exports.ContentType||(exports.ContentType={})).MP4='mp4',Na.DASH='dash',Na.DASH_SEP='dash_sep',Na.ONDEMAND_DASH='ondemand_dash',Na.HLS='hls',Na.ONDEMAND_HLS='ondemand_hls',Na.WEBM='webm',Na.RTMP='rtmp',Na.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(La||(La={})),exports.ConnectionType=void 0,(qa=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',qa.HTTP2='http2',qa.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(Ua||(Ua={}));const Ma={[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]:''},za={start:1e3,factor:1.5,max:3e5,random:.1};var Da;!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'}(Da||(Da={}));class Fa{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t.ValueSubject(!1),this.params=e;const r=Ba.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('')}(),Ba.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(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 Da.PARAM_SESSION_EXPIRED:case Da.PARAM_SESSION_KEY:case Da.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?s(t,e-1):void 0;case Da.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 n(this,void 0,void 0,(function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=xa(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.26',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,za);return new Promise((t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{xa(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.26'.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=xa(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 Da.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 $a(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 Ka=$a({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Qa=Ka?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(!$a({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,Ha=Ka?Qa.fetch:window.fetch;Ka?Qa.Request:window.Request;class Wa{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,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 Ha(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}),Ma[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(t,e,r){return n(this,void 0,void 0,(function*(){const n=Date.now(),o=o=>{o instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(o.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:o}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:o,data:{method:t,params:e,sessionKey:r,time:Date.now()-n}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Ha(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:r})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),o):void 0),o)}))}_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=r.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()}}const Va=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0');exports.OneStat=class{constructor(e,r){var n;this.subscription=new t.Subscription,this.vsid=Va(),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:Ma[r.apiEnv],apiEnv:r.apiEnv,error$:o});this.api=new Fa({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)}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=Va()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const r=Date.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?Ua.YES:!1===this.statContext.connectionReused?Ua.NO:void 0,stat_type:!0===this.statContext.autoplay?La.AUTO:!1===this.statContext.autoplay?La.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 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-beta.0',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-beta.0'.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}}};
|
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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as t,getExponentialDelay as e,Subscription as r,Subject as n,fromEvent as o}from'@vkontakte/videoplayer-shared/es2015.esm.js';import i from'lodash/debounce.js';function s(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 a='undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:'undefined'!=typeof global?global:'undefined'!=typeof self?self:{},u=function(t){return t&&t.Math==Math&&t},c=u('object'==typeof globalThis&&globalThis)||u('object'==typeof window&&window)||u('object'==typeof self&&self)||u('object'==typeof a&&a)||function(){return this}()||Function('return this')(),h=function(t){try{return!!t()}catch(t){return!0}},l=!h((function(){var t=function(){}.bind();return'function'!=typeof t||t.hasOwnProperty('prototype')})),f=l,p=Function.prototype,d=p.apply,v=p.call,m='object'==typeof Reflect&&Reflect.apply||(f?v.bind(d):function(){return v.apply(d,arguments)}),y=l,g=Function.prototype,b=g.bind,w=g.call,T=y&&b.bind(w,w),_=y?function(t){return t&&T(t)}:function(t){return t&&function(){return w.apply(t,arguments)}},O=function(t){return'function'==typeof t},S={},A=!h((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),P=l,E=Function.prototype.call,R=P?E.bind(E):function(){return E.apply(E,arguments)},k={},j={}.propertyIsEnumerable,C=Object.getOwnPropertyDescriptor,x=C&&!j.call({1:2},1);k.f=x?function(t){var e=C(this,t);return!!e&&e.enumerable}:j;var I,N,L=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},U=_,q=U({}.toString),B=U(''.slice),M=function(t){return B(q(t),8,-1)},z=h,D=M,F=Object,$=_(''.split),K=z((function(){return!F('z').propertyIsEnumerable(0)}))?function(t){return'String'==D(t)?$(t,''):F(t)}:F,H=TypeError,Q=function(t){if(null==t)throw H('Can\'t call method on '+t);return t},W=K,G=Q,V=O,Y=function(t){return'object'==typeof t?null!==t:V(t)},J={},Z=J,X=c,tt=O,et=function(t){return tt(t)?t:void 0},rt=function(t,e){return arguments.length<2?et(Z[t])||et(X[t]):Z[t]&&Z[t][e]||X[t]&&X[t][e]},nt=_({}.isPrototypeOf),ot=rt('navigator','userAgent')||'',it=c,st=ot,at=it.process,ut=it.Deno,ct=at&&at.versions||ut&&ut.version,ht=ct&&ct.v8;ht&&(N=(I=ht.split('.'))[0]>0&&I[0]<4?1:+(I[0]+I[1])),!N&&st&&(!(I=st.match(/Edge\/(\d+)/))||I[1]>=74)&&(I=st.match(/Chrome\/(\d+)/))&&(N=+I[1]);var lt=N,ft=lt,pt=h,dt=!!Object.getOwnPropertySymbols&&!pt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&ft&&ft<41})),vt=dt&&!Symbol.sham&&'symbol'==typeof Symbol.iterator,mt=rt,yt=O,gt=nt,bt=Object,wt=vt?function(t){return'symbol'==typeof t}:function(t){var e=mt('Symbol');return yt(e)&>(e.prototype,bt(t))},Tt=String,_t=function(t){try{return Tt(t)}catch(t){return'Object'}},Ot=O,St=_t,At=TypeError,Pt=function(t){if(Ot(t))return t;throw At(St(t)+' is not a function')},Et=Pt,Rt=function(t,e){var r=t[e];return null==r?void 0:Et(r)},kt=R,jt=O,Ct=Y,xt=TypeError,It={exports:{}},Nt=c,Lt=Object.defineProperty,Ut=function(t,e){try{Lt(Nt,t,{value:e,configurable:!0,writable:!0})}catch(r){Nt[t]=e}return e},qt=c['__core-js_shared__']||Ut('__core-js_shared__',{}),Bt=qt;(It.exports=function(t,e){return Bt[t]||(Bt[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 Mt=Q,zt=Object,Dt=function(t){return zt(Mt(t))},Ft=_({}.hasOwnProperty),$t=Object.hasOwn||function(t,e){return Ft(Dt(t),e)},Kt=_,Ht=0,Qt=Math.random(),Wt=Kt(1..toString),Gt=function(t){return'Symbol('+(void 0===t?'':t)+')_'+Wt(++Ht+Qt,36)},Vt=c,Yt=It.exports,Jt=$t,Zt=Gt,Xt=dt,te=vt,ee=Yt('wks'),re=Vt.Symbol,ne=re&&re.for,oe=te?re:re&&re.withoutSetter||Zt,ie=function(t){if(!Jt(ee,t)||!Xt&&'string'!=typeof ee[t]){var e='Symbol.'+t;Xt&&Jt(re,t)?ee[t]=re[t]:ee[t]=te&&ne?ne(e):oe(e)}return ee[t]},se=R,ae=Y,ue=wt,ce=Rt,he=function(t,e){var r,n;if('string'===e&&jt(r=t.toString)&&!Ct(n=kt(r,t)))return n;if(jt(r=t.valueOf)&&!Ct(n=kt(r,t)))return n;if('string'!==e&&jt(r=t.toString)&&!Ct(n=kt(r,t)))return n;throw xt('Can\'t convert object to primitive value')},le=TypeError,fe=ie('toPrimitive'),pe=function(t,e){if(!ae(t)||ue(t))return t;var r,n=ce(t,fe);if(n){if(void 0===e&&(e='default'),r=se(n,t,e),!ae(r)||ue(r))return r;throw le('Can\'t convert object to primitive value')}return void 0===e&&(e='number'),he(t,e)},de=wt,ve=function(t){var e=pe(t,'string');return de(e)?e:e+''},me=Y,ye=c.document,ge=me(ye)&&me(ye.createElement),be=function(t){return ge?ye.createElement(t):{}},we=be,Te=!A&&!h((function(){return 7!=Object.defineProperty(we('div'),'a',{get:function(){return 7}}).a})),_e=A,Oe=R,Se=k,Ae=L,Pe=function(t){return W(G(t))},Ee=ve,Re=$t,ke=Te,je=Object.getOwnPropertyDescriptor;S.f=_e?je:function(t,e){if(t=Pe(t),e=Ee(e),ke)try{return je(t,e)}catch(t){}if(Re(t,e))return Ae(!Oe(Se.f,t,e),t[e])};var Ce=h,xe=O,Ie=/#|\.prototype\./,Ne=function(t,e){var r=Ue[Le(t)];return r==Be||r!=qe&&(xe(e)?Ce(e):!!e)},Le=Ne.normalize=function(t){return String(t).replace(Ie,'.').toLowerCase()},Ue=Ne.data={},qe=Ne.NATIVE='N',Be=Ne.POLYFILL='P',Me=Ne,ze=Pt,De=l,Fe=_(_.bind),$e=function(t,e){return ze(t),void 0===e?t:De?Fe(t,e):function(){return t.apply(e,arguments)}},Ke={},He=A&&h((function(){return 42!=Object.defineProperty((function(){}),'prototype',{value:42,writable:!1}).prototype})),Qe=Y,We=String,Ge=TypeError,Ve=function(t){if(Qe(t))return t;throw Ge(We(t)+' is not an object')},Ye=A,Je=Te,Ze=He,Xe=Ve,tr=ve,er=TypeError,rr=Object.defineProperty,nr=Object.getOwnPropertyDescriptor;Ke.f=Ye?Ze?function(t,e,r){if(Xe(t),e=tr(e),Xe(r),'function'==typeof t&&'prototype'===e&&'value'in r&&'writable'in r&&!r.writable){var n=nr(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 rr(t,e,r)}:rr:function(t,e,r){if(Xe(t),e=tr(e),Xe(r),Je)try{return rr(t,e,r)}catch(t){}if('get'in r||'set'in r)throw er('Accessors not supported');return'value'in r&&(t[e]=r.value),t};var or=Ke,ir=L,sr=A?function(t,e,r){return or.f(t,e,ir(1,r))}:function(t,e,r){return t[e]=r,t},ar=c,ur=m,cr=_,hr=O,lr=S.f,fr=Me,pr=J,dr=$e,vr=sr,mr=$t,yr=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 ur(t,this,arguments)};return e.prototype=t.prototype,e},gr=function(t,e){var r,n,o,i,s,a,u,c,h=t.target,l=t.global,f=t.stat,p=t.proto,d=l?ar:f?ar[h]:(ar[h]||{}).prototype,v=l?pr:pr[h]||vr(pr,h,{})[h],m=v.prototype;for(o in e)r=!fr(l?o:h+(f?'.':'#')+o,t.forced)&&d&&mr(d,o),s=v[o],r&&(a=t.dontCallGetSet?(c=lr(d,o))&&c.value:d[o]),i=r&&a?a:e[o],r&&typeof s==typeof i||(u=t.bind&&r?dr(i,ar):t.wrap&&r?yr(i):p&&hr(i)?cr(i):i,(t.sham||i&&i.sham||s&&s.sham)&&vr(u,'sham',!0),vr(v,o,u),p&&(mr(pr,n=h+'Prototype')||vr(pr,n,{}),vr(pr[n],o,i),t.real&&m&&!m[o]&&vr(m,o,i)))},br='process'==M(c.process),wr=sr,Tr=(TypeError,_);Object.setPrototypeOf||'__proto__'in{}&&function(){var t,e=!1,r={};try{(t=Tr(Object.getOwnPropertyDescriptor(Object.prototype,'__proto__').set))(r,[]),e=r instanceof Array}catch(t){}}();var _r={};_r[ie('toStringTag')]='z';var Or='[object z]'===String(_r),Sr=Or,Ar=O,Pr=M,Er=ie('toStringTag'),Rr=Object,kr='Arguments'==Pr(function(){return arguments}()),jr=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=Rr(t),Er))?r:kr?Pr(e):'Object'==(n=Pr(e))&&Ar(e.callee)?'Arguments':n},Cr=jr,xr=Or?{}.toString:function(){return'[object '+Cr(this)+']'},Ir=Or,Nr=Ke.f,Lr=sr,Ur=$t,qr=xr,Br=ie('toStringTag'),Mr=rt,zr=Ke,Dr=A,Fr=ie('species'),$r=nt,Kr=TypeError,Hr=O,Qr=qt,Wr=_(Function.toString);Hr(Qr.inspectSource)||(Qr.inspectSource=function(t){return Wr(t)});var Gr=Qr.inspectSource,Vr=_,Yr=h,Jr=O,Zr=jr,Xr=Gr,tn=function(){},en=[],rn=rt('Reflect','construct'),nn=/^\s*(?:class|function)\b/,on=Vr(nn.exec),sn=!nn.exec(tn),an=function(t){if(!Jr(t))return!1;try{return rn(tn,en,t),!0}catch(t){return!1}},un=function(t){if(!Jr(t))return!1;switch(Zr(t)){case'AsyncFunction':case'GeneratorFunction':case'AsyncGeneratorFunction':return!1}try{return sn||!!on(nn,Xr(t))}catch(t){return!0}};un.sham=!0;var cn,hn,ln,fn,pn=!rn||Yr((function(){var t;return an(an.call)||!an(Object)||!an((function(){t=!0}))||t}))?un:an,dn=_t,vn=TypeError,mn=Ve,yn=function(t){if(pn(t))return t;throw vn(dn(t)+' is not a constructor')},gn=ie('species'),bn=function(t,e){var r,n=mn(t).constructor;return void 0===n||null==(r=mn(n)[gn])?e:yn(r)},wn=rt('document','documentElement'),Tn=_([].slice),_n=TypeError,On=/(?:ipad|iphone|ipod).*applewebkit/i.test(ot),Sn=c,An=m,Pn=$e,En=O,Rn=$t,kn=h,jn=wn,Cn=Tn,xn=be,In=function(t,e){if(t<e)throw _n('Not enough arguments');return t},Nn=On,Ln=br,Un=Sn.setImmediate,qn=Sn.clearImmediate,Bn=Sn.process,Mn=Sn.Dispatch,zn=Sn.Function,Dn=Sn.MessageChannel,Fn=Sn.String,$n=0,Kn={};try{cn=Sn.location}catch(t){}var Hn=function(t){if(Rn(Kn,t)){var e=Kn[t];delete Kn[t],e()}},Qn=function(t){return function(){Hn(t)}},Wn=function(t){Hn(t.data)},Gn=function(t){Sn.postMessage(Fn(t),cn.protocol+'//'+cn.host)};Un&&qn||(Un=function(t){In(arguments.length,1);var e=En(t)?t:zn(t),r=Cn(arguments,1);return Kn[++$n]=function(){An(e,void 0,r)},hn($n),$n},qn=function(t){delete Kn[t]},Ln?hn=function(t){Bn.nextTick(Qn(t))}:Mn&&Mn.now?hn=function(t){Mn.now(Qn(t))}:Dn&&!Nn?(fn=(ln=new Dn).port2,ln.port1.onmessage=Wn,hn=Pn(fn.postMessage,fn)):Sn.addEventListener&&En(Sn.postMessage)&&!Sn.importScripts&&cn&&'file:'!==cn.protocol&&!kn(Gn)?(hn=Gn,Sn.addEventListener('message',Wn,!1)):hn='onreadystatechange'in xn('script')?function(t){jn.appendChild(xn('script')).onreadystatechange=function(){jn.removeChild(this),Hn(t)}}:function(t){setTimeout(Qn(t),0)});var Vn,Yn,Jn,Zn,Xn,to,eo,ro,no={set:Un,clear:qn},oo=c,io=/ipad|iphone|ipod/i.test(ot)&&void 0!==oo.Pebble,so=/web0s(?!.*chrome)/i.test(ot),ao=c,uo=$e,co=S.f,ho=no.set,lo=On,fo=io,po=so,vo=br,mo=ao.MutationObserver||ao.WebKitMutationObserver,yo=ao.document,go=ao.process,bo=ao.Promise,wo=co(ao,'queueMicrotask'),To=wo&&wo.value;To||(Vn=function(){var t,e;for(vo&&(t=go.domain)&&t.exit();Yn;){e=Yn.fn,Yn=Yn.next;try{e()}catch(t){throw Yn?Zn():Jn=void 0,t}}Jn=void 0,t&&t.enter()},lo||vo||po||!mo||!yo?!fo&&bo&&bo.resolve?((eo=bo.resolve(void 0)).constructor=bo,ro=uo(eo.then,eo),Zn=function(){ro(Vn)}):vo?Zn=function(){go.nextTick(Vn)}:(ho=uo(ho,ao),Zn=function(){ho(Vn)}):(Xn=!0,to=yo.createTextNode(''),new mo(Vn).observe(to,{characterData:!0}),Zn=function(){to.data=Xn=!Xn}));var _o=To||function(t){var e={fn:t,next:void 0};Jn&&(Jn.next=e),Yn||(Yn=e,Zn()),Jn=e},Oo=c,So=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}},Ao=function(){this.head=null,this.tail=null};Ao.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,Eo,Ro,ko=Ao,jo=O,Co=Gr,xo=c.WeakMap,Io=jo(xo)&&/native code/.test(Co(xo)),No=It.exports,Lo=Gt,Uo=No('keys'),qo=Io,Bo=c,Mo=_,zo=Y,Do=sr,Fo=$t,$o=qt,Ko=function(t){return Uo[t]||(Uo[t]=Lo(t))},Ho=Bo.TypeError,Qo=Bo.WeakMap;if(qo||$o.state){var Wo=$o.state||($o.state=new Qo),Go=Mo(Wo.get),Vo=Mo(Wo.has),Yo=Mo(Wo.set);Po=function(t,e){if(Vo(Wo,t))throw new Ho('Object already initialized');return e.facade=t,Yo(Wo,t,e),e},Eo=function(t){return Go(Wo,t)||{}},Ro=function(t){return Vo(Wo,t)}}else{var Jo=Ko('state');Po=function(t,e){if(Fo(t,Jo))throw new Ho('Object already initialized');return e.facade=t,Do(t,Jo,e),e},Eo=function(t){return Fo(t,Jo)?t[Jo]:{}},Ro=function(t){return Fo(t,Jo)}}var Zo={set:Po,get:Eo,has:Ro,enforce:function(t){return Ro(t)?Eo(t):Po(t,{})},getterFor:function(t){return function(e){var r;if(!zo(e)||(r=Eo(e)).type!==t)throw Ho('Incompatible receiver, '+t+' required');return r}}},Xo=c.Promise,ti='object'==typeof Deno&&Deno&&'object'==typeof Deno.version,ei=!ti&&!br&&'object'==typeof window&&'object'==typeof document,ri=c,ni=Xo,oi=O,ii=Me,si=Gr,ai=ie,ui=ei,ci=ti,hi=lt,li=ni&&ni.prototype,fi=ai('species'),pi=!1,di=oi(ri.PromiseRejectionEvent),vi={CONSTRUCTOR:ii('Promise',(function(){var t=si(ni),e=t!==String(ni);if(!e&&66===hi)return!0;if(!li.catch||!li.finally)return!0;if(!hi||hi<51||!/native code/.test(t)){var r=new ni((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};if((r.constructor={})[fi]=n,!(pi=r.then((function(){}))instanceof n))return!0}return!e&&(ui||ci)&&!di})),REJECTION_EVENT:di,SUBCLASSING:pi},mi={},yi=Pt,gi=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=yi(e),this.reject=yi(r)};mi.f=function(t){return new gi(t)};var bi,wi,Ti=gr,_i=br,Oi=c,Si=R,Ai=function(t,e,r,n){return n&&n.enumerable?t[e]=r:wr(t,e,r),t},Pi=function(t,e,r,n){if(t){var o=r?t:t.prototype;Ur(o,Br)||Nr(o,Br,{configurable:!0,value:e}),n&&!Ir&&Lr(o,'toString',qr)}},Ei=function(t){var e=Mr(t),r=zr.f;Dr&&e&&!e[Fr]&&r(e,Fr,{configurable:!0,get:function(){return this}})},Ri=Pt,ki=O,ji=Y,Ci=function(t,e){if($r(e,t))return t;throw Kr('Incorrect invocation')},xi=bn,Ii=no.set,Ni=_o,Li=function(t,e){var r=Oo.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ui=So,qi=ko,Bi=Zo,Mi=Xo,zi=mi,Di=vi.CONSTRUCTOR,Fi=vi.REJECTION_EVENT,$i=Bi.getterFor('Promise'),Ki=Bi.set,Hi=Mi&&Mi.prototype,Qi=Mi,Wi=Hi,Gi=Oi.TypeError,Vi=Oi.document,Yi=Oi.process,Ji=zi.f,Zi=Ji,Xi=!!(Vi&&Vi.createEvent&&Oi.dispatchEvent),ts=function(t){var e;return!(!ji(t)||!ki(e=t.then))&&e},es=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&&ss(e),e.rejection=1),!0===a?r=i:(h&&h.enter(),r=a(i),h&&(h.exit(),o=!0)),r===t.promise?c(Gi('Promise-chain cycle')):(n=ts(r))?Si(n,r,u,c):u(r)):c(i)}catch(t){h&&!o&&h.exit(),c(t)}},rs=function(t,e){t.notified||(t.notified=!0,Ni((function(){for(var r,n=t.reactions;r=n.get();)es(r,t);t.notified=!1,e&&!t.rejection&&os(t)})))},ns=function(t,e,r){var n,o;Xi?((n=Vi.createEvent('Event')).promise=e,n.reason=r,n.initEvent(t,!1,!0),Oi.dispatchEvent(n)):n={promise:e,reason:r},!Fi&&(o=Oi['on'+t])?o(n):'unhandledrejection'===t&&Li('Unhandled promise rejection',r)},os=function(t){Si(Ii,Oi,(function(){var e,r=t.facade,n=t.value;if(is(t)&&(e=Ui((function(){_i?Yi.emit('unhandledRejection',n,r):ns('unhandledrejection',r,n)})),t.rejection=_i||is(t)?2:1,e.error))throw e.value}))},is=function(t){return 1!==t.rejection&&!t.parent},ss=function(t){Si(Ii,Oi,(function(){var e=t.facade;_i?Yi.emit('rejectionHandled',e):ns('rejectionhandled',e,t.value)}))},as=function(t,e,r){return function(n){t(e,n,r)}},us=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,rs(t,!0))},cs=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw Gi('Promise can\'t be resolved itself');var n=ts(e);n?Ni((function(){var r={done:!1};try{Si(n,e,as(cs,r,t),as(us,r,t))}catch(e){us(r,e,t)}})):(t.value=e,t.state=1,rs(t,!1))}catch(e){us({done:!1},e,t)}}};Di&&(Wi=(Qi=function(t){Ci(this,Wi),Ri(t),Si(bi,this);var e=$i(this);try{t(as(cs,e),as(us,e))}catch(t){us(e,t)}}).prototype,(bi=function(t){Ki(this,{type:'Promise',done:!1,notified:!1,parent:!1,reactions:new qi,rejection:!1,state:0,value:void 0})}).prototype=Ai(Wi,'then',(function(t,e){var r=$i(this),n=Ji(xi(this,Qi));return r.parent=!0,n.ok=!ki(t)||t,n.fail=ki(e)&&e,n.domain=_i?Yi.domain:void 0,0==r.state?r.reactions.add(n):Ni((function(){es(n,r)})),n.promise})),wi=function(){var t=new bi,e=$i(t);this.promise=t,this.resolve=as(cs,e),this.reject=as(us,e)},zi.f=Ji=function(t){return t===Qi||undefined===t?new wi(t):Zi(t)}),Ti({global:!0,constructor:!0,wrap:!0,forced:Di},{Promise:Qi}),Pi(Qi,'Promise',!1,!0),Ei('Promise');var hs={},ls=hs,fs=ie('iterator'),ps=Array.prototype,ds=Math.ceil,vs=Math.floor,ms=Math.trunc||function(t){var e=+t;return(e>0?vs:ds)(e)},ys=function(t){var e=+t;return e!=e||0===e?0:ms(e)},gs=Math.min,bs=function(t){return t>0?gs(ys(t),9007199254740991):0},ws=jr,Ts=Rt,_s=hs,Os=ie('iterator'),Ss=function(t){if(null!=t)return Ts(t,Os)||Ts(t,'@@iterator')||_s[ws(t)]},As=R,Ps=Pt,Es=Ve,Rs=_t,ks=Ss,js=TypeError,Cs=R,xs=Ve,Is=Rt,Ns=$e,Ls=R,Us=Ve,qs=_t,Bs=function(t){return void 0!==t&&(ls.Array===t||ps[fs]===t)},Ms=function(t){return bs(t.length)},zs=nt,Ds=function(t,e){var r=arguments.length<2?ks(t):e;if(Ps(r))return Es(As(r,t));throw js(Rs(t)+' is not iterable')},Fs=Ss,$s=function(t,e,r){var n,o;xs(t);try{if(!(n=Is(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 xs(n),r},Ks=TypeError,Hs=function(t,e){this.stopped=t,this.result=e},Qs=Hs.prototype,Ws=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),p=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=Ns(e,h),m=function(t){return n&&$s(n,'normal',t),new Hs(!0,t)},y=function(t){return l?(Us(t),d?v(t[0],t[1],m):v(t[0],t[1])):d?v(t,m):v(t)};if(f)n=t.iterator;else if(p)n=t;else{if(!(o=Fs(t)))throw Ks(qs(t)+' is not iterable');if(Bs(o)){for(i=0,s=Ms(t);s>i;i++)if((a=y(t[i]))&&zs(Qs,a))return a;return new Hs(!1)}n=Ds(t,o)}for(u=f?t.next:n.next;!(c=Ls(u,n)).done;){try{a=y(c.value)}catch(t){$s(n,'throw',t)}if('object'==typeof a&&a&&zs(Qs,a))return a}return new Hs(!1)},Gs=ie('iterator'),Vs=!1;try{var Ys=0,Js={next:function(){return{done:!!Ys++}},return:function(){Vs=!0}};Js[Gs]=function(){return this},Array.from(Js,(function(){throw 2}))}catch(t){}var Zs=Xo,Xs=vi.CONSTRUCTOR||!function(t,e){if(!e&&!Vs)return!1;var r=!1;try{var n={};n[Gs]=function(){return{next:function(){return{done:r=!0}}}},t(n)}catch(t){}return r}((function(t){Zs.all(t).then(void 0,(function(){}))})),ta=R,ea=Pt,ra=mi,na=So,oa=Ws;gr({target:'Promise',stat:!0,forced:Xs},{all:function(t){var e=this,r=ra.f(e),n=r.resolve,o=r.reject,i=na((function(){var r=ea(e.resolve),i=[],s=0,a=1;oa(t,(function(t){var u=s++,c=!1;a++,ta(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 ia=gr,sa=vi.CONSTRUCTOR;Xo&&Xo.prototype,ia({target:'Promise',proto:!0,forced:sa,real:!0},{catch:function(t){return this.then(void 0,t)}});var aa=R,ua=Pt,ca=mi,ha=So,la=Ws;gr({target:'Promise',stat:!0,forced:Xs},{race:function(t){var e=this,r=ca.f(e),n=r.reject,o=ha((function(){var o=ua(e.resolve);la(t,(function(t){aa(o,e,t).then(r.resolve,n)}))}));return o.error&&n(o.value),r.promise}});var fa=R,pa=mi;gr({target:'Promise',stat:!0,forced:vi.CONSTRUCTOR},{reject:function(t){var e=pa.f(this);return fa(e.reject,void 0,t),e.promise}});var da=Ve,va=Y,ma=mi,ya=function(t,e){if(da(t),va(e)&&e.constructor===t)return e;var r=ma.f(t);return(0,r.resolve)(e),r.promise},ga=gr,ba=Xo,wa=vi.CONSTRUCTOR,Ta=ya,_a=rt('Promise'),Oa=!wa;ga({target:'Promise',stat:!0,forced:true},{resolve:function(t){return Ta(Oa&&this===_a?ba:this,t)}});var Sa=gr,Aa=Xo,Pa=h,Ea=rt,Ra=O,ka=bn,ja=ya,Ca=Aa&&Aa.prototype;Sa({target:'Promise',proto:!0,real:!0,forced:!!Aa&&Pa((function(){Ca.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=ka(this,Ea('Promise')),r=Ra(t);return this.then(r?function(r){return ja(e,t()).then((function(){return r}))}:t,r?function(r){return ja(e,t()).then((function(){throw r}))}:t)}});var xa=rt('Promise','finally');const Ia=(()=>{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,La,Ua,qa,Ba,Ma,za,Da={get:t=>function(t){const e=Ia?Ia.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{Ia&&Ia.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){Ia&&Ia.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(Na||(Na={})),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'}(La||(La={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(Ua||(Ua={})),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=''}(Ba||(Ba={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(Ma||(Ma={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(za||(za={}));const Fa={[Na.PROD]:'https://api.ok.ru',[Na.VK_ALIAS]:'https://api.mycdn.me',[Na.VIDEOTEST]:'https://videotestapi.ok.ru/api',[Na.TEST]:'https://apitest.ok.ru',[Na.AUTO]:''},$a={start:1e3,factor:1.5,max:3e5,random:.1};var Ka;!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'}(Ka||(Ka={}));class Ha{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const r=Da.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('')}(),Da.set('uuid',this.uuid))}authorize(t){return s(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 s(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)=>s(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 Ka.PARAM_SESSION_EXPIRED:case Ka.PARAM_SESSION_KEY:case Ka.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=yield this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;case Ka.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 s(this,void 0,void 0,(function*(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=xa(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.26',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,$a);return new Promise((e=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout((()=>{xa(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 s(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.26'.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=xa(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=>s(this,void 0,void 0,(function*(){this.sessionKey=void 0;const e=null==t?void 0:t.error_code;switch(e){case Ka.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 Qa(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 Wa=Qa({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),Ga=Wa?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(!Qa({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,Va=Wa?Ga.fetch:window.fetch;Wa?Ga.Request:window.Request;class Ya{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.isApiBaseUrlFetched=!1}resolveApiBaseUrl(){var t;return s(this,void 0,void 0,(function*(){if(this.apiEnv!==Na.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),r=yield Va(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[Na.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,r){return s(this,void 0,void 0,(function*(){const n=Date.now(),o=o=>{o instanceof TypeError&&['Failed to fetch','NetworkError when attempting to fetch resource.'].includes(o.message)?this.params.error$.next({id:'Network',message:'Request failed',thrown:o}):this.params.error$.next({id:'OneStat:ApiTransport:sendRequest',message:'Unhandled request error',thrown:o,data:{method:t,params:e,sessionKey:r,time:Date.now()-n}})};return this.apiBaseUrl=yield this.resolveApiBaseUrl(),Va(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:r})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),o):void 0),o)}))}_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 Ja{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=i((()=>{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()}}const Za=()=>Math.floor(Math.random()*Math.pow(2,32)).toString(36).padStart(8,'0');class Xa{constructor(t,e){var i;this.subscription=new r,this.vsid=Za(),this.fieldBlacklist=[],this.statContext=t,this.config=Object.assign(Object.assign({},null!==(i=e.config)&&void 0!==i?i:{}),{requestRetryCount:1});const s=new n;this.experimental={error$:s};const a=new Ya({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:Fa[e.apiEnv],apiEnv:e.apiEnv,error$:s});this.api=new Ha({apiTransport:a,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new Ja({api:this.api,error$:s}),this.subscription.add(o(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext=Object.assign(Object.assign({},this.statContext),t)}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=Za()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const r=Date.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?za.YES:!1===this.statContext.connectionReused?za.NO:void 0,stat_type:!0===this.statContext.autoplay?Ba.AUTO:!1===this.statContext.autoplay?Ba.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{Na as ApiEnv,Ma as ConnectionType,qa as ContentType,Xa as OneStat,La as Quality,Ua 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,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-beta.0',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-beta.0'.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};
|
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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/es2018.cjs.js');function e(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var s=e(require('lodash/debounce.js'));const o=(()=>{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,i,a,n,h,u,l,p={get:t=>function(t){const e=o?o.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{o&&o.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){o&&o.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,(i=exports.Quality||(exports.Quality={})).Q144P='144',i.Q240P='240',i.Q360P='360',i.Q480P='480',i.Q720P='720',i.Q1080P='1080',i.Q1440P='1440',i.Q2160P='2160',i.Q4320P='4320',i.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,(n=exports.ContentType||(exports.ContentType={})).MP4='mp4',n.DASH='dash',n.DASH_SEP='dash_sep',n.ONDEMAND_DASH='ondemand_dash',n.HLS='hls',n.ONDEMAND_HLS='ondemand_hls',n.WEBM='webm',n.RTMP='rtmp',n.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(h||(h={})),exports.ConnectionType=void 0,(u=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',u.HTTP2='http2',u.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(l||(l={}));const d={[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]:''},c={start:1e3,factor:1.5,max:3e5,random:.1};var m;!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'}(m||(m={}));class g{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,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=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),r=null!==(e=this.sessionKey)&&void 0!==e?e:await this._authorizeWithBackoff();if(!r)return;const i=async(t,e=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,r)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const r=null==o?void 0:o.error_code;switch(r){case m.PARAM_SESSION_EXPIRED:case m.PARAM_SESSION_KEY:case m.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;case m.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${r}`,message:`${s} error`,data:o})}}};return i(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.26',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t.getExponentialDelay(this.consequentAuthErrors,c);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.26'.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 m.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 f(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 y=f({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),A=y?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!f({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const r=new s(t,e);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=i&&i.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 r=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([r,a(t,e)])}return a(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,v=y?A.fetch:window.fetch;y?A.Request:window.Request;class _{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,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 v(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),r=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!r)throw new Error('Wrong DNS response');return r}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),d[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}),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:t,params:e}})}return!1}async sendRequest(t,e,s){const o=Date.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:e,sessionKey:s,time:Date.now()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),v(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:s})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r):void 0),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 w{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=s.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()}}const T=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0');exports.OneStat=class{constructor(e,s){var o;this.subscription=new t.Subscription,this.vsid=T(),this.fieldBlacklist=[],this.statContext=e,this.config={...null!==(o=s.config)&&void 0!==o?o:{},requestRetryCount:1};const r=new t.Subject;this.experimental={error$:r};const i=new _({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:d[s.apiEnv],apiEnv:s.apiEnv,error$:r});this.api=new g({apiTransport:i,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:r}),this.logger=new w({api:this.api,error$:r}),this.subscription.add(t.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}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=T()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const s=Date.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?h.AUTO:!1===this.statContext.autoplay?h.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}}};
|
|
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-beta.0',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-beta.0'.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}}};
|
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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as t,getExponentialDelay as e,Subscription as s,Subject as o,fromEvent as r}from'@vkontakte/videoplayer-shared/es2018.esm.js';import i from'lodash/debounce.js';const a=(()=>{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 n,h,u,l,d,c,p,m={get:t=>function(t){const e=a?a.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{a&&a.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){a&&a.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(n||(n={})),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'}(h||(h={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(u||(u={})),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'}(l||(l={})),function(t){t.AUTO='auto',t.MANUAL=''}(d||(d={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(c||(c={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(p||(p={}));const g={[n.PROD]:'https://api.ok.ru',[n.VK_ALIAS]:'https://api.mycdn.me',[n.VIDEOTEST]:'https://videotestapi.ok.ru/api',[n.TEST]:'https://apitest.ok.ru',[n.AUTO]:''},f={start:1e3,factor:1.5,max:3e5,random:.1};var y;!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'}(y||(y={}));class A{constructor(e){this.consequentAuthErrors=0,this.authorized$=new t(!1),this.params=e;const s=m.get('uuid');s?this.uuid=String(s):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),m.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),r=null!==(e=this.sessionKey)&&void 0!==e?e:await this._authorizeWithBackoff();if(!r)return;const i=async(t,e=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(s,o,r)}catch(o){if(!o||!('error_code'in o))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${s} error`,thrown:o});const r=null==o?void 0:o.error_code;switch(r){case y.PARAM_SESSION_EXPIRED:case y.PARAM_SESSION_KEY:case y.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;case y.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),e>0?i(t,e-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${r}`,message:`${s} error`,data:o})}}};return i(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.26',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,f);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.26'.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 y.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 _(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 w=_({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),v=w?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!_({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const r=new s(t,e);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=i&&i.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 r=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([r,a(t,e)])}return a(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,T=w?v.fetch:window.fetch;w?v.Request:window.Request;class S{constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){var t;if(this.apiEnv!==n.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const e=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),s=await T(e,{method:'GET',mode:'cors',cache:'no-cache'}),o=await s.json(),r=null===(t=null==o?void 0:o.Answer[0])||void 0===t?void 0:t.data;if(!r)throw new Error('Wrong DNS response');return r}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),g[n.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}),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:t,params:e}})}return!1}async sendRequest(t,e,s){const o=Date.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:e,sessionKey:s,time:Date.now()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),T(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:s})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r):void 0),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 P{constructor(t){this.requestQueue=[],this.isPaused=!1,this.debouncedFlush=i((()=>{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()}}const R=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0');class E{constructor(t,e){var i;this.subscription=new s,this.vsid=R(),this.fieldBlacklist=[],this.statContext=t,this.config={...null!==(i=e.config)&&void 0!==i?i:{},requestRetryCount:1};const a=new o;this.experimental={error$:a};const n=new S({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:g[e.apiEnv],apiEnv:e.apiEnv,error$:a});this.api=new A({apiTransport:n,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:a}),this.logger=new P({api:this.api,error$:a}),this.subscription.add(r(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}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=R()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const s=Date.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?d.AUTO:!1===this.statContext.autoplay?d.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{n as ApiEnv,c as ConnectionType,l as ContentType,E as OneStat,h as Quality,u 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,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-beta.0',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-beta.0'.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};
|
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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var t=require('@vkontakte/videoplayer-shared/esnext.cjs.js');function e(t){return t&&'object'==typeof t&&'default'in t?t:{default:t}}var s=e(require('lodash/debounce.js'));const o=(()=>{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,i,a,n,h,u,p,l={get:t=>function(t){const e=o?o.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{o&&o.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){o&&o.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,(i=exports.Quality||(exports.Quality={})).Q144P='144',i.Q240P='240',i.Q360P='360',i.Q480P='480',i.Q720P='720',i.Q1080P='1080',i.Q1440P='1440',i.Q2160P='2160',i.Q4320P='4320',i.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,(n=exports.ContentType||(exports.ContentType={})).MP4='mp4',n.DASH='dash',n.DASH_SEP='dash_sep',n.ONDEMAND_DASH='ondemand_dash',n.HLS='hls',n.ONDEMAND_HLS='ondemand_hls',n.WEBM='webm',n.RTMP='rtmp',n.UNKNOWN='unknown',function(t){t.AUTO='auto',t.MANUAL=''}(h||(h={})),exports.ConnectionType=void 0,(u=exports.ConnectionType||(exports.ConnectionType={})).HTTP1='http1',u.HTTP2='http2',u.HTTP3='http3',function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(p||(p={}));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]:''},d={start:1e3,factor:1.5,max:3e5,random:.1};var m;!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'}(m||(m={}));class g{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new t.ValueSubject(!1);backoffTimeoutId;constructor(t){this.params=t;const e=l.get('uuid');e?this.uuid=String(e):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),l.set('uuid',this.uuid))}async authorize(t){return this.authToken=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){const e='log.externalLog',s=this.createLogParams(t),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(t,i=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(e,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${e} error`,thrown:s});const o=s?.error_code;switch(o){case m.PARAM_SESSION_EXPIRED:case m.PARAM_SESSION_KEY:case m.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(t,i-1):void 0;case m.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(t,i-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${e} error`,data:s})}}};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.26',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const e=t.getExponentialDelay(this.consequentAuthErrors,d);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.26'.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=>(t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=t?.session_key??void 0,this.sessionKey))).catch((async t=>{this.sessionKey=void 0;const e=t?.error_code;switch(e){case m.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 f(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 y=f({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),A=y?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!f({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const r=new s(t,e);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=i&&i.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 r=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([r,a(t,e)])}return a(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,_=y?A.fetch:window.fetch;y?A.Request:window.Request;class w{apiKey;apiBaseUrl;apiEnv;isApiBaseUrlFetched;params;constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==exports.ApiEnv.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),e=await _(t,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await e.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}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}),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:t,params:e}})}return!1}async sendRequest(t,e,s){const o=Date.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:e,sessionKey:s,time:Date.now()-o}})};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:e,sessionKey:s})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r):void 0),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 v{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=s.default((()=>{try{this.flush()}catch(t){this.error$.next({id:'LoggerError',message:String(t)??'Unknown logger error',thrown:t})}}),3e3,{maxWait:15e3});constructor(t){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()}}const T=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0');exports.OneStat=class{api;logger;config;subscription=new t.Subscription;experimental;statContext;vsid=T();fieldBlacklist=[];constructor(e,s){this.statContext=e,this.config={...s.config??{},requestRetryCount:1};const o=new t.Subject;this.experimental={error$:o};const r=new w({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:c[s.apiEnv],apiEnv:s.apiEnv,error$:o});this.api=new g({apiTransport:r,refreshAuthToken:s.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:o}),this.logger=new v({api:this.api,error$:o}),this.subscription.add(t.fromEvent(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}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=T()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const s=Date.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?h.AUTO:!1===this.statContext.autoplay?h.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}}};
|
|
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-beta.0',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-beta.0'.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 b{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 w=()=>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 b;experimental;statContext;vsid=w();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=w()}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.27-beta.0
|
|
3
|
+
* Fri, 02 Dec 2022 10:16:04 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-27/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{ValueSubject as t,getExponentialDelay as e,Subscription as s,Subject as o,fromEvent as r}from'@vkontakte/videoplayer-shared/esnext.esm.js';import i from'lodash/debounce.js';const a=(()=>{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 n,h,u,l,c,d,p,m={get:t=>function(t){const e=a?a.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{a&&a.setItem('_one-stat_'+t,JSON.stringify(e))}catch(t){}}(t,e)},remove(t){!function(t){a&&a.removeItem('_one-stat_'+t)}(t)}};!function(t){t.PROD='prod',t.VK_ALIAS='vk_alias',t.VIDEOTEST='videotest',t.TEST='test',t.AUTO='auto'}(n||(n={})),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'}(h||(h={})),function(t){t.CHROMECAST='chromecast',t.APPLE_TV='appletv',t.PIP='pip',t.HEADPHONES='externalHeadphones',t.SCREEN=''}(u||(u={})),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'}(l||(l={})),function(t){t.AUTO='auto',t.MANUAL=''}(c||(c={})),function(t){t.HTTP1='http1',t.HTTP2='http2',t.HTTP3='http3'}(d||(d={})),function(t){t[t.YES=1]='YES',t[t.NO=0]='NO'}(p||(p={}));const g={[n.PROD]:'https://api.ok.ru',[n.VK_ALIAS]:'https://api.mycdn.me',[n.VIDEOTEST]:'https://videotestapi.ok.ru/api',[n.TEST]:'https://apitest.ok.ru',[n.AUTO]:''},f={start:1e3,factor:1.5,max:3e5,random:.1};var y;!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'}(y||(y={}));class A{params;uuid;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new t(!1);backoffTimeoutId;constructor(t){this.params=t;const e=m.get('uuid');e?this.uuid=String(e):(this.uuid=function(){const t='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''),e=new Array(36);let s,o,r=0;for(o=0;o<36;o++)8===o||13===o||18===o||23===o?e[o]='-':14===o?e[o]='4':(r<=2&&(r=33554432+16777216*Math.random()|0),s=15&r,r>>=4,e[o]=t[19===o?3&s|8:s]);return e.join('')}(),m.set('uuid',this.uuid))}async authorize(t){return this.authToken=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){const e='log.externalLog',s=this.createLogParams(t),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(t,i=this.params.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(e,s,o)}catch(s){if(!s||!('error_code'in s))return void this.params.error$.next({id:'logRequestUnknown',message:`Unknown ${e} error`,thrown:s});const o=s?.error_code;switch(o){case y.PARAM_SESSION_EXPIRED:case y.PARAM_SESSION_KEY:case y.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(t,i-1):void 0;case y.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),i>0?r(t,i-1):void 0;default:return void this.params.error$.next({id:`LogRequest#${o}`,message:`${e} error`,data:s})}}};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.26',platform:'WEB',items:t.map((t=>({...t,time:0,type:1})))})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=e(this.consequentAuthErrors,f);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.26'.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=>(t&&t.session_key||this.params.error$.next({id:'AuthorizeFailed',message:'No session key',data:t}),this.sessionKey=t?.session_key??void 0,this.sessionKey))).catch((async t=>{this.sessionKey=void 0;const e=t?.error_code;switch(e){case y.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 _(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 w=_({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),T=w?function(t){'function'==typeof t&&(t={fetch:t});const{fetch:e,Request:s=e.Request,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r=!1}=t;if(!_({fetch:e,Request:s,AbortController:o,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:r}))return{fetch:e,Request:i};let i=s;(i&&!i.prototype.hasOwnProperty('signal')||r)&&(i=function(t,e){let o;e&&e.signal&&(o=e.signal,delete e.signal);const r=new s(t,e);return o&&Object.defineProperty(r,'signal',{writable:!1,enumerable:!1,configurable:!0,value:o}),r},i.prototype=s.prototype);const a=e;return{fetch:(t,e)=>{const s=i&&i.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 r=new Promise(((t,e)=>{s.addEventListener('abort',(()=>e(o)),{once:!0})}));return e&&e.signal&&delete e.signal,Promise.race([r,a(t,e)])}return a(t,e)},Request:i}}({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,P=w?T.fetch:window.fetch;w?T.Request:window.Request;class S{apiKey;apiBaseUrl;apiEnv;isApiBaseUrlFetched;params;constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.apiEnv,this.apiBaseUrl=t.apiBaseUrl,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==n.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob('aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ='),e=await P(t,{method:'GET',mode:'cors',cache:'no-cache'}),s=(await e.json())?.Answer[0]?.data;if(!s)throw new Error('Wrong DNS response');return s}catch(t){return this.params.error$.next({id:'OneStat:ApiTransport:resolveApiBaseUrl',message:'Unhandled resolve api base url error',thrown:t}),g[n.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}),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:t,params:e}})}return!1}async sendRequest(t,e,s){const o=Date.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:e,sessionKey:s,time:Date.now()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),P(`${this.apiBaseUrl}/fb.do`,{method:'post',headers:{'Content-type':'application/x-www-form-urlencoded'},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:s})}).then((t=>Number(t.headers.get('content-length'))>0?t.json().then((t=>Object.prototype.hasOwnProperty.call(t,'error_msg')?Promise.reject(t):t),r):void 0),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 v{api;error$;requestQueue=[];subscription;isPaused=!1;debouncedFlush=i((()=>{try{this.flush()}catch(t){this.error$.next({id:'LoggerError',message:String(t)??'Unknown logger error',thrown:t})}}),3e3,{maxWait:15e3});constructor(t){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()}}const k=()=>Math.floor(Math.random()*2**32).toString(36).padStart(8,'0');class E{api;logger;config;subscription=new s;experimental;statContext;vsid=k();fieldBlacklist=[];constructor(t,e){this.statContext=t,this.config={...e.config??{},requestRetryCount:1};const s=new o;this.experimental={error$:s};const i=new S({apiKey:'CIOPGQJGDIHBABABA',apiBaseUrl:g[e.apiEnv],apiEnv:e.apiEnv,error$:s});this.api=new A({apiTransport:i,refreshAuthToken:e.refreshAuthToken,requestRetryCount:this.config.requestRetryCount,error$:s}),this.logger=new v({api:this.api,error$:s}),this.subscription.add(r(window,'beforeunload').subscribe((()=>this.logger.flush(!0))))}updateContext(t){this.statContext={...this.statContext,...t}}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=k()}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){this.log({operation:'watch_coverage_live',param:`${t.start}-${t.end}`}),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.crateLogItem(t);this.logger.log(e)}crateLogItem({operation:t,param:e}){const s=Date.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?c.AUTO:!1===this.statContext.autoplay?c.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{n as ApiEnv,d as ConnectionType,l as ContentType,E as OneStat,h as Quality,u 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,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-beta.0',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-beta.0'.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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/videoplayer-statistics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27-beta.0",
|
|
4
4
|
"author": "vk.com",
|
|
5
5
|
"description": "Statistics library for vk.com videoplayer",
|
|
6
6
|
"homepage": "https://vk.com",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@vkontakte/videoplayer-shared": "^1.0.17",
|
|
43
43
|
"lodash": "4.17.21"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@vkontakte/videoplayer-core": "^2.0.75-beta.0"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VideoFormat, VideoQuality, HttpConnectionType as CoreConnectionType } from '@vkontakte/videoplayer-core';
|
|
2
|
+
import { ContentType, Quality, ConnectionType as StatisticsConnectionType } from '../types';
|
|
3
|
+
export declare const quality: (coreQuality: VideoQuality | undefined) => Quality | undefined;
|
|
4
|
+
export declare const connectionType: (coreType: CoreConnectionType | undefined) => StatisticsConnectionType | undefined;
|
|
5
|
+
export declare const contentType: (format: VideoFormat | undefined) => ContentType | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Milliseconds } from '@vkontakte/videoplayer-shared';
|
|
2
|
+
export declare class TimeSynchronisation {
|
|
3
|
+
private offset;
|
|
4
|
+
constructor(initialOffset?: Milliseconds);
|
|
5
|
+
getOffset(): Milliseconds;
|
|
6
|
+
setOffset(offset: Milliseconds): void;
|
|
7
|
+
now(): number;
|
|
8
|
+
date(date?: Date): Date;
|
|
9
|
+
addServerTime(serverTime: Milliseconds, rtt: Milliseconds): void;
|
|
10
|
+
}
|