@vkontakte/videoplayer-statistics 1.0.49 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es2015.cjs.js +4 -4
- package/es2015.esm.js +4 -4
- package/es2018.cjs.js +4 -4
- package/es2018.esm.js +4 -4
- package/esnext.cjs.js +4 -4
- package/esnext.esm.js +4 -4
- package/evergreen.esm.js +4 -4
- package/package.json +8 -8
- package/types/Api.d.ts +38 -0
- package/types/ApiTransport.d.ts +26 -0
- package/types/Logger.d.ts +37 -0
- package/{index.d.ts → types/OneStat.d.ts} +21 -184
- package/types/config.d.ts +29 -0
- package/types/env.d.ts +7 -0
- package/types/index.d.ts +6 -0
- package/types/types.d.ts +43 -0
- package/types/uiEvents.d.ts +24 -0
- package/types/utils/mappers.d.ts +7 -0
- package/types/utils/shorten.d.ts +2 -0
- package/types/utils/timeSynchronisation.d.ts +10 -0
- package/types/utils/uuid.d.ts +1 -0
- package/types/utils/vsid.d.ts +2 -0
- package/types/utils/watchCoverage.d.ts +6 -0
- package/types/values.d.ts +85 -0
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.50
|
|
3
|
+
* Mon, 24 Jun 2024 13:02:45 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-50/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{fillWithDefault as ft,ValueSubject as C,getExponentialDelay as gt,ErrorCategory as b,now as p,debounceFn as Y,safeStorage as y,assertNever as nt,Observable as pt,Subscription as D,merge as I,fromEvent as Q,filterChanged as mt,map as bt,filter as X,Subject as k,isNullable as F,Logger as St,isNonNullable as x,detectEmbed as _t,once as Et,combine as J,observableFrom as At,assertNonNullable as wt}from"@vkontakte/videoplayer-shared/esnext.esm.js";import{Surface as L,VideoQuality as _,HttpConnectionType as V,VideoFormat as f,PlaybackState as Z}from"@vkontakte/videoplayer-core/esnext.esm.js";var E;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(E||(E={}));var m;(function(e){e.Q144P="mobile",e.Q240P="lowest",e.Q360P="low",e.Q480P="medium",e.Q720P="high",e.Q1080P="fullhd",e.Q1440P="quadhd",e.Q2160P="ultrahd",e.UNKNOWN="unknown"})(m||(m={}));var g;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.AV1="av1",e.ONDEMAND_DASH_LIVE="ondemand_dash_live",e.ONDEMAND_HLS_LIVE="ondemand_hls_live",e.WEBRTC="webrtc",e.UNKNOWN="unknown",e.RTMP="rtmp"})(g||(g={}));var B;(function(e){e.AUTO="auto",e.MANUAL=""})(B||(B={}));var O;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(O||(O={}));var A;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(A||(A={}));var $;(function(e){e.EXCELLENT="excellent",e.GOOD="good",e.POOR="poor"})($||($={}));var P;(function(e){e.PIP="pip",e.FULLSCREEN="fullscreen",e.EXTERNAL="external",e.PREFETCH="prefetch",e.AIRPLAY="airplay",e.CHROMECAST="chromecast",e.INVISIBLE="invisible"})(P||(P={}));var U;(function(e){e.SLIDER="slider",e.DOUBLE_TAP="double_tap",e.TIME_CODE="time_code",e.EPISODE="episode",e.REWIND="rewind",e.LIVE="live",e.UNKNOWN="unknown"})(U||(U={}));var tt;(function(e){e.GRAPH_SHOW="iGraphShow",e.GRAPH_HIDE="iGraphHide",e.NEXT_AREA="iNextChapterArea",e.NEXT_BUTTON="iNextChapterBtn",e.WATCH_AGAIN="iWatchAgainBtn"})(tt||(tt={}));const vt={action_play:"ap",action_play_interactive:"api",first_bytes:"fb",player_ready:"pr",first_frame:"ff",seek:"sk",watch_coverage_record:"wr",watch_coverage_live:"wl",empty_buffer:"eb",action_stop:"as",close_at_empty_buffer:"cb",content_error:"er",player_interface_click:"pc",next_movie:"nm",track_switch:"ts",failover:"fo"},yt={vsid:"si",isid:"is",vid:"vi",place:"pl",quality:"qt",cdn_host:"ch",stat_type:"st",param:"pm",vk_app_id:"va",track_code:"tc",connection_type:"cnt",connection_reused:"cr",cached_data:"cd",live:"lv",muted:"mu",mode:"mo",subtitles:"sb",failover:"fo",download_speed:"ds",manual_quality:"mq",ref_domain:"rd",direct_url:"du"},Pt={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},Tt={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv"},xt={apiEnv:E.VK_ALIAS,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:[],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1}},Lt=e=>ft(e,xt);function $t(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),t=new Array(36);let i=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?t[o]="-":o===14?t[o]="4":(i<=2&&(i=33554432+Math.random()*16777216|0),s=i&15,i=i>>4,t[o]=e[o===19?s&3|8:s]);return t.join("")}const Nt=e=>{const{operation:t,custom:i}=e,s=Object.fromEntries(Object.entries(i).map(([o,n])=>{const a=yt[o]??o;let u=n;return n&&(o==="mode"?u=Tt[n]??n:o==="quality"&&(u=Pt[n]??n)),[a,u]}));return{...e,operation:vt[t]??t,custom:s}},et="1.0.49",Ct="CIOPGQJGDIHBABABA",st={[E.PROD]:"https://api.ok.ru",[E.VK_ALIAS]:"https://api.mycdn.me",[E.VIDEOTEST]:"https://videotestapi.ok.ru/api",[E.TEST]:"https://apitest.ok.ru",[E.AUTO]:""};var T;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(T||(T={}));class Ot{params;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new C(!1);backoffTimeoutId;constructor(t){this.params=t}async authorize(t){return this.authToken=t??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(t){const i="log.externalLog",s=this.createLogParams(t),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(i,s,o)||this.logRequest(t)}async logRequest(t){const i="log.externalLog",s=this.createLogParams(t),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const n=async(a,u=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(i,s,o)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:b.NETWORK,message:`Unknown ${i} error`,thrown:h});return}const l=h?.error_code;switch(l){case T.PARAM_SESSION_EXPIRED:case T.PARAM_SESSION_KEY:case T.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),u>0?n(a,u-1):void 0;case T.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),u>0?n(a,u-1):void 0;default:{this.params.error$.next({id:`LogRequest#${l}`,category:b.EXTERNAL_API,message:`${i} error`,data:h});return}}}};return n(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:${et}`,platform:this.params.mobile?"M_WEB":"WEB",items:this.params.config.shorten?t.map(Nt):t})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=gt(this.consequentAuthErrors,this.params.config.backoff);return new Promise(i=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(i).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:b.NETWORK,message:"Otherwise unhandled error in authorization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},t))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t="auth.anonymLogin",i={session_data:{version:2,device_id:this.params.uuid,client_version:et.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(i.session_data.auth_token=this.authToken,i.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(t,i).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:b.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const o=s?.error_code;switch(o){case T.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:b.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:b.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class it{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(t,i,s){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:i,options:s})}removeEventListener(t,i){if(!(t in this.listeners))return;const s=this.listeners[t];for(let o=0,n=s.length;o<n;o++)if(s[o].callback===i){s.splice(o,1);return}}dispatchEvent(t){if(!(t.type in this.listeners))return;const s=this.listeners[t.type].slice();for(let o=0,n=s.length;o<n;o++){const a=s[o];try{a.callback.call(this,t)}catch(u){Promise.resolve().then(()=>{throw u})}a.options&&a.options.once&&this.removeEventListener(t.type,a.callback)}return!t.defaultPrevented}}class at extends it{constructor(){super(),this.listeners||it.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(t){t.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,t)),super.dispatchEvent(t)}}class Rt{constructor(){Object.defineProperty(this,"signal",{value:new at,writable:!0,configurable:!0})}abort(t){let i;try{i=new Event("abort")}catch{typeof document<"u"?document.createEvent?(i=document.createEvent("Event"),i.initEvent("abort",!1,!1)):(i=document.createEventObject(),i.type="abort"):i={type:"abort",bubbles:!1,cancelable:!1}}let s=t;if(s===void 0)if(typeof document>"u")s=new Error("This operation was aborted"),s.name="AbortError";else try{s=new DOMException("signal is aborted without reason")}catch{s=new Error("This operation was aborted"),s.name="AbortError"}this.signal.reason=s,this.signal.dispatchEvent(i)}toString(){return"[object AbortController]"}}typeof Symbol<"u"&&Symbol.toStringTag&&(Rt.prototype[Symbol.toStringTag]="AbortController",at.prototype[Symbol.toStringTag]="AbortSignal");function ct(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function It(e){typeof e=="function"&&(e={fetch:e});const{fetch:t,Request:i=t.Request,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=e;if(!ct({fetch:t,Request:i,AbortController:s,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:t,Request:n};let n=i;(n&&!n.prototype.hasOwnProperty("signal")||o)&&(n=function(l,r){let c;r&&r.signal&&(c=r.signal,delete r.signal);const d=new i(l,r);return c&&Object.defineProperty(d,"signal",{writable:!1,enumerable:!1,configurable:!0,value:c}),d},n.prototype=i.prototype);const a=t;return{fetch:(h,l)=>{const r=n&&n.prototype.isPrototypeOf(h)?h.signal:l?l.signal:void 0;if(r){let c;try{c=new DOMException("Aborted","AbortError")}catch{c=new Error("Aborted"),c.name="AbortError"}if(r.aborted)return Promise.reject(c);const d=new Promise((S,w)=>{r.addEventListener("abort",()=>w(c),{once:!0})});return l&&l.signal&&delete l.signal,Promise.race([d,a(h,l)])}return a(h,l)},Request:n}}const j=ct({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),ut=j?It({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,ot=j?ut.fetch:window.fetch;j?ut.Request:window.Request;class kt{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.config.apiEnv,this.apiBaseUrl=st[this.apiEnv],this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==E.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await ot(t,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:b.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),st[E.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(t,i,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:i,sessionKey:s}),n=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,n)}catch(a){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:b.NETWORK,message:"Unhandled beacon error",thrown:a,data:{method:t,params:i}})}return!1}async sendRequest(t,i,s){const o=p(),n=a=>{if(a instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(a.message)){this.params.error$.next({id:"Network",category:b.NETWORK,message:"Request failed",thrown:a});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:b.NETWORK,message:"Unhandled request error",thrown:a,data:{method:t,params:i,sessionKey:s,time:p()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),ot(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:i,sessionKey:s})}).then(a=>{const u=Number(a.headers.get("content-length"))===0,h=new Date(a.headers.get("date")??"").getTime(),l=p()-o;if(isFinite(h)&&this.timeSynchronisation?.addServerTime(h,l),!u)return a.json().then(r=>Object.prototype.hasOwnProperty.call(r,"error_msg")?Promise.reject(r):r,n)},n)}_prepareQueryParams(t){const i=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return t.sessionKey!==void 0&&i.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach(([s,o])=>i.append(s,typeof o=="string"?o:JSON.stringify(o))),i}}const R="onestat_events",H=e=>t=>t.timestamp+e>=p();class Dt{params;api;error$;subscription;userSalt;unsaltedStorage=[];lastVsid;isPaused=!1;firstFlush;debouncedFlush;loggerDebugLog;constructor(t){this.params=t,this.api=t.api,this.error$=t.error$,this.userSalt=t.userSalt,this.loggerDebugLog=t.debugLogger.createComponentLog("stat logger"),this.firstFlush=Y(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});const i=y.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=Y(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:i}),this.subscription=this.api.authorized$.subscribe(s=>{s&&this.debouncedFlush()}),this.housekeepStorage()}isUrgent=t=>{const{operation:i}=t;return["action_play","watch_coverage_record","watch_coverage_live"].includes(i)};safeFlush(){try{this.flush()}catch(t){this.error$.next({id:"LoggerError",category:b.WTF,message:String(t)??"Unknown logger error",thrown:t})}}readFromStorage(){const t=y.get(R);try{return t?JSON.parse(t):{}}catch{}return{}}addToStorage(t){if(!this.userSalt){this.unsaltedStorage.push(t);return}const i=this.readFromStorage(),o=(i[this.userSalt]??[]).filter(H(this.params.config.storageExpiration));y.set(R,JSON.stringify({...i,[this.userSalt]:[...o,t]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(H(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}const t=this.readFromStorage();delete t[this.userSalt],y.set(R,JSON.stringify(t))}housekeepStorage(){const t=this.readFromStorage();for(const[i,s]of Object.entries(t)){const o=s.filter(H(this.params.config.storageExpiration));o.length?t[i]=o:delete t[i],this.loggerDebugLog({message:`${s.length} retrieved from storage, ${o.length} of them actual`})}y.set(R,JSON.stringify(t))}log(t){this.addToStorage(t),!this.isPaused&&(this.isUrgent(t)?this.flush():this.lastVsid!==t.custom.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=t.custom.vsid)}flush(t=!1){const i=this.getFromStorage();i.length!==0&&(this.api.authorized$.getValue()?(t&&this.params.config.useBeacon?(this.loggerDebugLog({message:`Flushing ${i.length} events through beacon`}),this.api.logBeacon(i)):(this.loggerDebugLog({message:`Flushing ${i.length} events`}),this.api.logRequest(i)),this.markStorageSent()):this.api.authorize(),this.firstFlush.cancel(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe(),this.firstFlush.cancel(),this.debouncedFlush.cancel()}}const Ft=e=>e&&{[_.INVARIANT]:m.UNKNOWN,[_.Q_144P]:m.Q144P,[_.Q_240P]:m.Q240P,[_.Q_360P]:m.Q360P,[_.Q_480P]:m.Q480P,[_.Q_720P]:m.Q720P,[_.Q_1080P]:m.Q1080P,[_.Q_1440P]:m.Q1440P,[_.Q_2160P]:m.Q2160P,[_.Q_4320P]:m.UNKNOWN}[e],rt=e=>e&&{[V.HTTP1]:O.HTTP1,[V.HTTP2]:O.HTTP2,[V.QUIC]:O.HTTP3}[e],Bt=e=>{if(e!==void 0)switch(e){case f.MPEG:return g.MP4;case f.DASH_LIVE:return g.DASH;case f.DASH_SEP:return g.DASH_SEP;case f.DASH_ONDEMAND:return g.ONDEMAND_DASH;case f.DASH_WEBM:case f.DASH_LIVE_WEBM:return g.WEBM;case f.DASH_WEBM_AV1:return g.AV1;case f.DASH_LIVE_CMAF:return g.ONDEMAND_DASH_LIVE;case f.HLS:case f.HLS_LIVE:return g.HLS;case f.HLS_ONDEMAND:return g.ONDEMAND_HLS;case f.HLS_LIVE_CMAF:return g.ONDEMAND_HLS_LIVE;case f.WEB_RTC_LIVE:return g.WEBRTC;default:return nt(e)}},W=e=>{if(e!==void 0)switch(e){case L.NONE:case L.INLINE:return;case L.FULLSCREEN:return P.FULLSCREEN;case L.SECOND_SCREEN:return P.CHROMECAST;case L.PIP:return P.PIP;case L.INVISIBLE:return P.INVISIBLE;default:return nt(e)}},Ut=e=>{switch(e){case"slow-2g":return $.POOR;case"2g":return $.POOR;case"3g":return $.GOOD;case"4g":return $.EXCELLENT}};class qt{offset=void 0;constructor(t){this.offset=t}getOffset(){return this.offset??0}setOffset(t){this.offset=t}now(){return Date.now()+(this.offset??0)}date(t=new Date){return t.setTime(t.getTime()+(this.offset??0)),t}addServerTime(t,i){const s=Date.now(),o=t-s-i/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const Mt=()=>Math.floor(Math.random()*2**32).toString(36).padStart(7,"0"),Vt=()=>Math.floor(Math.random()*2**64).toString(36).padStart(13,"0"),Ht=(e,t)=>new pt(i=>{const s=new D,o=I(Q(window,"beforeunload"),e.events.willDestruct$),n=new C(void 0);let a;s.add(e.info.isLive$.pipe(mt()).subscribe(v=>{a&&(a.unsubscribe(),n.next(void 0)),v?a=e.info.liveTime$.pipe(bt(M=>M&&M/1e3)).subscribe(n):a=e.info.position$.subscribe(n),s.add(a)}));const{playing$:u,paused$:h}=e.events,l=e.events.willSeek$.pipe(X(()=>e.info.playbackState$.getValue()===Z.PLAYING)),r=e.events.seeked$.pipe(X(()=>e.info.playbackState$.getValue()===Z.PLAYING));let c=!1;const d=new k;s.add(l.subscribe(()=>{c||d.next(),c=!0})),s.add(r.subscribe(()=>c=!1));const S=new k,w=new k,q=I(u,r,S),G=I(h,d,o,e.events.looped$,w);let N;const ht=()=>N=n.getValue(),lt=()=>{const v=n.getValue();F(N)||N===v||F(v)||(i.next({from:N,to:v}),N=void 0)},dt=()=>{w.next(),S.next()};if(s.add(q.subscribe(ht)),s.add(G.subscribe(lt)),t.forceInterval&&isFinite(t.forceInterval)){let v=0;s.add(q.subscribe(()=>v=window.setTimeout(dt,t.forceInterval))),s.add(G.subscribe(()=>window.clearTimeout(v)))}return s}),Wt="_one-stat_",K=`${Wt}uuid`,z=()=>{const e=new D;return{subscription:e,subscribe:(t,i)=>{t&&e.add(t.subscribe(i))}}};class Qt{api;logger;config;subscription=new D;beforeunloadSubscription;timeSynchronisation;debugLogger=new St;oneStatDebugLog=this.debugLogger.createComponentLog("onestat");loopCounter=0;disabled=!1;experimental;vsid$=new C(void 0);isid$=new C(void 0);statContext;isEmbed;embedParent;uiEvents;player;seekAction$=new C(U.UNKNOWN);uuid;constructor(t,i){this.statContext=t,this.config=Lt(i.config??{}),x(i.apiEnv)&&(this.config.apiEnv=i.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new qt);const s=new k;this.experimental={error$:s};const o=y.get(K);o?o.startsWith('"')&&o.endsWith('"')?(this.uuid=o.replaceAll('"',""),y.set(K,this.uuid)):this.uuid=o:(this.uuid=$t(),y.set(K,this.uuid)),this.resetViewSession(),i.useIsid&&this.isid$.next(i.isid??Vt());const n=new kt({apiKey:Ct,config:this.config,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new Ot({config:this.config,apiTransport:n,refreshAuthToken:i.refreshAuthToken,mobile:this.statContext.mobile??!1,uuid:this.uuid,error$:s}),this.logger=new Dt({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:s,userSalt:i.userSalt});const{isEmbed:a,host:u}=_t();this.isEmbed=a,this.embedParent=u,this.subscribe()}updateContext(t){this.statContext={...this.statContext,...t}}attachTo(t){const i=new D,s=(r,c)=>i.add(r.subscribe(c));s(t.events.willStart$,()=>{const r=t.info.position$.getValue();this.logActionPlay({position:r}),this.statContext.projectId&&this.logActionPlayInteractive({position:r})}),s(t.events.looped$,()=>{this.resetViewSession(),++this.loopCounter>this.config.maxLoops&&(this.disabled=!0),this.logActionPlay({position:t.info.position$.getValue()})}),s(t.events.seeked$,()=>{this.logSeek({action:this.seekAction$.getValue(),time:t.info.position$.getValue()}),this.seekAction$.next(U.UNKNOWN)}),s(t.events.paused$,()=>{this.logPause({position:t.info.position$.getValue()})}),s(t.events.willResume$,()=>{this.logPlay()}),s(t.events.started$,()=>{this.statContext.clip&&this.logWatchCoverageRecord({start:0,end:0})}),s(Ht(t,{forceInterval:this.config.watchCoverageInterval}),r=>{const c=t.info.isLive$.getValue(),d={start:parseFloat(r.from.toFixed(3)),end:parseFloat(r.to.toFixed(3))};c?this.logWatchCoverageLive(d):this.logWatchCoverageRecord(d)});let o;s(t.info.isStalled$,r=>{r?o=p():(x(o)&&this.logEmptyBuffer({duration:p()-o}),o=void 0)});let n=!1;i.add(t.events.fatalError$.pipe(Et()).subscribe(()=>n=!0)),s(t.events.willStop$,()=>{if(t.info.isStalled$.getValue()){const c=x(o)?p()-o:void 0;this.logCloseAtEmptyBuffer({duration:c??0}),o=void 0}else n||this.logActionStop()}),s(t.events.managedError$,({id:r})=>{this.logError({fatal:!1,errorType:r})}),s(t.events.fatalError$,({id:r})=>{this.logError({fatal:!0,errorType:r})});let a,u,h=!1;s(t.events.firstBytes$,r=>{a=p(),this.logFirstBytes({time:r})}),s(t.events.willStart$,()=>u=p()),s(t.info.currentBuffer$,r=>{!h&&r&&r.end-r.start>0&&x(a)&&(this.logPlayerReady({duration:p()-a}),h=!0)}),s(t.events.firstFrame$,()=>{x(a)&&!h&&(this.logPlayerReady({duration:p()-a}),h=!0),x(u)&&this.logFirstFrame({time:p()-u})}),s(t.info.atLiveEdge$,r=>this.updateContext({liveEdge:r})),s(J({muted:t.info.muted$,volume:t.info.volume$}),({muted:r,volume:c})=>this.updateContext({audible:!r&&c>0})),s(t.info.currentQuality$,r=>this.updateContext({quality:Ft(r)})),s(t.info.isAutoQualityEnabled$,r=>this.updateContext({autoQuality:r})),s(t.info.currentFormat$,r=>this.updateContext({contentType:Bt(r)})),s(t.info.currentPlaybackRate$,r=>this.updateContext({rate:r})),s(t.info.is3DVideo$,r=>this.updateContext({is3d:r}));let l;return s(t.info.hostname$,r=>{const c=l!==void 0&&l!==r;this.updateContext({cdnHostname:r,failover:c}),c&&this.logFailover(r),l=r}),s(t.info.throughputEstimation$,r=>this.updateContext({downloadSpeed:r})),s(t.info.httpConnectionType$,r=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:rt(r)}),this.updateContext({connectionType:rt(r)})}),s(t.info.httpConnectionReused$,r=>{F(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:r}),this.updateContext({connectionReused:r})}),s(t.info.surface$,r=>this.updateContext({mode:W(r)})),s(J({current:t.info.currentTextTrack$,available:t.info.availableTextTracks$}),({current:r,available:c})=>{const d=c.find(({id:w})=>w===r),S=d&&(d.isAuto?`${d.language}_auto`:d.language);this.updateContext({subtitles:S})}),this.player=t,this.uiEvents&&this.attachToUi(this.uiEvents),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToUi(t){this.uiEvents=t;const{subscription:i,subscribe:s}=z();return this.player&&(s(t.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),s(t.actionSeek$,this.seekAction$),s(t.inPiP$,o=>{const n=o?P.PIP:W(this.player?.info.surface$.getValue());this.updateContext({mode:n})}),s(t.inFullscreen$,o=>{const n=o?P.FULLSCREEN:W(this.player?.info.surface$.getValue());this.updateContext({mode:n})}),s(t.actionSetSubtitle$,o=>this.updateContext({subtitles:o})),s(t.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i)),i}attachToAds(t){const{subscription:i,subscribe:s}=z();return s(t.slotRequested$,()=>this.logAdSlotRequest()),s(t.started$,o=>this.logAdStarted(o)),s(t.paused$,()=>this.logAdPaused()),s(t.resumed$,()=>this.logAdResumed()),s(t.ended$,()=>this.logAdEnded()),s(t.skipped$,()=>this.logAdSkipped()),s(t.clicked$,()=>this.logAdClicked()),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToInteractive(t){const{subscription:i,subscribe:s}=z();return s(t.click$,o=>this.logInterfaceClick(o)),s(t.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i),i}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause(),this.oneStatDebugLog({message:"paused"})}resume(){this.logger.resume(),this.oneStatDebugLog({message:"resumed"})}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.oneStatDebugLog({message:"VSID reset"}),this.vsid$.next(Mt())}getDeviceId(){return this.uuid}setFieldBlacklist(){}logInited(){}logReady(t){this.log({operation:"player_ready",param:String(t.time)})}logStarted(...t){this.logActionPlay(...t)}logPlay(){this.log({operation:"play_toggle"})}logPause(t){this.log({operation:"pause",param:String(Math.round(t.position))})}logSeek(t){this.log({operation:"seek",param:t.action,time:t.time})}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:"content_error",param:`${t.fatal?"fatal":"recoverable"}_${t.errorType}`})}logWatchCoverageRecord(t){this.log({operation:"watch_coverage_record",param:`${t.start}-${t.end}`})}logWatchCoverageLive(t){const i=this.timeSynchronisation?.getOffset()??0,s=t.start+i,o=t.end+i;this.log({operation:"watch_coverage_live",param:`${s}-${o}`})}logEmptyBuffer(t){this.log({operation:"empty_buffer",param:String(t.duration)})}logDownloadSpeed(){}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"})}logInterfaceClick(t){this.log({operation:"player_interface_click",param:t})}logNextMovie(t){this.log({operation:"next_movie",param:String(t)})}subscribe(){this.resubscribeBeforeunload();const t=window.navigator.connection;t&&"onchange"in t&&"effectiveType"in t&&this.subscription.add(I(Q(t,"change"),At(["init"])).subscribe(()=>this.updateContext({network:Ut(t.effectiveType)}))),this.config.debugLog&&this.debugLogger.log$.subscribe(i=>{console.debug("%c stat ","background:#fa6470;",`component: ${i.component}.`,i.message)})}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=Q(window,"beforeunload").subscribe(()=>this.logger.flush(!0)),this.subscription.add(this.beforeunloadSubscription)}logPlayerReady(t){this.log({operation:"player_ready",param:String(Math.round(t.duration))})}logActionPlay(t){this.log({operation:"action_play",param:String(Math.round(t.position))})}logActionPlayInteractive(t){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(Math.round(t.position))},{vid:this.statContext.projectId})}logFailover(t){this.log({operation:"failover",param:t})}logCloseAtEmptyBuffer(t){this.log({operation:"close_at_empty_buffer",param:String(Math.round(t.duration))})}logActionStop(){this.log({operation:"action_stop"})}log(t,i={}){if(this.disabled){this.oneStatDebugLog({message:`operation ${t.operation} but statistics is disabled`});return}if(this.config.disabledOperations.includes(t.operation)){this.oneStatDebugLog({message:`operation ${t.operation} but it is disabled`});return}this.oneStatDebugLog({message:`operation ${t.operation} ${t.param}`});const s=this.createLogItem(t,i);this.logger.log(s)}createLogItem({operation:t,param:i,time:s},o={}){const n=this.timeSynchronisation?.now()??p(),a=this.vsid$.getValue();wt(a);const u=this.isid$.getValue(),h=t==="empty_buffer"||t==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,l=this.statContext.firstConnectionReused;let r,c;if(this.isEmbed){r=this.embedParent;const S=[...new URLSearchParams(location.search).entries()].filter(([w,q])=>this.config.embedUrlParams.includes(w));c=new URLSearchParams(S).toString()}else this.statContext.place==="direct"&&((this.statContext.refDomain||document.referrer)&&(r=new URL(this.statContext.refDomain||document.referrer).hostname),c=location.href.substring(0,1024));const d={vsid:a,isid:u,vid:this.statContext.movieId,ct:this.statContext.contentType,place:this.isEmbed?"embed":this.statContext.place,quality:this.statContext.quality,cdn_host:this.statContext.cdnHostname,stat_type:this.statContext.autoplay===!0?B.AUTO:this.statContext.autoplay===!1?B.MANUAL:void 0,param:i,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode,connection_type:h,connection_reused:l===!0?A.YES:l===!1?A.NO:void 0,cached_data:this.statContext.cached===!0?A.YES:this.statContext.cached===!1?A.NO:void 0,live:this.statContext.liveEdge?A.YES:void 0,muted:this.statContext.audible===!1?A.YES:void 0,mode:this.statContext.mode,subtitles:this.statContext.subtitles,download_speed:this.statContext.downloadSpeed,manual_quality:this.statContext.autoQuality?void 0:A.YES,ref_domain:r,direct_url:c,rate:this.statContext.rate===1||F(this.statContext.rate)?void 0:this.statContext.rate.toFixed(2),view_360:this.statContext.is3d?1:void 0,aid:this.statContext.albumId,vk_playlist_id:this.statContext.vkPlaylistId,...o};for(const S of this.config.disabledCustomFields)delete d[S];return{operation:t,type:1,time:s,network:this.statContext.network,timestamp:n,custom:d}}}export{E as ApiEnv,O as ConnectionType,g as ContentType,tt as InteractiveInterfaceClick,Qt as OneStat,m as Quality,U as SeekAction,et as VERSION};
|
|
6
|
+
var Il=Object.create;var Ki=Object.defineProperty;var El=Object.getOwnPropertyDescriptor;var ql=Object.getOwnPropertyNames;var Pl=Object.getPrototypeOf,Tl=Object.prototype.hasOwnProperty;var n=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Ol=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ql(e))!Tl.call(r,o)&&o!==t&&Ki(r,o,{get:()=>e[o],enumerable:!(i=El(e,o))||i.enumerable});return r};var Lr=(r,e,t)=>(t=r!=null?Il(Pl(r)):{},Ol(e||!r||!r.__esModule?Ki(t,"default",{value:r,enumerable:!0}):t,r));var Wi=n(()=>{"use strict"});var Hi=n(()=>{"use strict"});var I=n((zi,Qi)=>{"use strict";var Be=function(r){return r&&r.Math==Math&&r};Qi.exports=Be(typeof globalThis=="object"&&globalThis)||Be(typeof window=="object"&&window)||Be(typeof self=="object"&&self)||Be(typeof global=="object"&&global)||function(){return this}()||zi||Function("return this")()});var T=n((Kb,Yi)=>{"use strict";Yi.exports=function(r){try{return!!r()}catch{return!0}}});var me=n((Wb,Ji)=>{"use strict";var _l=T();Ji.exports=!_l(function(){var r=function(){}.bind();return typeof r!="function"||r.hasOwnProperty("prototype")})});var kr=n((Hb,ro)=>{"use strict";var xl=me(),eo=Function.prototype,Xi=eo.apply,Zi=eo.call;ro.exports=typeof Reflect=="object"&&Reflect.apply||(xl?Zi.bind(Xi):function(){return Zi.apply(Xi,arguments)})});var q=n((zb,oo)=>{"use strict";var to=me(),io=Function.prototype,Dr=io.call,Rl=to&&io.bind.bind(Dr,Dr);oo.exports=to?Rl:function(r){return function(){return Dr.apply(r,arguments)}}});var J=n((Qb,ao)=>{"use strict";var no=q(),wl=no({}.toString),Al=no("".slice);ao.exports=function(r){return Al(wl(r),8,-1)}});var $r=n((Yb,so)=>{"use strict";var Cl=J(),Nl=q();so.exports=function(r){if(Cl(r)==="Function")return Nl(r)}});var jr=n((Jb,uo)=>{"use strict";var Mr=typeof document=="object"&&document.all,Ll=typeof Mr>"u"&&Mr!==void 0;uo.exports={all:Mr,IS_HTMLDDA:Ll}});var g=n((Xb,lo)=>{"use strict";var co=jr(),kl=co.all;lo.exports=co.IS_HTMLDDA?function(r){return typeof r=="function"||r===kl}:function(r){return typeof r=="function"}});var L=n((Zb,fo)=>{"use strict";var Dl=T();fo.exports=!Dl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!=7})});var P=n((ey,po)=>{"use strict";var $l=me(),Ue=Function.prototype.call;po.exports=$l?Ue.bind(Ue):function(){return Ue.apply(Ue,arguments)}});var mo=n(go=>{"use strict";var vo={}.propertyIsEnumerable,ho=Object.getOwnPropertyDescriptor,Ml=ho&&!vo.call({1:2},1);go.f=Ml?function(e){var t=ho(this,e);return!!t&&t.enumerable}:vo});var be=n((ty,bo)=>{"use strict";bo.exports=function(r,e){return{enumerable:!(r&1),configurable:!(r&2),writable:!(r&4),value:e}}});var So=n((iy,yo)=>{"use strict";var jl=q(),Fl=T(),Bl=J(),Fr=Object,Ul=jl("".split);yo.exports=Fl(function(){return!Fr("z").propertyIsEnumerable(0)})?function(r){return Bl(r)=="String"?Ul(r,""):Fr(r)}:Fr});var X=n((oy,Io)=>{"use strict";Io.exports=function(r){return r==null}});var Ve=n((ny,Eo)=>{"use strict";var Vl=X(),Gl=TypeError;Eo.exports=function(r){if(Vl(r))throw Gl("Can't call method on "+r);return r}});var Z=n((ay,qo)=>{"use strict";var Kl=So(),Wl=Ve();qo.exports=function(r){return Kl(Wl(r))}});var k=n((sy,Oo)=>{"use strict";var Po=g(),To=jr(),Hl=To.all;Oo.exports=To.IS_HTMLDDA?function(r){return typeof r=="object"?r!==null:Po(r)||r===Hl}:function(r){return typeof r=="object"?r!==null:Po(r)}});var Ge=n((uy,_o)=>{"use strict";_o.exports={}});var $=n((cy,Ro)=>{"use strict";var Br=Ge(),Ur=I(),zl=g(),xo=function(r){return zl(r)?r:void 0};Ro.exports=function(r,e){return arguments.length<2?xo(Br[r])||xo(Ur[r]):Br[r]&&Br[r][e]||Ur[r]&&Ur[r][e]}});var ye=n((ly,wo)=>{"use strict";var Ql=q();wo.exports=Ql({}.isPrototypeOf)});var Se=n((fy,Ao)=>{"use strict";Ao.exports=typeof navigator<"u"&&String(navigator.userAgent)||""});var Gr=n((dy,$o)=>{"use strict";var Do=I(),Vr=Se(),Co=Do.process,No=Do.Deno,Lo=Co&&Co.versions||No&&No.version,ko=Lo&&Lo.v8,x,Ke;ko&&(x=ko.split("."),Ke=x[0]>0&&x[0]<4?1:+(x[0]+x[1]));!Ke&&Vr&&(x=Vr.match(/Edge\/(\d+)/),(!x||x[1]>=74)&&(x=Vr.match(/Chrome\/(\d+)/),x&&(Ke=+x[1])));$o.exports=Ke});var Kr=n((py,jo)=>{"use strict";var Mo=Gr(),Yl=T(),Jl=I(),Xl=Jl.String;jo.exports=!!Object.getOwnPropertySymbols&&!Yl(function(){var r=Symbol();return!Xl(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&Mo&&Mo<41})});var Wr=n((vy,Fo)=>{"use strict";var Zl=Kr();Fo.exports=Zl&&!Symbol.sham&&typeof Symbol.iterator=="symbol"});var Hr=n((hy,Bo)=>{"use strict";var ef=$(),rf=g(),tf=ye(),of=Wr(),nf=Object;Bo.exports=of?function(r){return typeof r=="symbol"}:function(r){var e=ef("Symbol");return rf(e)&&tf(e.prototype,nf(r))}});var Ie=n((gy,Uo)=>{"use strict";var af=String;Uo.exports=function(r){try{return af(r)}catch{return"Object"}}});var M=n((my,Vo)=>{"use strict";var sf=g(),uf=Ie(),cf=TypeError;Vo.exports=function(r){if(sf(r))return r;throw cf(uf(r)+" is not a function")}});var Ee=n((by,Go)=>{"use strict";var lf=M(),ff=X();Go.exports=function(r,e){var t=r[e];return ff(t)?void 0:lf(t)}});var Wo=n((yy,Ko)=>{"use strict";var zr=P(),Qr=g(),Yr=k(),df=TypeError;Ko.exports=function(r,e){var t,i;if(e==="string"&&Qr(t=r.toString)&&!Yr(i=zr(t,r))||Qr(t=r.valueOf)&&!Yr(i=zr(t,r))||e!=="string"&&Qr(t=r.toString)&&!Yr(i=zr(t,r)))return i;throw df("Can't convert object to primitive value")}});var R=n((Sy,Ho)=>{"use strict";Ho.exports=!0});var Yo=n((Iy,Qo)=>{"use strict";var zo=I(),pf=Object.defineProperty;Qo.exports=function(r,e){try{pf(zo,r,{value:e,configurable:!0,writable:!0})}catch{zo[r]=e}return e}});var We=n((Ey,Xo)=>{"use strict";var vf=I(),hf=Yo(),Jo="__core-js_shared__",gf=vf[Jo]||hf(Jo,{});Xo.exports=gf});var Jr=n((qy,en)=>{"use strict";var mf=R(),Zo=We();(en.exports=function(r,e){return Zo[r]||(Zo[r]=e!==void 0?e:{})})("versions",[]).push({version:"3.31.0",mode:mf?"pure":"global",copyright:"\xA9 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.31.0/LICENSE",source:"https://github.com/zloirock/core-js"})});var He=n((Py,rn)=>{"use strict";var bf=Ve(),yf=Object;rn.exports=function(r){return yf(bf(r))}});var w=n((Ty,tn)=>{"use strict";var Sf=q(),If=He(),Ef=Sf({}.hasOwnProperty);tn.exports=Object.hasOwn||function(e,t){return Ef(If(e),t)}});var Xr=n((Oy,on)=>{"use strict";var qf=q(),Pf=0,Tf=Math.random(),Of=qf(1 .toString);on.exports=function(r){return"Symbol("+(r===void 0?"":r)+")_"+Of(++Pf+Tf,36)}});var E=n((_y,an)=>{"use strict";var _f=I(),xf=Jr(),nn=w(),Rf=Xr(),wf=Kr(),Af=Wr(),ee=_f.Symbol,Zr=xf("wks"),Cf=Af?ee.for||ee:ee&&ee.withoutSetter||Rf;an.exports=function(r){return nn(Zr,r)||(Zr[r]=wf&&nn(ee,r)?ee[r]:Cf("Symbol."+r)),Zr[r]}});var ln=n((xy,cn)=>{"use strict";var Nf=P(),sn=k(),un=Hr(),Lf=Ee(),kf=Wo(),Df=E(),$f=TypeError,Mf=Df("toPrimitive");cn.exports=function(r,e){if(!sn(r)||un(r))return r;var t=Lf(r,Mf),i;if(t){if(e===void 0&&(e="default"),i=Nf(t,r,e),!sn(i)||un(i))return i;throw $f("Can't convert object to primitive value")}return e===void 0&&(e="number"),kf(r,e)}});var ze=n((Ry,fn)=>{"use strict";var jf=ln(),Ff=Hr();fn.exports=function(r){var e=jf(r,"string");return Ff(e)?e:e+""}});var Qe=n((wy,pn)=>{"use strict";var Bf=I(),dn=k(),et=Bf.document,Uf=dn(et)&&dn(et.createElement);pn.exports=function(r){return Uf?et.createElement(r):{}}});var rt=n((Ay,vn)=>{"use strict";var Vf=L(),Gf=T(),Kf=Qe();vn.exports=!Vf&&!Gf(function(){return Object.defineProperty(Kf("div"),"a",{get:function(){return 7}}).a!=7})});var tt=n(gn=>{"use strict";var Wf=L(),Hf=P(),zf=mo(),Qf=be(),Yf=Z(),Jf=ze(),Xf=w(),Zf=rt(),hn=Object.getOwnPropertyDescriptor;gn.f=Wf?hn:function(e,t){if(e=Yf(e),t=Jf(t),Zf)try{return hn(e,t)}catch{}if(Xf(e,t))return Qf(!Hf(zf.f,e,t),e[t])}});var it=n((Ny,mn)=>{"use strict";var ed=T(),rd=g(),td=/#|\.prototype\./,qe=function(r,e){var t=od[id(r)];return t==ad?!0:t==nd?!1:rd(e)?ed(e):!!e},id=qe.normalize=function(r){return String(r).replace(td,".").toLowerCase()},od=qe.data={},nd=qe.NATIVE="N",ad=qe.POLYFILL="P";mn.exports=qe});var Pe=n((Ly,yn)=>{"use strict";var bn=$r(),sd=M(),ud=me(),cd=bn(bn.bind);yn.exports=function(r,e){return sd(r),e===void 0?r:ud?cd(r,e):function(){return r.apply(e,arguments)}}});var ot=n((ky,Sn)=>{"use strict";var ld=L(),fd=T();Sn.exports=ld&&fd(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!=42})});var A=n((Dy,In)=>{"use strict";var dd=k(),pd=String,vd=TypeError;In.exports=function(r){if(dd(r))return r;throw vd(pd(r)+" is not an object")}});var V=n(qn=>{"use strict";var hd=L(),gd=rt(),md=ot(),Ye=A(),En=ze(),bd=TypeError,nt=Object.defineProperty,yd=Object.getOwnPropertyDescriptor,at="enumerable",st="configurable",ut="writable";qn.f=hd?md?function(e,t,i){if(Ye(e),t=En(t),Ye(i),typeof e=="function"&&t==="prototype"&&"value"in i&&ut in i&&!i[ut]){var o=yd(e,t);o&&o[ut]&&(e[t]=i.value,i={configurable:st in i?i[st]:o[st],enumerable:at in i?i[at]:o[at],writable:!1})}return nt(e,t,i)}:nt:function(e,t,i){if(Ye(e),t=En(t),Ye(i),gd)try{return nt(e,t,i)}catch{}if("get"in i||"set"in i)throw bd("Accessors not supported");return"value"in i&&(e[t]=i.value),e}});var G=n((My,Pn)=>{"use strict";var Sd=L(),Id=V(),Ed=be();Pn.exports=Sd?function(r,e,t){return Id.f(r,e,Ed(1,t))}:function(r,e,t){return r[e]=t,r}});var C=n((jy,On)=>{"use strict";var Je=I(),qd=kr(),Pd=$r(),Td=g(),Od=tt().f,_d=it(),re=Ge(),xd=Pe(),te=G(),Tn=w(),Rd=function(r){var e=function(t,i,o){if(this instanceof e){switch(arguments.length){case 0:return new r;case 1:return new r(t);case 2:return new r(t,i)}return new r(t,i,o)}return qd(r,this,arguments)};return e.prototype=r.prototype,e};On.exports=function(r,e){var t=r.target,i=r.global,o=r.stat,s=r.proto,u=i?Je:o?Je[t]:(Je[t]||{}).prototype,c=i?re:re[t]||te(re,t,{})[t],p=c.prototype,f,a,d,v,l,h,m,y,b;for(v in e)f=_d(i?v:t+(o?".":"#")+v,r.forced),a=!f&&u&&Tn(u,v),h=c[v],a&&(r.dontCallGetSet?(b=Od(u,v),m=b&&b.value):m=u[v]),l=a&&m?m:e[v],!(a&&typeof h==typeof l)&&(r.bind&&a?y=xd(l,Je):r.wrap&&a?y=Rd(l):s&&Td(l)?y=Pd(l):y=l,(r.sham||l&&l.sham||h&&h.sham)&&te(y,"sham",!0),te(c,v,y),s&&(d=t+"Prototype",Tn(re,d)||te(re,d,{}),te(re[d],v,l),r.real&&p&&(f||!p[v])&&te(p,v,l)))}});var xn=n((Fy,_n)=>{"use strict";var wd=k(),Ad=J(),Cd=E(),Nd=Cd("match");_n.exports=function(r){var e;return wd(r)&&((e=r[Nd])!==void 0?!!e:Ad(r)=="RegExp")}});var Xe=n((By,wn)=>{"use strict";var Ld=E(),kd=Ld("toStringTag"),Rn={};Rn[kd]="z";wn.exports=String(Rn)==="[object z]"});var ie=n((Uy,An)=>{"use strict";var Dd=Xe(),$d=g(),Ze=J(),Md=E(),jd=Md("toStringTag"),Fd=Object,Bd=Ze(function(){return arguments}())=="Arguments",Ud=function(r,e){try{return r[e]}catch{}};An.exports=Dd?Ze:function(r){var e,t,i;return r===void 0?"Undefined":r===null?"Null":typeof(t=Ud(e=Fd(r),jd))=="string"?t:Bd?Ze(e):(i=Ze(e))=="Object"&&$d(e.callee)?"Arguments":i}});var Nn=n((Vy,Cn)=>{"use strict";var Vd=ie(),Gd=String;Cn.exports=function(r){if(Vd(r)==="Symbol")throw TypeError("Cannot convert a Symbol value to a string");return Gd(r)}});var kn=n((Gy,Ln)=>{"use strict";var Kd=A();Ln.exports=function(){var r=Kd(this),e="";return r.hasIndices&&(e+="d"),r.global&&(e+="g"),r.ignoreCase&&(e+="i"),r.multiline&&(e+="m"),r.dotAll&&(e+="s"),r.unicode&&(e+="u"),r.unicodeSets&&(e+="v"),r.sticky&&(e+="y"),e}});var Mn=n((Ky,$n)=>{"use strict";var Wd=P(),Hd=w(),zd=ye(),Qd=kn(),Dn=RegExp.prototype;$n.exports=function(r){var e=r.flags;return e===void 0&&!("flags"in Dn)&&!Hd(r,"flags")&&zd(Dn,r)?Wd(Qd,r):e}});var Fn=n((Wy,jn)=>{"use strict";var ft=q(),Yd=He(),Jd=Math.floor,ct=ft("".charAt),Xd=ft("".replace),lt=ft("".slice),Zd=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,ep=/\$([$&'`]|\d{1,2})/g;jn.exports=function(r,e,t,i,o,s){var u=t+r.length,c=i.length,p=ep;return o!==void 0&&(o=Yd(o),p=Zd),Xd(s,p,function(f,a){var d;switch(ct(a,0)){case"$":return"$";case"&":return r;case"`":return lt(e,0,t);case"'":return lt(e,u);case"<":d=o[lt(a,1,-1)];break;default:var v=+a;if(v===0)return f;if(v>c){var l=Jd(v/10);return l===0?f:l<=c?i[l-1]===void 0?ct(a,1):i[l-1]+ct(a,1):f}d=i[v-1]}return d===void 0?"":d})}});var Kn=n(()=>{"use strict";var rp=C(),tp=P(),dt=q(),Bn=Ve(),ip=g(),op=X(),np=xn(),oe=Nn(),ap=Ee(),sp=Mn(),up=Fn(),cp=E(),lp=R(),fp=cp("replace"),dp=TypeError,Gn=dt("".indexOf),pp=dt("".replace),Un=dt("".slice),vp=Math.max,Vn=function(r,e,t){return t>r.length?-1:e===""?t:Gn(r,e,t)};rp({target:"String",proto:!0},{replaceAll:function(e,t){var i=Bn(this),o,s,u,c,p,f,a,d,v,l=0,h=0,m="";if(!op(e)){if(o=np(e),o&&(s=oe(Bn(sp(e))),!~Gn(s,"g")))throw dp("`.replaceAll` does not allow non-global regexes");if(u=ap(e,fp),u)return tp(u,e,i,t);if(lp&&o)return pp(oe(i),e,t)}for(c=oe(i),p=oe(e),f=ip(t),f||(t=oe(t)),a=p.length,d=vp(1,a),l=Vn(c,p,0);l!==-1;)v=f?oe(t(p,l,c)):up(p,c,l,[],void 0,t),m+=Un(c,h,l)+v,h=l+a,l=Vn(c,p,l+d);return h<c.length&&(m+=Un(c,h)),m}})});var pt=n((Qy,Wn)=>{"use strict";var hp=$();Wn.exports=hp});var zn=n((Yy,Hn)=>{"use strict";Wi();Hi();Kn();var gp=pt();Hn.exports=gp("String","replaceAll")});var Yn=n((Jy,Qn)=>{"use strict";var mp=zn();Qn.exports=mp});var Xn=n((Xy,Jn)=>{"use strict";var bp=Yn();Jn.exports=bp});var na=n(()=>{"use strict"});var Oe=n((uS,aa)=>{"use strict";var Ip=J();aa.exports=typeof process<"u"&&Ip(process)=="process"});var ne=n((cS,sa)=>{"use strict";var Ep=G();sa.exports=function(r,e,t,i){return i&&i.enumerable?r[e]=t:Ep(r,e,t),r}});var ca=n((lS,ua)=>{"use strict";var qp=q(),Pp=M();ua.exports=function(r,e,t){try{return qp(Pp(Object.getOwnPropertyDescriptor(r,e)[t]))}catch{}}});var fa=n((fS,la)=>{"use strict";var Tp=g(),Op=String,_p=TypeError;la.exports=function(r){if(typeof r=="object"||Tp(r))return r;throw _p("Can't set "+Op(r)+" as a prototype")}});var yt=n((dS,da)=>{"use strict";var xp=ca(),Rp=A(),wp=fa();da.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var r=!1,e={},t;try{t=xp(Object.prototype,"__proto__","set"),t(e,[]),r=e instanceof Array}catch{}return function(o,s){return Rp(o),wp(s),r?t(o,s):o.__proto__=s,o}}():void 0)});var va=n((pS,pa)=>{"use strict";var Ap=Xe(),Cp=ie();pa.exports=Ap?{}.toString:function(){return"[object "+Cp(this)+"]"}});var er=n((vS,ga)=>{"use strict";var Np=Xe(),Lp=V().f,kp=G(),Dp=w(),$p=va(),Mp=E(),ha=Mp("toStringTag");ga.exports=function(r,e,t,i){if(r){var o=t?r:r.prototype;Dp(o,ha)||Lp(o,ha,{configurable:!0,value:e}),i&&!Np&&kp(o,"toString",$p)}}});var ba=n((hS,ma)=>{"use strict";var jp=V();ma.exports=function(r,e,t){return jp.f(r,e,t)}});var Ia=n((gS,Sa)=>{"use strict";var Fp=$(),Bp=ba(),Up=E(),Vp=L(),ya=Up("species");Sa.exports=function(r){var e=Fp(r);Vp&&e&&!e[ya]&&Bp(e,ya,{configurable:!0,get:function(){return this}})}});var qa=n((mS,Ea)=>{"use strict";var Gp=ye(),Kp=TypeError;Ea.exports=function(r,e){if(Gp(e,r))return r;throw Kp("Incorrect invocation")}});var It=n((bS,Pa)=>{"use strict";var Wp=q(),Hp=g(),St=We(),zp=Wp(Function.toString);Hp(St.inspectSource)||(St.inspectSource=function(r){return zp(r)});Pa.exports=St.inspectSource});var wa=n((yS,Ra)=>{"use strict";var Qp=q(),Yp=T(),Ta=g(),Jp=ie(),Xp=$(),Zp=It(),Oa=function(){},ev=[],_a=Xp("Reflect","construct"),Et=/^\s*(?:class|function)\b/,rv=Qp(Et.exec),tv=!Et.exec(Oa),_e=function(e){if(!Ta(e))return!1;try{return _a(Oa,ev,e),!0}catch{return!1}},xa=function(e){if(!Ta(e))return!1;switch(Jp(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return tv||!!rv(Et,Zp(e))}catch{return!0}};xa.sham=!0;Ra.exports=!_a||Yp(function(){var r;return _e(_e.call)||!_e(Object)||!_e(function(){r=!0})||r})?xa:_e});var Ca=n((SS,Aa)=>{"use strict";var iv=wa(),ov=Ie(),nv=TypeError;Aa.exports=function(r){if(iv(r))return r;throw nv(ov(r)+" is not a constructor")}});var qt=n((IS,La)=>{"use strict";var Na=A(),av=Ca(),sv=X(),uv=E(),cv=uv("species");La.exports=function(r,e){var t=Na(r).constructor,i;return t===void 0||sv(i=Na(t)[cv])?e:av(i)}});var Pt=n((ES,ka)=>{"use strict";var lv=$();ka.exports=lv("document","documentElement")});var $a=n((qS,Da)=>{"use strict";var fv=q();Da.exports=fv([].slice)});var ja=n((PS,Ma)=>{"use strict";var dv=TypeError;Ma.exports=function(r,e){if(r<e)throw dv("Not enough arguments");return r}});var Tt=n((TS,Fa)=>{"use strict";var pv=Se();Fa.exports=/(?:ipad|iphone|ipod).*applewebkit/i.test(pv)});var Lt=n((OS,Qa)=>{"use strict";var O=I(),vv=kr(),hv=Pe(),Ba=g(),gv=w(),za=T(),Ua=Pt(),mv=$a(),Va=Qe(),bv=ja(),yv=Tt(),Sv=Oe(),At=O.setImmediate,Ct=O.clearImmediate,Iv=O.process,Ot=O.Dispatch,Ev=O.Function,Ga=O.MessageChannel,qv=O.String,_t=0,xe={},Ka="onreadystatechange",Re,K,xt,Rt;za(function(){Re=O.location});var Nt=function(r){if(gv(xe,r)){var e=xe[r];delete xe[r],e()}},wt=function(r){return function(){Nt(r)}},Wa=function(r){Nt(r.data)},Ha=function(r){O.postMessage(qv(r),Re.protocol+"//"+Re.host)};(!At||!Ct)&&(At=function(e){bv(arguments.length,1);var t=Ba(e)?e:Ev(e),i=mv(arguments,1);return xe[++_t]=function(){vv(t,void 0,i)},K(_t),_t},Ct=function(e){delete xe[e]},Sv?K=function(r){Iv.nextTick(wt(r))}:Ot&&Ot.now?K=function(r){Ot.now(wt(r))}:Ga&&!yv?(xt=new Ga,Rt=xt.port2,xt.port1.onmessage=Wa,K=hv(Rt.postMessage,Rt)):O.addEventListener&&Ba(O.postMessage)&&!O.importScripts&&Re&&Re.protocol!=="file:"&&!za(Ha)?(K=Ha,O.addEventListener("message",Wa,!1)):Ka in Va("script")?K=function(r){Ua.appendChild(Va("script"))[Ka]=function(){Ua.removeChild(this),Nt(r)}}:K=function(r){setTimeout(wt(r),0)});Qa.exports={set:At,clear:Ct}});var kt=n((_S,Ja)=>{"use strict";var Ya=function(){this.head=null,this.tail=null};Ya.prototype={add:function(r){var e={item:r,next:null},t=this.tail;t?t.next=e:this.head=e,this.tail=e},get:function(){var r=this.head;if(r){var e=this.head=r.next;return e===null&&(this.tail=null),r.item}}};Ja.exports=Ya});var Za=n((xS,Xa)=>{"use strict";var Pv=Se();Xa.exports=/ipad|iphone|ipod/i.test(Pv)&&typeof Pebble<"u"});var rs=n((RS,es)=>{"use strict";var Tv=Se();es.exports=/web0s(?!.*chrome)/i.test(Tv)});var cs=n((wS,us)=>{"use strict";var W=I(),ts=Pe(),Ov=tt().f,Dt=Lt().set,_v=kt(),xv=Tt(),Rv=Za(),wv=rs(),$t=Oe(),is=W.MutationObserver||W.WebKitMutationObserver,os=W.document,ns=W.process,rr=W.Promise,as=Ov(W,"queueMicrotask"),Ft=as&&as.value,ae,Mt,jt,tr,ss;Ft||(we=new _v,Ae=function(){var r,e;for($t&&(r=ns.domain)&&r.exit();e=we.get();)try{e()}catch(t){throw we.head&&ae(),t}r&&r.enter()},!xv&&!$t&&!wv&&is&&os?(Mt=!0,jt=os.createTextNode(""),new is(Ae).observe(jt,{characterData:!0}),ae=function(){jt.data=Mt=!Mt}):!Rv&&rr&&rr.resolve?(tr=rr.resolve(void 0),tr.constructor=rr,ss=ts(tr.then,tr),ae=function(){ss(Ae)}):$t?ae=function(){ns.nextTick(Ae)}:(Dt=ts(Dt,W),ae=function(){Dt(Ae)}),Ft=function(r){we.head||ae(),we.add(r)});var we,Ae;us.exports=Ft});var fs=n((AS,ls)=>{"use strict";ls.exports=function(r,e){try{arguments.length==1?console.error(r):console.error(r,e)}catch{}}});var ir=n((CS,ds)=>{"use strict";ds.exports=function(r){try{return{error:!1,value:r()}}catch(e){return{error:!0,value:e}}}});var hs=n((NS,vs)=>{"use strict";var Av=I(),Cv=g(),ps=Av.WeakMap;vs.exports=Cv(ps)&&/native code/.test(String(ps))});var or=n((LS,ms)=>{"use strict";var Nv=Jr(),Lv=Xr(),gs=Nv("keys");ms.exports=function(r){return gs[r]||(gs[r]=Lv(r))}});var nr=n((kS,bs)=>{"use strict";bs.exports={}});var Gt=n((DS,Is)=>{"use strict";var kv=hs(),Ss=I(),Dv=k(),$v=G(),Bt=w(),Ut=We(),Mv=or(),jv=nr(),ys="Object already initialized",Vt=Ss.TypeError,Fv=Ss.WeakMap,ar,Ce,sr,Bv=function(r){return sr(r)?Ce(r):ar(r,{})},Uv=function(r){return function(e){var t;if(!Dv(e)||(t=Ce(e)).type!==r)throw Vt("Incompatible receiver, "+r+" required");return t}};kv||Ut.state?(N=Ut.state||(Ut.state=new Fv),N.get=N.get,N.has=N.has,N.set=N.set,ar=function(r,e){if(N.has(r))throw Vt(ys);return e.facade=r,N.set(r,e),e},Ce=function(r){return N.get(r)||{}},sr=function(r){return N.has(r)}):(H=Mv("state"),jv[H]=!0,ar=function(r,e){if(Bt(r,H))throw Vt(ys);return e.facade=r,$v(r,H,e),e},Ce=function(r){return Bt(r,H)?r[H]:{}},sr=function(r){return Bt(r,H)});var N,H;Is.exports={set:ar,get:Ce,has:sr,enforce:Bv,getterFor:Uv}});var z=n(($S,Es)=>{"use strict";var Vv=I();Es.exports=Vv.Promise});var Kt=n((MS,qs)=>{"use strict";qs.exports=typeof Deno=="object"&&Deno&&typeof Deno.version=="object"});var Ts=n((jS,Ps)=>{"use strict";var Gv=Kt(),Kv=Oe();Ps.exports=!Gv&&!Kv&&typeof window=="object"&&typeof document=="object"});var se=n((FS,xs)=>{"use strict";var Wv=I(),Ne=z(),Hv=g(),zv=it(),Qv=It(),Yv=E(),Jv=Ts(),Xv=Kt(),Zv=R(),Wt=Gr(),Os=Ne&&Ne.prototype,eh=Yv("species"),Ht=!1,_s=Hv(Wv.PromiseRejectionEvent),rh=zv("Promise",function(){var r=Qv(Ne),e=r!==String(Ne);if(!e&&Wt===66||Zv&&!(Os.catch&&Os.finally))return!0;if(!Wt||Wt<51||!/native code/.test(r)){var t=new Ne(function(s){s(1)}),i=function(s){s(function(){},function(){})},o=t.constructor={};if(o[eh]=i,Ht=t.then(function(){})instanceof i,!Ht)return!0}return!e&&(Jv||Xv)&&!_s});xs.exports={CONSTRUCTOR:rh,REJECTION_EVENT:_s,SUBCLASSING:Ht}});var ue=n((BS,ws)=>{"use strict";var Rs=M(),th=TypeError,ih=function(r){var e,t;this.promise=new r(function(i,o){if(e!==void 0||t!==void 0)throw th("Bad Promise constructor");e=i,t=o}),this.resolve=Rs(e),this.reject=Rs(t)};ws.exports.f=function(r){return new ih(r)}});var Qs=n(()=>{"use strict";var oh=C(),nh=R(),fr=Oe(),U=I(),de=P(),As=ne(),Cs=yt(),ah=er(),sh=Ia(),uh=M(),lr=g(),ch=k(),lh=qa(),fh=qt(),$s=Lt().set,Xt=cs(),dh=fs(),ph=ir(),vh=kt(),Ms=Gt(),dr=z(),Zt=se(),js=ue(),pr="Promise",Fs=Zt.CONSTRUCTOR,hh=Zt.REJECTION_EVENT,gh=Zt.SUBCLASSING,zt=Ms.getterFor(pr),mh=Ms.set,ce=dr&&dr.prototype,Q=dr,ur=ce,Bs=U.TypeError,Qt=U.document,ei=U.process,Yt=js.f,bh=Yt,yh=!!(Qt&&Qt.createEvent&&U.dispatchEvent),Us="unhandledrejection",Sh="rejectionhandled",Ns=0,Vs=1,Ih=2,ri=1,Gs=2,cr,Ls,Eh,ks,Ks=function(r){var e;return ch(r)&&lr(e=r.then)?e:!1},Ws=function(r,e){var t=e.value,i=e.state==Vs,o=i?r.ok:r.fail,s=r.resolve,u=r.reject,c=r.domain,p,f,a;try{o?(i||(e.rejection===Gs&&Ph(e),e.rejection=ri),o===!0?p=t:(c&&c.enter(),p=o(t),c&&(c.exit(),a=!0)),p===r.promise?u(Bs("Promise-chain cycle")):(f=Ks(p))?de(f,p,s,u):s(p)):u(t)}catch(d){c&&!a&&c.exit(),u(d)}},Hs=function(r,e){r.notified||(r.notified=!0,Xt(function(){for(var t=r.reactions,i;i=t.get();)Ws(i,r);r.notified=!1,e&&!r.rejection&&qh(r)}))},zs=function(r,e,t){var i,o;yh?(i=Qt.createEvent("Event"),i.promise=e,i.reason=t,i.initEvent(r,!1,!0),U.dispatchEvent(i)):i={promise:e,reason:t},!hh&&(o=U["on"+r])?o(i):r===Us&&dh("Unhandled promise rejection",t)},qh=function(r){de($s,U,function(){var e=r.facade,t=r.value,i=Ds(r),o;if(i&&(o=ph(function(){fr?ei.emit("unhandledRejection",t,e):zs(Us,e,t)}),r.rejection=fr||Ds(r)?Gs:ri,o.error))throw o.value})},Ds=function(r){return r.rejection!==ri&&!r.parent},Ph=function(r){de($s,U,function(){var e=r.facade;fr?ei.emit("rejectionHandled",e):zs(Sh,e,r.value)})},le=function(r,e,t){return function(i){r(e,i,t)}},fe=function(r,e,t){r.done||(r.done=!0,t&&(r=t),r.value=e,r.state=Ih,Hs(r,!0))},Jt=function(r,e,t){if(!r.done){r.done=!0,t&&(r=t);try{if(r.facade===e)throw Bs("Promise can't be resolved itself");var i=Ks(e);i?Xt(function(){var o={done:!1};try{de(i,e,le(Jt,o,r),le(fe,o,r))}catch(s){fe(o,s,r)}}):(r.value=e,r.state=Vs,Hs(r,!1))}catch(o){fe({done:!1},o,r)}}};if(Fs&&(Q=function(e){lh(this,ur),uh(e),de(cr,this);var t=zt(this);try{e(le(Jt,t),le(fe,t))}catch(i){fe(t,i)}},ur=Q.prototype,cr=function(e){mh(this,{type:pr,done:!1,notified:!1,parent:!1,reactions:new vh,rejection:!1,state:Ns,value:void 0})},cr.prototype=As(ur,"then",function(e,t){var i=zt(this),o=Yt(fh(this,Q));return i.parent=!0,o.ok=lr(e)?e:!0,o.fail=lr(t)&&t,o.domain=fr?ei.domain:void 0,i.state==Ns?i.reactions.add(o):Xt(function(){Ws(o,i)}),o.promise}),Ls=function(){var r=new cr,e=zt(r);this.promise=r,this.resolve=le(Jt,e),this.reject=le(fe,e)},js.f=Yt=function(r){return r===Q||r===Eh?new Ls(r):bh(r)},!nh&&lr(dr)&&ce!==Object.prototype)){ks=ce.then,gh||As(ce,"then",function(e,t){var i=this;return new Q(function(o,s){de(ks,i,o,s)}).then(e,t)},{unsafe:!0});try{delete ce.constructor}catch{}Cs&&Cs(ce,ur)}oh({global:!0,constructor:!0,wrap:!0,forced:Fs},{Promise:Q});ah(Q,pr,!1,!0);sh(pr)});var Y=n((GS,Ys)=>{"use strict";Ys.exports={}});var Xs=n((KS,Js)=>{"use strict";var Th=E(),Oh=Y(),_h=Th("iterator"),xh=Array.prototype;Js.exports=function(r){return r!==void 0&&(Oh.Array===r||xh[_h]===r)}});var eu=n((WS,Zs)=>{"use strict";var Rh=Math.ceil,wh=Math.floor;Zs.exports=Math.trunc||function(e){var t=+e;return(t>0?wh:Rh)(t)}});var ti=n((HS,ru)=>{"use strict";var Ah=eu();ru.exports=function(r){var e=+r;return e!==e||e===0?0:Ah(e)}});var iu=n((zS,tu)=>{"use strict";var Ch=ti(),Nh=Math.min;tu.exports=function(r){return r>0?Nh(Ch(r),9007199254740991):0}});var ii=n((QS,ou)=>{"use strict";var Lh=iu();ou.exports=function(r){return Lh(r.length)}});var oi=n((YS,au)=>{"use strict";var kh=ie(),nu=Ee(),Dh=X(),$h=Y(),Mh=E(),jh=Mh("iterator");au.exports=function(r){if(!Dh(r))return nu(r,jh)||nu(r,"@@iterator")||$h[kh(r)]}});var uu=n((JS,su)=>{"use strict";var Fh=P(),Bh=M(),Uh=A(),Vh=Ie(),Gh=oi(),Kh=TypeError;su.exports=function(r,e){var t=arguments.length<2?Gh(r):e;if(Bh(t))return Uh(Fh(t,r));throw Kh(Vh(r)+" is not iterable")}});var fu=n((XS,lu)=>{"use strict";var Wh=P(),cu=A(),Hh=Ee();lu.exports=function(r,e,t){var i,o;cu(r);try{if(i=Hh(r,"return"),!i){if(e==="throw")throw t;return t}i=Wh(i,r)}catch(s){o=!0,i=s}if(e==="throw")throw t;if(o)throw i;return cu(i),t}});var hr=n((ZS,hu)=>{"use strict";var zh=Pe(),Qh=P(),Yh=A(),Jh=Ie(),Xh=Xs(),Zh=ii(),du=ye(),eg=uu(),rg=oi(),pu=fu(),tg=TypeError,vr=function(r,e){this.stopped=r,this.result=e},vu=vr.prototype;hu.exports=function(r,e,t){var i=t&&t.that,o=!!(t&&t.AS_ENTRIES),s=!!(t&&t.IS_RECORD),u=!!(t&&t.IS_ITERATOR),c=!!(t&&t.INTERRUPTED),p=zh(e,i),f,a,d,v,l,h,m,y=function(S){return f&&pu(f,"normal",S),new vr(!0,S)},b=function(S){return o?(Yh(S),c?p(S[0],S[1],y):p(S[0],S[1])):c?p(S,y):p(S)};if(s)f=r.iterator;else if(u)f=r;else{if(a=rg(r),!a)throw tg(Jh(r)+" is not iterable");if(Xh(a)){for(d=0,v=Zh(r);v>d;d++)if(l=b(r[d]),l&&du(vu,l))return l;return new vr(!1)}f=eg(r,a)}for(h=s?r.next:f.next;!(m=Qh(h,f)).done;){try{l=b(m.value)}catch(S){pu(f,"throw",S)}if(typeof l=="object"&&l&&du(vu,l))return l}return new vr(!1)}});var Su=n((eI,yu)=>{"use strict";var ig=E(),mu=ig("iterator"),bu=!1;try{gu=0,ni={next:function(){return{done:!!gu++}},return:function(){bu=!0}},ni[mu]=function(){return this},Array.from(ni,function(){throw 2})}catch{}var gu,ni;yu.exports=function(r,e){if(!e&&!bu)return!1;var t=!1;try{var i={};i[mu]=function(){return{next:function(){return{done:t=!0}}}},r(i)}catch{}return t}});var ai=n((rI,Iu)=>{"use strict";var og=z(),ng=Su(),ag=se().CONSTRUCTOR;Iu.exports=ag||!ng(function(r){og.all(r).then(void 0,function(){})})});var Eu=n(()=>{"use strict";var sg=C(),ug=P(),cg=M(),lg=ue(),fg=ir(),dg=hr(),pg=ai();sg({target:"Promise",stat:!0,forced:pg},{all:function(e){var t=this,i=lg.f(t),o=i.resolve,s=i.reject,u=fg(function(){var c=cg(t.resolve),p=[],f=0,a=1;dg(e,function(d){var v=f++,l=!1;a++,ug(c,t,d).then(function(h){l||(l=!0,p[v]=h,--a||o(p))},s)}),--a||o(p)});return u.error&&s(u.value),i.promise}})});var Pu=n(()=>{"use strict";var vg=C(),hg=R(),gg=se().CONSTRUCTOR,ui=z(),mg=$(),bg=g(),yg=ne(),qu=ui&&ui.prototype;vg({target:"Promise",proto:!0,forced:gg,real:!0},{catch:function(r){return this.then(void 0,r)}});!hg&&bg(ui)&&(si=mg("Promise").prototype.catch,qu.catch!==si&&yg(qu,"catch",si,{unsafe:!0}));var si});var Tu=n(()=>{"use strict";var Sg=C(),Ig=P(),Eg=M(),qg=ue(),Pg=ir(),Tg=hr(),Og=ai();Sg({target:"Promise",stat:!0,forced:Og},{race:function(e){var t=this,i=qg.f(t),o=i.reject,s=Pg(function(){var u=Eg(t.resolve);Tg(e,function(c){Ig(u,t,c).then(i.resolve,o)})});return s.error&&o(s.value),i.promise}})});var Ou=n(()=>{"use strict";var _g=C(),xg=P(),Rg=ue(),wg=se().CONSTRUCTOR;_g({target:"Promise",stat:!0,forced:wg},{reject:function(e){var t=Rg.f(this);return xg(t.reject,void 0,e),t.promise}})});var ci=n((lI,_u)=>{"use strict";var Ag=A(),Cg=k(),Ng=ue();_u.exports=function(r,e){if(Ag(r),Cg(e)&&e.constructor===r)return e;var t=Ng.f(r),i=t.resolve;return i(e),t.promise}});var wu=n(()=>{"use strict";var Lg=C(),kg=$(),xu=R(),Dg=z(),Ru=se().CONSTRUCTOR,$g=ci(),Mg=kg("Promise"),jg=xu&&!Ru;Lg({target:"Promise",stat:!0,forced:xu||Ru},{resolve:function(e){return $g(jg&&this===Mg?Dg:this,e)}})});var Au=n(()=>{"use strict";Qs();Eu();Pu();Tu();Ou();wu()});var ku=n(()=>{"use strict";var Fg=C(),Bg=R(),gr=z(),Ug=T(),Nu=$(),Lu=g(),Vg=qt(),Cu=ci(),Gg=ne(),fi=gr&&gr.prototype,Kg=!!gr&&Ug(function(){fi.finally.call({then:function(){}},function(){})});Fg({target:"Promise",proto:!0,real:!0,forced:Kg},{finally:function(r){var e=Vg(this,Nu("Promise")),t=Lu(r);return this.then(t?function(i){return Cu(e,r()).then(function(){return i})}:r,t?function(i){return Cu(e,r()).then(function(){throw i})}:r)}});!Bg&&Lu(gr)&&(li=Nu("Promise").prototype.finally,fi.finally!==li&&Gg(fi,"finally",li,{unsafe:!0}));var li});var $u=n((mI,Du)=>{"use strict";na();Au();ku();var Wg=pt();Du.exports=Wg("Promise","finally")});var ju=n((bI,Mu)=>{"use strict";var Hg=$u();Mu.exports=Hg});var Bu=n((yI,Fu)=>{"use strict";var zg=ju();Fu.exports=zg});var Vu=n((SI,Uu)=>{"use strict";Uu.exports=function(){}});var Wu=n((II,Ku)=>{"use strict";var di=L(),Qg=w(),Gu=Function.prototype,Yg=di&&Object.getOwnPropertyDescriptor,pi=Qg(Gu,"name"),Jg=pi&&function(){}.name==="something",Xg=pi&&(!di||di&&Yg(Gu,"name").configurable);Ku.exports={EXISTS:pi,PROPER:Jg,CONFIGURABLE:Xg}});var zu=n((EI,Hu)=>{"use strict";var Zg=ti(),em=Math.max,rm=Math.min;Hu.exports=function(r,e){var t=Zg(r);return t<0?em(t+e,0):rm(t,e)}});var Ju=n((qI,Yu)=>{"use strict";var tm=Z(),im=zu(),om=ii(),Qu=function(r){return function(e,t,i){var o=tm(e),s=om(o),u=im(i,s),c;if(r&&t!=t){for(;s>u;)if(c=o[u++],c!=c)return!0}else for(;s>u;u++)if((r||u in o)&&o[u]===t)return r||u||0;return!r&&-1}};Yu.exports={includes:Qu(!0),indexOf:Qu(!1)}});var ec=n((PI,Zu)=>{"use strict";var nm=q(),vi=w(),am=Z(),sm=Ju().indexOf,um=nr(),Xu=nm([].push);Zu.exports=function(r,e){var t=am(r),i=0,o=[],s;for(s in t)!vi(um,s)&&vi(t,s)&&Xu(o,s);for(;e.length>i;)vi(t,s=e[i++])&&(~sm(o,s)||Xu(o,s));return o}});var hi=n((TI,rc)=>{"use strict";rc.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]});var ic=n((OI,tc)=>{"use strict";var cm=ec(),lm=hi();tc.exports=Object.keys||function(e){return cm(e,lm)}});var nc=n(oc=>{"use strict";var fm=L(),dm=ot(),pm=V(),vm=A(),hm=Z(),gm=ic();oc.f=fm&&!dm?Object.defineProperties:function(e,t){vm(e);for(var i=hm(t),o=gm(t),s=o.length,u=0,c;s>u;)pm.f(e,c=o[u++],i[c]);return e}});var yi=n((xI,dc)=>{"use strict";var mm=A(),bm=nc(),ac=hi(),ym=nr(),Sm=Pt(),Im=Qe(),Em=or(),sc=">",uc="<",mi="prototype",bi="script",lc=Em("IE_PROTO"),gi=function(){},fc=function(r){return uc+bi+sc+r+uc+"/"+bi+sc},cc=function(r){r.write(fc("")),r.close();var e=r.parentWindow.Object;return r=null,e},qm=function(){var r=Im("iframe"),e="java"+bi+":",t;return r.style.display="none",Sm.appendChild(r),r.src=String(e),t=r.contentWindow.document,t.open(),t.write(fc("document.F=Object")),t.close(),t.F},mr,br=function(){try{mr=new ActiveXObject("htmlfile")}catch{}br=typeof document<"u"?document.domain&&mr?cc(mr):qm():cc(mr);for(var r=ac.length;r--;)delete br[mi][ac[r]];return br()};ym[lc]=!0;dc.exports=Object.create||function(e,t){var i;return e!==null?(gi[mi]=mm(e),i=new gi,gi[mi]=null,i[lc]=e):i=br(),t===void 0?i:bm.f(i,t)}});var vc=n((RI,pc)=>{"use strict";var Pm=T();pc.exports=!Pm(function(){function r(){}return r.prototype.constructor=null,Object.getPrototypeOf(new r)!==r.prototype})});var Ii=n((wI,gc)=>{"use strict";var Tm=w(),Om=g(),_m=He(),xm=or(),Rm=vc(),hc=xm("IE_PROTO"),Si=Object,wm=Si.prototype;gc.exports=Rm?Si.getPrototypeOf:function(r){var e=_m(r);if(Tm(e,hc))return e[hc];var t=e.constructor;return Om(t)&&e instanceof t?t.prototype:e instanceof Si?wm:null}});var Ti=n((AI,yc)=>{"use strict";var Am=T(),Cm=g(),Nm=k(),Lm=yi(),mc=Ii(),km=ne(),Dm=E(),$m=R(),Pi=Dm("iterator"),bc=!1,j,Ei,qi;[].keys&&(qi=[].keys(),"next"in qi?(Ei=mc(mc(qi)),Ei!==Object.prototype&&(j=Ei)):bc=!0);var Mm=!Nm(j)||Am(function(){var r={};return j[Pi].call(r)!==r});Mm?j={}:$m&&(j=Lm(j));Cm(j[Pi])||km(j,Pi,function(){return this});yc.exports={IteratorPrototype:j,BUGGY_SAFARI_ITERATORS:bc}});var Ic=n((CI,Sc)=>{"use strict";var jm=Ti().IteratorPrototype,Fm=yi(),Bm=be(),Um=er(),Vm=Y(),Gm=function(){return this};Sc.exports=function(r,e,t,i){var o=e+" Iterator";return r.prototype=Fm(jm,{next:Bm(+!i,t)}),Um(r,o,!1,!0),Vm[o]=Gm,r}});var Cc=n((NI,Ac)=>{"use strict";var Km=C(),Wm=P(),yr=R(),Rc=Wu(),Hm=g(),zm=Ic(),Ec=Ii(),qc=yt(),Qm=er(),Ym=G(),Oi=ne(),Jm=E(),Pc=Y(),wc=Ti(),Xm=Rc.PROPER,Zm=Rc.CONFIGURABLE,Tc=wc.IteratorPrototype,Sr=wc.BUGGY_SAFARI_ITERATORS,Le=Jm("iterator"),Oc="keys",ke="values",_c="entries",xc=function(){return this};Ac.exports=function(r,e,t,i,o,s,u){zm(t,e,i);var c=function(b){if(b===o&&v)return v;if(!Sr&&b in a)return a[b];switch(b){case Oc:return function(){return new t(this,b)};case ke:return function(){return new t(this,b)};case _c:return function(){return new t(this,b)}}return function(){return new t(this)}},p=e+" Iterator",f=!1,a=r.prototype,d=a[Le]||a["@@iterator"]||o&&a[o],v=!Sr&&d||c(o),l=e=="Array"&&a.entries||d,h,m,y;if(l&&(h=Ec(l.call(new r)),h!==Object.prototype&&h.next&&(!yr&&Ec(h)!==Tc&&(qc?qc(h,Tc):Hm(h[Le])||Oi(h,Le,xc)),Qm(h,p,!0,!0),yr&&(Pc[p]=xc))),Xm&&o==ke&&d&&d.name!==ke&&(!yr&&Zm?Ym(a,"name",ke):(f=!0,v=function(){return Wm(d,this)})),o)if(m={values:c(ke),keys:s?v:c(Oc),entries:c(_c)},u)for(y in m)(Sr||f||!(y in a))&&Oi(a,y,m[y]);else Km({target:e,proto:!0,forced:Sr||f},m);return(!yr||u)&&a[Le]!==v&&Oi(a,Le,v,{name:o}),Pc[e]=v,m}});var Lc=n((LI,Nc)=>{"use strict";Nc.exports=function(r,e){return{value:r,done:e}}});var xi=n((kI,jc)=>{"use strict";var eb=Z(),_i=Vu(),kc=Y(),$c=Gt(),rb=V().f,tb=Cc(),Ir=Lc(),ib=R(),ob=L(),Mc="Array Iterator",nb=$c.set,ab=$c.getterFor(Mc);jc.exports=tb(Array,"Array",function(r,e){nb(this,{type:Mc,target:eb(r),index:0,kind:e})},function(){var r=ab(this),e=r.target,t=r.kind,i=r.index++;return!e||i>=e.length?(r.target=void 0,Ir(void 0,!0)):t=="keys"?Ir(i,!1):t=="values"?Ir(e[i],!1):Ir([i,e[i]],!1)},"values");var Dc=kc.Arguments=kc.Array;_i("keys");_i("values");_i("entries");if(!ib&&ob&&Dc.name!=="values")try{rb(Dc,"name",{value:"values"})}catch{}});var Bc=n((DI,Fc)=>{"use strict";var sb=ze(),ub=V(),cb=be();Fc.exports=function(r,e,t){var i=sb(e);i in r?ub.f(r,i,cb(0,t)):r[i]=t}});var Uc=n(()=>{"use strict";var lb=C(),fb=hr(),db=Bc();lb({target:"Object",stat:!0},{fromEntries:function(e){var t={};return fb(e,function(i,o){db(t,i,o)},{AS_ENTRIES:!0}),t}})});var Gc=n((jI,Vc)=>{"use strict";xi();Uc();var pb=Ge();Vc.exports=pb.Object.fromEntries});var Wc=n((FI,Kc)=>{"use strict";Kc.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}});var Qc=n(()=>{"use strict";xi();var vb=Wc(),hb=I(),gb=ie(),mb=G(),Hc=Y(),bb=E(),zc=bb("toStringTag");for(Er in vb)Ri=hb[Er],qr=Ri&&Ri.prototype,qr&&gb(qr)!==zc&&mb(qr,zc,Er),Hc[Er]=Hc.Array;var Ri,qr,Er});var Jc=n((VI,Yc)=>{"use strict";var yb=Gc();Qc();Yc.exports=yb});var Zc=n((GI,Xc)=>{"use strict";var Sb=Jc();Xc.exports=Sb});var bl=Lr(Xn(),1);var Te=(s=>(s.PROD="prod",s.VK_ALIAS="vk_alias",s.VIDEOTEST="videotest",s.TEST="test",s.AUTO="auto",s))(Te||{}),vt=(f=>(f.Q144P="mobile",f.Q240P="lowest",f.Q360P="low",f.Q480P="medium",f.Q720P="high",f.Q1080P="fullhd",f.Q1440P="quadhd",f.Q2160P="ultrahd",f.UNKNOWN="unknown",f))(vt||{}),ht=(l=>(l.MP4="mp4",l.DASH="dash",l.DASH_SEP="dash_sep",l.ONDEMAND_DASH="ondemand_dash",l.HLS="hls",l.ONDEMAND_HLS="ondemand_hls",l.WEBM="webm",l.AV1="av1",l.ONDEMAND_DASH_LIVE="ondemand_dash_live",l.ONDEMAND_HLS_LIVE="ondemand_hls_live",l.WEBRTC="webrtc",l.UNKNOWN="unknown",l.RTMP="rtmp",l))(ht||{});var gt=(i=>(i.HTTP1="http1",i.HTTP2="http2",i.HTTP3="http3",i))(gt||{});var mt=(c=>(c.SLIDER="slider",c.DOUBLE_TAP="double_tap",c.TIME_CODE="time_code",c.EPISODE="episode",c.REWIND="rewind",c.LIVE="live",c.UNKNOWN="unknown",c))(mt||{}),Zn=(s=>(s.GRAPH_SHOW="iGraphShow",s.GRAPH_HIDE="iGraphHide",s.NEXT_AREA="iNextChapterArea",s.NEXT_BUTTON="iNextChapterBtn",s.WATCH_AGAIN="iWatchAgainBtn",s))(Zn||{}),ea={action_play:"ap",action_play_interactive:"api",first_bytes:"fb",player_ready:"pr",first_frame:"ff",seek:"sk",watch_coverage_record:"wr",watch_coverage_live:"wl",empty_buffer:"eb",action_stop:"as",close_at_empty_buffer:"cb",content_error:"er",player_interface_click:"pc",next_movie:"nm",track_switch:"ts",failover:"fo"},ra={vsid:"si",isid:"is",vid:"vi",place:"pl",quality:"qt",cdn_host:"ch",stat_type:"st",param:"pm",vk_app_id:"va",track_code:"tc",connection_type:"cnt",connection_reused:"cr",cached_data:"cd",live:"lv",muted:"mu",mode:"mo",subtitles:"sb",failover:"fo",download_speed:"ds",manual_quality:"mq",ref_domain:"rd",direct_url:"du"},ta={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},ia={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv"};import{fillWithDefault as yp}from"@vkontakte/videoplayer-shared";var Sp={apiEnv:"vk_alias",requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:[],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1}},oa=r=>yp(r,Sp);function bt(){let r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36),t=0,i,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(t<=2&&(t=33554432+Math.random()*16777216|0),i=t&15,t=t>>4,e[o]=r[o===19?i&3|8:i]);return e.join("")}import{assertNonNullable as Cb,combine as hl,fromEvent as gl,isNonNullable as ge,isNullable as ml,merge as Nb,now as F,observableFrom as Lb,once as kb,safeStorage as ji,Subject as Db,Subscription as Vi,ValueSubject as Fi}from"@vkontakte/videoplayer-shared";import{Logger as $b,detectEmbed as Mb}from"@vkontakte/videoplayer-shared";var Tr=Lr(Bu(),1);var el=Lr(Zc(),1);var rl=r=>{let{operation:e,custom:t}=r,i=(0,el.default)(Object.entries(t).map(([o,s])=>{let u=ra[o]??o,c=s;return s&&(o==="mode"?c=ia[s]??s:o==="quality"&&(c=ta[s]??s)),[u,c]}));return{...r,operation:ea[e]??e,custom:i}};var Pr="__VERSION__",tl="CIOPGQJGDIHBABABA",wi={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",auto:""};import{ValueSubject as Ib,getExponentialDelay as Eb,ErrorCategory as pe}from"@vkontakte/videoplayer-shared";var De=class{constructor(e){this.consequentAuthErrors=0;this.authorized$=new Ib(!1);this.params=e}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){let t="log.externalLog",i=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(t,i,o)||this.logRequest(e)}async logRequest(e){let t="log.externalLog",i=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;let s=async(u,c=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(t,i,o)}catch(p){if(!p||!("error_code"in p)){this.params.error$.next({id:"logRequestUnknown",category:pe.NETWORK,message:`Unknown ${t} error`,thrown:p});return}let f=p?.error_code;switch(f){case 102:case 103:case 104:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),c>0?s(u,c-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),c>0?s(u,c-1):void 0;default:{this.params.error$.next({id:`LogRequest#${f}`,category:pe.EXTERNAL_API,message:`${t} error`,data:p});return}}}};return s(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=(0,Tr.default)(this.params.refreshAuthToken(),()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:`@vkontakte/videoplayer-statistics:${Pr}`,platform:this.params.mobile?"M_WEB":"WEB",items:this.params.config.shorten?e.map(rl):e})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();let e=Eb(this.consequentAuthErrors,this.params.config.backoff);return new Promise(t=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{(0,Tr.default)(this._authorize().then(t).catch(i=>this.params.error$.next({id:"AuthorizeBackoff",category:pe.NETWORK,message:"Otherwise unhandled error in authorization",thrown:i})),()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);let e="auth.anonymLogin",t={session_data:{version:2,device_id:this.params.uuid,client_version:Pr.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=(0,Tr.default)(this.params.apiTransport.sendRequest(e,t).then(i=>((!i||!i.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:pe.EXTERNAL_API,message:"No session key",data:i}),this.sessionKey=i?.session_key??void 0,this.sessionKey)).catch(async i=>{this.sessionKey=void 0;let o=i?.error_code;switch(o){case 401:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:pe.EXTERNAL_API,message:"authorize error",data:i}):this.params.error$.next({id:"AuthorizeUnknown",category:pe.NETWORK,message:"authorize error",thrown:i})}),()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}};var Or=class{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(e,t,i){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push({callback:t,options:i})}removeEventListener(e,t){if(!(e in this.listeners))return;let i=this.listeners[e];for(let o=0,s=i.length;o<s;o++)if(i[o].callback===t){i.splice(o,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return;let i=this.listeners[e.type].slice();for(let o=0,s=i.length;o<s;o++){let u=i[o];try{u.callback.call(this,e)}catch(c){Promise.resolve().then(()=>{throw c})}u.options&&u.options.once&&this.removeEventListener(e.type,u.callback)}return!e.defaultPrevented}},ve=class extends Or{constructor(){super(),this.listeners||Or.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,e)),super.dispatchEvent(e)}},$e=class{constructor(){Object.defineProperty(this,"signal",{value:new ve,writable:!0,configurable:!0})}abort(e){let t;try{t=new Event("abort")}catch{typeof document<"u"?document.createEvent?(t=document.createEvent("Event"),t.initEvent("abort",!1,!1)):(t=document.createEventObject(),t.type="abort"):t={type:"abort",bubbles:!1,cancelable:!1}}let i=e;if(i===void 0)if(typeof document>"u")i=new Error("This operation was aborted"),i.name="AbortError";else try{i=new DOMException("signal is aborted without reason")}catch{i=new Error("This operation was aborted"),i.name="AbortError"}this.signal.reason=i,this.signal.dispatchEvent(t)}toString(){return"[object AbortController]"}};typeof Symbol<"u"&&Symbol.toStringTag&&($e.prototype[Symbol.toStringTag]="AbortController",ve.prototype[Symbol.toStringTag]="AbortSignal");function _r(r){return r.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof r.Request=="function"&&!r.Request.prototype.hasOwnProperty("signal")||!r.AbortController}function Ai(r){typeof r=="function"&&(r={fetch:r});let{fetch:e,Request:t=e.Request,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o=!1}=r;if(!_r({fetch:e,Request:t,AbortController:i,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:e,Request:s};let s=t;(s&&!s.prototype.hasOwnProperty("signal")||o)&&(s=function(f,a){let d;a&&a.signal&&(d=a.signal,delete a.signal);let v=new t(f,a);return d&&Object.defineProperty(v,"signal",{writable:!1,enumerable:!1,configurable:!0,value:d}),v},s.prototype=t.prototype);let u=e;return{fetch:(p,f)=>{let a=s&&s.prototype.isPrototypeOf(p)?p.signal:f?f.signal:void 0;if(a){let d;try{d=new DOMException("Aborted","AbortError")}catch{d=new Error("Aborted"),d.name="AbortError"}if(a.aborted)return Promise.reject(d);let v=new Promise((l,h)=>{a.addEventListener("abort",()=>h(d),{once:!0})});return f&&f.signal&&delete f.signal,Promise.race([v,u(p,f)])}return u(p,f)},Request:s}}var Me=_r({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}),il=Me?Ai({fetch:window.fetch,Request:window.Request,AbortController:window.AbortController}):void 0,Ci=Me?il.fetch:window.fetch,fE=Me?il.Request:window.Request,dE=Me?$e:window.AbortController,pE=Me?ve:window.AbortSignal;import{ErrorCategory as xr,now as Ni}from"@vkontakte/videoplayer-shared";var je=class{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=wi[this.apiEnv],this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!=="auto"||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{let e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await Ci(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:xr.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),wi.vk_alias}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,t,i){if(!window.Blob||!window.navigator.sendBeacon)return!1;let o=this._prepareQueryParams({method:e,queryParams:t,sessionKey:i}),s=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,s)}catch(u){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:xr.NETWORK,message:"Unhandled beacon error",thrown:u,data:{method:e,params:t}})}return!1}async sendRequest(e,t,i){let o=Ni(),s=u=>{if(u instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(u.message)){this.params.error$.next({id:"Network",category:xr.NETWORK,message:"Request failed",thrown:u});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:xr.NETWORK,message:"Unhandled request error",thrown:u,data:{method:e,params:t,sessionKey:i,time:Ni()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),Ci(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:t,sessionKey:i})}).then(u=>{let c=Number(u.headers.get("content-length"))===0,p=new Date(u.headers.get("date")??"").getTime(),f=Ni()-o;if(isFinite(p)&&this.timeSynchronisation?.addServerTime(p,f),!c)return u.json().then(a=>Object.prototype.hasOwnProperty.call(a,"error_msg")?Promise.reject(a):a,s)},s)}_prepareQueryParams(e){let t=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&t.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([i,o])=>t.append(i,typeof o=="string"?o:JSON.stringify(o))),t}};import{ErrorCategory as qb,now as Pb,safeStorage as Fe,debounceFn as ol}from"@vkontakte/videoplayer-shared";var Rr="onestat_events",Li=r=>e=>e.timestamp+r>=Pb(),wr=class{constructor(e){this.unsaltedStorage=[];this.isPaused=!1;this.isUrgent=e=>{let{operation:t}=e;return["action_play","watch_coverage_record","watch_coverage_live"].includes(t)};this.params=e,this.api=e.api,this.error$=e.error$,this.userSalt=e.userSalt,this.loggerDebugLog=e.debugLogger.createComponentLog("stat logger"),this.firstFlush=ol(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let t=Fe.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=ol(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:t}),this.subscription=this.api.authorized$.subscribe(i=>{i&&this.debouncedFlush()}),this.housekeepStorage()}safeFlush(){try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:qb.WTF,message:String(e)??"Unknown logger error",thrown:e})}}readFromStorage(){let e=Fe.get(Rr);try{return e?JSON.parse(e):{}}catch{}return{}}addToStorage(e){if(!this.userSalt){this.unsaltedStorage.push(e);return}let t=this.readFromStorage(),o=(t[this.userSalt]??[]).filter(Li(this.params.config.storageExpiration));Fe.set(Rr,JSON.stringify({...t,[this.userSalt]:[...o,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(Li(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],Fe.set(Rr,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[t,i]of Object.entries(e)){let o=i.filter(Li(this.params.config.storageExpiration));o.length?e[t]=o:delete e[t],this.loggerDebugLog({message:`${i.length} retrieved from storage, ${o.length} of them actual`})}Fe.set(Rr,JSON.stringify(e))}log(e){this.addToStorage(e),!this.isPaused&&(this.isUrgent(e)?this.flush():this.lastVsid!==e.custom.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=e.custom.vsid)}flush(e=!1){let t=this.getFromStorage();t.length!==0&&(this.api.authorized$.getValue()?(e&&this.params.config.useBeacon?(this.loggerDebugLog({message:`Flushing ${t.length} events through beacon`}),this.api.logBeacon(t)):(this.loggerDebugLog({message:`Flushing ${t.length} events`}),this.api.logRequest(t)),this.markStorageSent()):this.api.authorize(),this.firstFlush.cancel(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe(),this.firstFlush.cancel(),this.debouncedFlush.cancel()}};import{HttpConnectionType as ki,Surface as he,VideoFormat as _,VideoQuality as D}from"@vkontakte/videoplayer-core";import{assertNever as nl}from"@vkontakte/videoplayer-shared";var al=r=>r&&{[D.INVARIANT]:"unknown",[D.Q_144P]:"mobile",[D.Q_240P]:"lowest",[D.Q_360P]:"low",[D.Q_480P]:"medium",[D.Q_720P]:"high",[D.Q_1080P]:"fullhd",[D.Q_1440P]:"quadhd",[D.Q_2160P]:"ultrahd",[D.Q_4320P]:"unknown"}[r],Di=r=>r&&{[ki.HTTP1]:"http1",[ki.HTTP2]:"http2",[ki.QUIC]:"http3"}[r],sl=r=>{if(r!==void 0)switch(r){case _.MPEG:return"mp4";case _.DASH_LIVE:return"dash";case _.DASH_SEP:return"dash_sep";case _.DASH_ONDEMAND:return"ondemand_dash";case _.DASH_WEBM:case _.DASH_LIVE_WEBM:return"webm";case _.DASH_WEBM_AV1:return"av1";case _.DASH_LIVE_CMAF:return"ondemand_dash_live";case _.HLS:case _.HLS_LIVE:return"hls";case _.HLS_ONDEMAND:return"ondemand_hls";case _.HLS_LIVE_CMAF:return"ondemand_hls_live";case _.WEB_RTC_LIVE:return"webrtc";default:return nl(r)}},Ar=r=>{if(r!==void 0)switch(r){case he.NONE:case he.INLINE:return;case he.FULLSCREEN:return"fullscreen";case he.SECOND_SCREEN:return"chromecast";case he.PIP:return"pip";case he.INVISIBLE:return"invisible";default:return nl(r)}},ul=r=>{switch(r){case"slow-2g":return"poor";case"2g":return"poor";case"3g":return"good";case"4g":return"excellent"}};var Cr=class{constructor(e){this.offset=void 0;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){let i=Date.now(),o=e-i-t/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}};var cl=()=>Math.floor(Math.random()*4294967296).toString(36).padStart(7,"0"),ll=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");import{PlaybackState as fl}from"@vkontakte/videoplayer-core";import{filter as dl,filterChanged as Ob,fromEvent as _b,isNullable as pl,map as xb,merge as $i,Observable as Rb,Subject as Mi,Subscription as wb,ValueSubject as Ab}from"@vkontakte/videoplayer-shared";var vl=(r,e)=>new Rb(t=>{let i=new wb,o=$i(_b(window,"beforeunload"),r.events.willDestruct$),s=new Ab(void 0),u;i.add(r.info.isLive$.pipe(Ob()).subscribe(B=>{u&&(u.unsubscribe(),s.next(void 0)),B?u=r.info.liveTime$.pipe(xb(Nr=>Nr&&Nr/1e3)).subscribe(s):u=r.info.position$.subscribe(s),i.add(u)}));let{playing$:c,paused$:p}=r.events,f=r.events.willSeek$.pipe(dl(()=>r.info.playbackState$.getValue()===fl.PLAYING)),a=r.events.seeked$.pipe(dl(()=>r.info.playbackState$.getValue()===fl.PLAYING)),d=!1,v=new Mi;i.add(f.subscribe(()=>{d||v.next(),d=!0})),i.add(a.subscribe(()=>d=!1));let l=new Mi,h=new Mi,m=$i(c,a,l),y=$i(p,v,o,r.events.looped$,h),b,S=()=>b=s.getValue(),yl=()=>{let B=s.getValue();pl(b)||b===B||pl(B)||(t.next({from:b,to:B}),b=void 0)},Sl=()=>{h.next(),l.next()};if(i.add(m.subscribe(S)),i.add(y.subscribe(yl)),e.forceInterval&&isFinite(e.forceInterval)){let B=0;i.add(m.subscribe(()=>B=window.setTimeout(Sl,e.forceInterval))),i.add(y.subscribe(()=>window.clearTimeout(B)))}return i});var jb="_one-stat_",Bi=`${jb}uuid`,Ui=()=>{let r=new Vi;return{subscription:r,subscribe:(e,t)=>{e&&r.add(e.subscribe(t))}}},Gi=class{constructor(e,t){this.subscription=new Vi;this.debugLogger=new $b;this.oneStatDebugLog=this.debugLogger.createComponentLog("onestat");this.loopCounter=0;this.disabled=!1;this.vsid$=new Fi(void 0);this.isid$=new Fi(void 0);this.seekAction$=new Fi("unknown");this.statContext=e,this.config=oa(t.config??{}),ge(t.apiEnv)&&(this.config.apiEnv=t.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new Cr);let i=new Db;this.experimental={error$:i};let o=ji.get(Bi);o?o.startsWith('"')&&o.endsWith('"')?(this.uuid=(0,bl.default)(o,'"',""),ji.set(Bi,this.uuid)):this.uuid=o:(this.uuid=bt(),ji.set(Bi,this.uuid)),this.resetViewSession(),t.useIsid&&this.isid$.next(t.isid??ll());let s=new je({apiKey:tl,config:this.config,error$:i,timeSynchronisation:this.timeSynchronisation});this.api=new De({config:this.config,apiTransport:s,refreshAuthToken:t.refreshAuthToken,mobile:this.statContext.mobile??!1,uuid:this.uuid,error$:i}),this.logger=new wr({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:i,userSalt:t.userSalt});let{isEmbed:u,host:c}=Mb();this.isEmbed=u,this.embedParent=c,this.subscribe()}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let t=new Vi,i=(a,d)=>t.add(a.subscribe(d));i(e.events.willStart$,()=>{let a=e.info.position$.getValue();this.logActionPlay({position:a}),this.statContext.projectId&&this.logActionPlayInteractive({position:a})}),i(e.events.looped$,()=>{this.resetViewSession(),++this.loopCounter>this.config.maxLoops&&(this.disabled=!0),this.logActionPlay({position:e.info.position$.getValue()})}),i(e.events.seeked$,()=>{this.logSeek({action:this.seekAction$.getValue(),time:e.info.position$.getValue()}),this.seekAction$.next("unknown")}),i(e.events.paused$,()=>{this.logPause({position:e.info.position$.getValue()})}),i(e.events.willResume$,()=>{this.logPlay()}),i(e.events.started$,()=>{this.statContext.clip&&this.logWatchCoverageRecord({start:0,end:0})}),i(vl(e,{forceInterval:this.config.watchCoverageInterval}),a=>{let d=e.info.isLive$.getValue(),v={start:parseFloat(a.from.toFixed(3)),end:parseFloat(a.to.toFixed(3))};d?this.logWatchCoverageLive(v):this.logWatchCoverageRecord(v)});let o;i(e.info.isStalled$,a=>{a?o=F():(ge(o)&&this.logEmptyBuffer({duration:F()-o}),o=void 0)});let s=!1;t.add(e.events.fatalError$.pipe(kb()).subscribe(()=>s=!0)),i(e.events.willStop$,()=>{if(e.info.isStalled$.getValue()){let d=ge(o)?F()-o:void 0;this.logCloseAtEmptyBuffer({duration:d??0}),o=void 0}else s||this.logActionStop()}),i(e.events.managedError$,({id:a})=>{this.logError({fatal:!1,errorType:a})}),i(e.events.fatalError$,({id:a})=>{this.logError({fatal:!0,errorType:a})});let u,c,p=!1;i(e.events.firstBytes$,a=>{u=F(),this.logFirstBytes({time:a})}),i(e.events.willStart$,()=>c=F()),i(e.info.currentBuffer$,a=>{!p&&a&&a.end-a.start>0&&ge(u)&&(this.logPlayerReady({duration:F()-u}),p=!0)}),i(e.events.firstFrame$,()=>{ge(u)&&!p&&(this.logPlayerReady({duration:F()-u}),p=!0),ge(c)&&this.logFirstFrame({time:F()-c})}),i(e.info.atLiveEdge$,a=>this.updateContext({liveEdge:a})),i(hl({muted:e.info.muted$,volume:e.info.volume$}),({muted:a,volume:d})=>this.updateContext({audible:!a&&d>0})),i(e.info.currentQuality$,a=>this.updateContext({quality:al(a)})),i(e.info.isAutoQualityEnabled$,a=>this.updateContext({autoQuality:a})),i(e.info.currentFormat$,a=>this.updateContext({contentType:sl(a)})),i(e.info.currentPlaybackRate$,a=>this.updateContext({rate:a})),i(e.info.is3DVideo$,a=>this.updateContext({is3d:a}));let f;return i(e.info.hostname$,a=>{let d=f!==void 0&&f!==a;this.updateContext({cdnHostname:a,failover:d}),d&&this.logFailover(a),f=a}),i(e.info.throughputEstimation$,a=>this.updateContext({downloadSpeed:a})),i(e.info.httpConnectionType$,a=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:Di(a)}),this.updateContext({connectionType:Di(a)})}),i(e.info.httpConnectionReused$,a=>{ml(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:a}),this.updateContext({connectionReused:a})}),i(e.info.surface$,a=>this.updateContext({mode:Ar(a)})),i(hl({current:e.info.currentTextTrack$,available:e.info.availableTextTracks$}),({current:a,available:d})=>{let v=d.find(({id:h})=>h===a),l=v&&(v.isAuto?`${v.language}_auto`:v.language);this.updateContext({subtitles:l})}),this.player=e,this.uiEvents&&this.attachToUi(this.uiEvents),this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToUi(e){this.uiEvents=e;let{subscription:t,subscribe:i}=Ui();return this.player&&(i(e.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),i(e.actionSeek$,this.seekAction$),i(e.inPiP$,o=>{let s=o?"pip":Ar(this.player?.info.surface$.getValue());this.updateContext({mode:s})}),i(e.inFullscreen$,o=>{let s=o?"fullscreen":Ar(this.player?.info.surface$.getValue());this.updateContext({mode:s})}),i(e.actionSetSubtitle$,o=>this.updateContext({subtitles:o})),i(e.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(t)),t}attachToAds(e){let{subscription:t,subscribe:i}=Ui();return i(e.slotRequested$,()=>this.logAdSlotRequest()),i(e.started$,o=>this.logAdStarted(o)),i(e.paused$,()=>this.logAdPaused()),i(e.resumed$,()=>this.logAdResumed()),i(e.ended$,()=>this.logAdEnded()),i(e.skipped$,()=>this.logAdSkipped()),i(e.clicked$,()=>this.logAdClicked()),this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToInteractive(e){let{subscription:t,subscribe:i}=Ui();return i(e.click$,o=>this.logInterfaceClick(o)),i(e.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(t),t}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause(),this.oneStatDebugLog({message:"paused"})}resume(){this.logger.resume(),this.oneStatDebugLog({message:"resumed"})}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.oneStatDebugLog({message:"VSID reset"}),this.vsid$.next(cl())}getDeviceId(){return this.uuid}setFieldBlacklist(){}logInited(){}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(...e){this.logActionPlay(...e)}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(e){this.log({operation:"seek",param:e.action,time:e.time})}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:"content_error",param:`${e.fatal?"fatal":"recoverable"}_${e.errorType}`})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`})}logWatchCoverageLive(e){let t=this.timeSynchronisation?.getOffset()??0,i=e.start+t,o=e.end+t;this.log({operation:"watch_coverage_live",param:`${i}-${o}`})}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(){}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"})}logInterfaceClick(e){this.log({operation:"player_interface_click",param:e})}logNextMovie(e){this.log({operation:"next_movie",param:String(e)})}subscribe(){this.resubscribeBeforeunload();let e=window.navigator.connection;e&&"onchange"in e&&"effectiveType"in e&&this.subscription.add(Nb(gl(e,"change"),Lb(["init"])).subscribe(()=>this.updateContext({network:ul(e.effectiveType)}))),this.config.debugLog&&this.debugLogger.log$.subscribe(t=>{console.debug("%c stat ","background:#fa6470;",`component: ${t.component}.`,t.message)})}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=gl(window,"beforeunload").subscribe(()=>this.logger.flush(!0)),this.subscription.add(this.beforeunloadSubscription)}logPlayerReady(e){this.log({operation:"player_ready",param:String(Math.round(e.duration))})}logActionPlay(e){this.log({operation:"action_play",param:String(Math.round(e.position))})}logActionPlayInteractive(e){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(Math.round(e.position))},{vid:this.statContext.projectId})}logFailover(e){this.log({operation:"failover",param:e})}logCloseAtEmptyBuffer(e){this.log({operation:"close_at_empty_buffer",param:String(Math.round(e.duration))})}logActionStop(){this.log({operation:"action_stop"})}log(e,t={}){if(this.disabled){this.oneStatDebugLog({message:`operation ${e.operation} but statistics is disabled`});return}if(this.config.disabledOperations.includes(e.operation)){this.oneStatDebugLog({message:`operation ${e.operation} but it is disabled`});return}this.oneStatDebugLog({message:`operation ${e.operation} ${e.param}`});let i=this.createLogItem(e,t);this.logger.log(i)}createLogItem({operation:e,param:t,time:i},o={}){let s=this.timeSynchronisation?.now()??F(),u=this.vsid$.getValue();Cb(u);let c=this.isid$.getValue(),p=e==="empty_buffer"||e==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,f=this.statContext.firstConnectionReused,a,d;if(this.isEmbed){a=this.embedParent;let l=[...new URLSearchParams(location.search).entries()].filter(([h,m])=>this.config.embedUrlParams.includes(h));d=new URLSearchParams(l).toString()}else this.statContext.place==="direct"&&((this.statContext.refDomain||document.referrer)&&(a=new URL(this.statContext.refDomain||document.referrer).hostname),d=location.href.substring(0,1024));let v={vsid:u,isid:c,vid:this.statContext.movieId,ct:this.statContext.contentType,place:this.isEmbed?"embed":this.statContext.place,quality:this.statContext.quality,cdn_host:this.statContext.cdnHostname,stat_type:this.statContext.autoplay===!0?"auto":this.statContext.autoplay===!1?"":void 0,param:t,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode,connection_type:p,connection_reused:f===!0?1:f===!1?0:void 0,cached_data:this.statContext.cached===!0?1:this.statContext.cached===!1?0:void 0,live:this.statContext.liveEdge?1:void 0,muted:this.statContext.audible===!1?1:void 0,mode:this.statContext.mode,subtitles:this.statContext.subtitles,download_speed:this.statContext.downloadSpeed,manual_quality:this.statContext.autoQuality?void 0:1,ref_domain:a,direct_url:d,rate:this.statContext.rate===1||ml(this.statContext.rate)?void 0:this.statContext.rate.toFixed(2),view_360:this.statContext.is3d?1:void 0,aid:this.statContext.albumId,vk_playlist_id:this.statContext.vkPlaylistId,...o};for(let l of this.config.disabledCustomFields)delete v[l];return{operation:e,type:1,time:i,network:this.statContext.network,timestamp:s,custom:v}}};export{Te as ApiEnv,gt as ConnectionType,ht as ContentType,Zn as InteractiveInterfaceClick,Gi as OneStat,vt as Quality,mt as SeekAction,Pr as VERSION};
|
package/evergreen.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.50
|
|
3
|
+
* Mon, 24 Jun 2024 13:02:45 GMT
|
|
4
|
+
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-50/doc/
|
|
5
5
|
*/
|
|
6
|
-
import{fillWithDefault as at,ValueSubject as I,getExponentialDelay as ht,ErrorCategory as b,now as p,debounceFn as j,safeStorage as w,assertNever as it,Observable as ut,Subscription as D,merge as O,fromEvent as Q,filterChanged as ct,map as dt,filter as Y,Subject as R,isNullable as B,Logger as lt,isNonNullable as y,detectEmbed as ft,once as gt,combine as X,observableFrom as pt,assertNonNullable as mt}from"@vkontakte/videoplayer-shared/evergreen.esm.js";import{Surface as $,VideoQuality as S,HttpConnectionType as M,VideoFormat as f,PlaybackState as J}from"@vkontakte/videoplayer-core/evergreen.esm.js";var _;(function(e){e.PROD="prod",e.VK_ALIAS="vk_alias",e.VIDEOTEST="videotest",e.TEST="test",e.AUTO="auto"})(_||(_={}));var m;(function(e){e.Q144P="mobile",e.Q240P="lowest",e.Q360P="low",e.Q480P="medium",e.Q720P="high",e.Q1080P="fullhd",e.Q1440P="quadhd",e.Q2160P="ultrahd",e.UNKNOWN="unknown"})(m||(m={}));var g;(function(e){e.MP4="mp4",e.DASH="dash",e.DASH_SEP="dash_sep",e.ONDEMAND_DASH="ondemand_dash",e.HLS="hls",e.ONDEMAND_HLS="ondemand_hls",e.WEBM="webm",e.AV1="av1",e.ONDEMAND_DASH_LIVE="ondemand_dash_live",e.ONDEMAND_HLS_LIVE="ondemand_hls_live",e.WEBRTC="webrtc",e.UNKNOWN="unknown",e.RTMP="rtmp"})(g||(g={}));var F;(function(e){e.AUTO="auto",e.MANUAL=""})(F||(F={}));var L;(function(e){e.HTTP1="http1",e.HTTP2="http2",e.HTTP3="http3"})(L||(L={}));var A;(function(e){e[e.YES=1]="YES",e[e.NO=0]="NO"})(A||(A={}));var N;(function(e){e.EXCELLENT="excellent",e.GOOD="good",e.POOR="poor"})(N||(N={}));var P;(function(e){e.PIP="pip",e.FULLSCREEN="fullscreen",e.EXTERNAL="external",e.PREFETCH="prefetch",e.AIRPLAY="airplay",e.CHROMECAST="chromecast",e.INVISIBLE="invisible"})(P||(P={}));var U;(function(e){e.SLIDER="slider",e.DOUBLE_TAP="double_tap",e.TIME_CODE="time_code",e.EPISODE="episode",e.REWIND="rewind",e.LIVE="live",e.UNKNOWN="unknown"})(U||(U={}));var Z;(function(e){e.GRAPH_SHOW="iGraphShow",e.GRAPH_HIDE="iGraphHide",e.NEXT_AREA="iNextChapterArea",e.NEXT_BUTTON="iNextChapterBtn",e.WATCH_AGAIN="iWatchAgainBtn"})(Z||(Z={}));const bt={action_play:"ap",action_play_interactive:"api",first_bytes:"fb",player_ready:"pr",first_frame:"ff",seek:"sk",watch_coverage_record:"wr",watch_coverage_live:"wl",empty_buffer:"eb",action_stop:"as",close_at_empty_buffer:"cb",content_error:"er",player_interface_click:"pc",next_movie:"nm",track_switch:"ts",failover:"fo"},St={vsid:"si",isid:"is",vid:"vi",place:"pl",quality:"qt",cdn_host:"ch",stat_type:"st",param:"pm",vk_app_id:"va",track_code:"tc",connection_type:"cnt",connection_reused:"cr",cached_data:"cd",live:"lv",muted:"mu",mode:"mo",subtitles:"sb",failover:"fo",download_speed:"ds",manual_quality:"mq",ref_domain:"rd",direct_url:"du"},_t={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},At={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv"},Et={apiEnv:_.VK_ALIAS,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:[],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1}},vt=e=>at(e,Et);function wt(){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),t=new Array(36);let i=0,s,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?t[o]="-":o===14?t[o]="4":(i<=2&&(i=33554432+Math.random()*16777216|0),s=i&15,i=i>>4,t[o]=e[o===19?s&3|8:s]);return t.join("")}const Pt=e=>{const{operation:t,custom:i}=e,s=Object.fromEntries(Object.entries(i).map(([o,r])=>{const a=St[o]??o;let h=r;return r&&(o==="mode"?h=At[r]??r:o==="quality"&&(h=_t[r]??r)),[a,h]}));return{...e,operation:bt[t]??t,custom:s}},tt="1.0.49",Tt="CIOPGQJGDIHBABABA",et={[_.PROD]:"https://api.ok.ru",[_.VK_ALIAS]:"https://api.mycdn.me",[_.VIDEOTEST]:"https://videotestapi.ok.ru/api",[_.TEST]:"https://apitest.ok.ru",[_.AUTO]:""};var T;(function(e){e[e.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",e[e.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",e[e.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",e[e.AUTH_LOGIN=401]="AUTH_LOGIN"})(T||(T={}));class xt{params;authToken;sessionKey;authorizePromise;refreshAuthTokenPromise;consequentAuthErrors=0;authorized$=new I(!1);backoffTimeoutId;constructor(t){this.params=t}async authorize(t){return this.authToken=t??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(t){const i="log.externalLog",s=this.createLogParams(t),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(i,s,o)||this.logRequest(t)}async logRequest(t){const i="log.externalLog",s=this.createLogParams(t),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;const r=async(a,h=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(i,s,o)}catch(c){if(!c||!("error_code"in c)){this.params.error$.next({id:"logRequestUnknown",category:b.NETWORK,message:`Unknown ${i} error`,thrown:c});return}const d=c?.error_code;switch(d){case T.PARAM_SESSION_EXPIRED:case T.PARAM_SESSION_KEY:case T.PARAM_SIGNATURE:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),h>0?r(a,h-1):void 0;case T.AUTH_LOGIN:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),h>0?r(a,h-1):void 0;default:{this.params.error$.next({id:`LogRequest#${d}`,category:b.EXTERNAL_API,message:`${i} error`,data:c});return}}}};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:${tt}`,platform:this.params.mobile?"M_WEB":"WEB",items:this.params.config.shorten?t.map(Pt):t})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();const t=ht(this.consequentAuthErrors,this.params.config.backoff);return new Promise(i=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(i).catch(s=>this.params.error$.next({id:"AuthorizeBackoff",category:b.NETWORK,message:"Otherwise unhandled error in authorization",thrown:s})).finally(()=>this.backoffTimeoutId=0)},t))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);const t="auth.anonymLogin",i={session_data:{version:2,device_id:this.params.uuid,client_version:tt.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(i.session_data.auth_token=this.authToken,i.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(t,i).then(s=>((!s||!s.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:b.EXTERNAL_API,message:"No session key",data:s}),this.sessionKey=s?.session_key??void 0,this.sessionKey)).catch(async s=>{this.sessionKey=void 0;const o=s?.error_code;switch(o){case T.AUTH_LOGIN:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:b.EXTERNAL_API,message:"authorize error",data:s}):this.params.error$.next({id:"AuthorizeUnknown",category:b.NETWORK,message:"authorize error",thrown:s})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}}class yt{apiKey;apiBaseUrl;apiEnv;timeSynchronisation;isApiBaseUrlFetched;params;constructor(t){this.params=t,this.apiKey=t.apiKey,this.apiEnv=t.config.apiEnv,this.apiBaseUrl=et[this.apiEnv],this.timeSynchronisation=t.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!==_.AUTO||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{const t=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await fetch(t,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(t){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:b.NETWORK,message:"Unhandled resolve api base url error",thrown:t}),et[_.VK_ALIAS]}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(t,i,s){if(!window.Blob||!window.navigator.sendBeacon)return!1;const o=this._prepareQueryParams({method:t,queryParams:i,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(a){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:b.NETWORK,message:"Unhandled beacon error",thrown:a,data:{method:t,params:i}})}return!1}async sendRequest(t,i,s){const o=p(),r=a=>{if(a instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(a.message)){this.params.error$.next({id:"Network",category:b.NETWORK,message:"Request failed",thrown:a});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:b.NETWORK,message:"Unhandled request error",thrown:a,data:{method:t,params:i,sessionKey:s,time:p()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),fetch(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:i,sessionKey:s})}).then(a=>{const h=Number(a.headers.get("content-length"))===0,c=new Date(a.headers.get("date")??"").getTime(),d=p()-o;if(isFinite(c)&&this.timeSynchronisation?.addServerTime(c,d),!h)return a.json().then(n=>Object.prototype.hasOwnProperty.call(n,"error_msg")?Promise.reject(n):n,r)},r)}_prepareQueryParams(t){const i=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return t.sessionKey!==void 0&&i.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach(([s,o])=>i.append(s,typeof o=="string"?o:JSON.stringify(o))),i}}const k="onestat_events",W=e=>t=>t.timestamp+e>=p();class $t{params;api;error$;subscription;userSalt;unsaltedStorage=[];lastVsid;isPaused=!1;firstFlush;debouncedFlush;loggerDebugLog;constructor(t){this.params=t,this.api=t.api,this.error$=t.error$,this.userSalt=t.userSalt,this.loggerDebugLog=t.debugLogger.createComponentLog("stat logger"),this.firstFlush=j(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});const i=w.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=j(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:i}),this.subscription=this.api.authorized$.subscribe(s=>{s&&this.debouncedFlush()}),this.housekeepStorage()}isUrgent=t=>{const{operation:i}=t;return["action_play","watch_coverage_record","watch_coverage_live"].includes(i)};safeFlush(){try{this.flush()}catch(t){this.error$.next({id:"LoggerError",category:b.WTF,message:String(t)??"Unknown logger error",thrown:t})}}readFromStorage(){const t=w.get(k);try{return t?JSON.parse(t):{}}catch{}return{}}addToStorage(t){if(!this.userSalt){this.unsaltedStorage.push(t);return}const i=this.readFromStorage(),o=(i[this.userSalt]??[]).filter(W(this.params.config.storageExpiration));w.set(k,JSON.stringify({...i,[this.userSalt]:[...o,t]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(W(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}const t=this.readFromStorage();delete t[this.userSalt],w.set(k,JSON.stringify(t))}housekeepStorage(){const t=this.readFromStorage();for(const[i,s]of Object.entries(t)){const o=s.filter(W(this.params.config.storageExpiration));o.length?t[i]=o:delete t[i],this.loggerDebugLog({message:`${s.length} retrieved from storage, ${o.length} of them actual`})}w.set(k,JSON.stringify(t))}log(t){this.addToStorage(t),!this.isPaused&&(this.isUrgent(t)?this.flush():this.lastVsid!==t.custom.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=t.custom.vsid)}flush(t=!1){const i=this.getFromStorage();i.length!==0&&(this.api.authorized$.getValue()?(t&&this.params.config.useBeacon?(this.loggerDebugLog({message:`Flushing ${i.length} events through beacon`}),this.api.logBeacon(i)):(this.loggerDebugLog({message:`Flushing ${i.length} events`}),this.api.logRequest(i)),this.markStorageSent()):this.api.authorize(),this.firstFlush.cancel(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe(),this.firstFlush.cancel(),this.debouncedFlush.cancel()}}const Nt=e=>e&&{[S.INVARIANT]:m.UNKNOWN,[S.Q_144P]:m.Q144P,[S.Q_240P]:m.Q240P,[S.Q_360P]:m.Q360P,[S.Q_480P]:m.Q480P,[S.Q_720P]:m.Q720P,[S.Q_1080P]:m.Q1080P,[S.Q_1440P]:m.Q1440P,[S.Q_2160P]:m.Q2160P,[S.Q_4320P]:m.UNKNOWN}[e],st=e=>e&&{[M.HTTP1]:L.HTTP1,[M.HTTP2]:L.HTTP2,[M.QUIC]:L.HTTP3}[e],Ct=e=>{if(e!==void 0)switch(e){case f.MPEG:return g.MP4;case f.DASH_LIVE:return g.DASH;case f.DASH_SEP:return g.DASH_SEP;case f.DASH_ONDEMAND:return g.ONDEMAND_DASH;case f.DASH_WEBM:case f.DASH_LIVE_WEBM:return g.WEBM;case f.DASH_WEBM_AV1:return g.AV1;case f.DASH_LIVE_CMAF:return g.ONDEMAND_DASH_LIVE;case f.HLS:case f.HLS_LIVE:return g.HLS;case f.HLS_ONDEMAND:return g.ONDEMAND_HLS;case f.HLS_LIVE_CMAF:return g.ONDEMAND_HLS_LIVE;case f.WEB_RTC_LIVE:return g.WEBRTC;default:return it(e)}},K=e=>{if(e!==void 0)switch(e){case $.NONE:case $.INLINE:return;case $.FULLSCREEN:return P.FULLSCREEN;case $.SECOND_SCREEN:return P.CHROMECAST;case $.PIP:return P.PIP;case $.INVISIBLE:return P.INVISIBLE;default:return it(e)}},It=e=>{switch(e){case"slow-2g":return N.POOR;case"2g":return N.POOR;case"3g":return N.GOOD;case"4g":return N.EXCELLENT}};class Lt{offset=void 0;constructor(t){this.offset=t}getOffset(){return this.offset??0}setOffset(t){this.offset=t}now(){return Date.now()+(this.offset??0)}date(t=new Date){return t.setTime(t.getTime()+(this.offset??0)),t}addServerTime(t,i){const s=Date.now(),o=t-s-i/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}}const kt=()=>Math.floor(Math.random()*2**32).toString(36).padStart(7,"0"),Ot=()=>Math.floor(Math.random()*2**64).toString(36).padStart(13,"0"),Rt=(e,t)=>new ut(i=>{const s=new D,o=O(Q(window,"beforeunload"),e.events.willDestruct$),r=new I(void 0);let a;s.add(e.info.isLive$.pipe(ct()).subscribe(v=>{a&&(a.unsubscribe(),r.next(void 0)),v?a=e.info.liveTime$.pipe(dt(H=>H&&H/1e3)).subscribe(r):a=e.info.position$.subscribe(r),s.add(a)}));const{playing$:h,paused$:c}=e.events,d=e.events.willSeek$.pipe(Y(()=>e.info.playbackState$.getValue()===J.PLAYING)),n=e.events.seeked$.pipe(Y(()=>e.info.playbackState$.getValue()===J.PLAYING));let u=!1;const l=new R;s.add(d.subscribe(()=>{u||l.next(),u=!0})),s.add(n.subscribe(()=>u=!1));const E=new R,x=new R,V=O(h,n,E),G=O(c,l,o,e.events.looped$,x);let C;const ot=()=>C=r.getValue(),nt=()=>{const v=r.getValue();B(C)||C===v||B(v)||(i.next({from:C,to:v}),C=void 0)},rt=()=>{x.next(),E.next()};if(s.add(V.subscribe(ot)),s.add(G.subscribe(nt)),t.forceInterval&&isFinite(t.forceInterval)){let v=0;s.add(V.subscribe(()=>v=window.setTimeout(rt,t.forceInterval))),s.add(G.subscribe(()=>window.clearTimeout(v)))}return s}),Dt="_one-stat_",q=`${Dt}uuid`,z=()=>{const e=new D;return{subscription:e,subscribe:(t,i)=>{t&&e.add(t.subscribe(i))}}};class Ut{api;logger;config;subscription=new D;beforeunloadSubscription;timeSynchronisation;debugLogger=new lt;oneStatDebugLog=this.debugLogger.createComponentLog("onestat");loopCounter=0;disabled=!1;experimental;vsid$=new I(void 0);isid$=new I(void 0);statContext;isEmbed;embedParent;uiEvents;player;seekAction$=new I(U.UNKNOWN);uuid;constructor(t,i){this.statContext=t,this.config=vt(i.config??{}),y(i.apiEnv)&&(this.config.apiEnv=i.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new Lt);const s=new R;this.experimental={error$:s};const o=w.get(q);o?o.startsWith('"')&&o.endsWith('"')?(this.uuid=o.replaceAll('"',""),w.set(q,this.uuid)):this.uuid=o:(this.uuid=wt(),w.set(q,this.uuid)),this.resetViewSession(),i.useIsid&&this.isid$.next(i.isid??Ot());const r=new yt({apiKey:Tt,config:this.config,error$:s,timeSynchronisation:this.timeSynchronisation});this.api=new xt({config:this.config,apiTransport:r,refreshAuthToken:i.refreshAuthToken,mobile:this.statContext.mobile??!1,uuid:this.uuid,error$:s}),this.logger=new $t({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:s,userSalt:i.userSalt});const{isEmbed:a,host:h}=ft();this.isEmbed=a,this.embedParent=h,this.subscribe()}updateContext(t){this.statContext={...this.statContext,...t}}attachTo(t){const i=new D,s=(n,u)=>i.add(n.subscribe(u));s(t.events.willStart$,()=>{const n=t.info.position$.getValue();this.logActionPlay({position:n}),this.statContext.projectId&&this.logActionPlayInteractive({position:n})}),s(t.events.looped$,()=>{this.resetViewSession(),++this.loopCounter>this.config.maxLoops&&(this.disabled=!0),this.logActionPlay({position:t.info.position$.getValue()})}),s(t.events.seeked$,()=>{this.logSeek({action:this.seekAction$.getValue(),time:t.info.position$.getValue()}),this.seekAction$.next(U.UNKNOWN)}),s(t.events.paused$,()=>{this.logPause({position:t.info.position$.getValue()})}),s(t.events.willResume$,()=>{this.logPlay()}),s(t.events.started$,()=>{this.statContext.clip&&this.logWatchCoverageRecord({start:0,end:0})}),s(Rt(t,{forceInterval:this.config.watchCoverageInterval}),n=>{const u=t.info.isLive$.getValue(),l={start:parseFloat(n.from.toFixed(3)),end:parseFloat(n.to.toFixed(3))};u?this.logWatchCoverageLive(l):this.logWatchCoverageRecord(l)});let o;s(t.info.isStalled$,n=>{n?o=p():(y(o)&&this.logEmptyBuffer({duration:p()-o}),o=void 0)});let r=!1;i.add(t.events.fatalError$.pipe(gt()).subscribe(()=>r=!0)),s(t.events.willStop$,()=>{if(t.info.isStalled$.getValue()){const u=y(o)?p()-o:void 0;this.logCloseAtEmptyBuffer({duration:u??0}),o=void 0}else r||this.logActionStop()}),s(t.events.managedError$,({id:n})=>{this.logError({fatal:!1,errorType:n})}),s(t.events.fatalError$,({id:n})=>{this.logError({fatal:!0,errorType:n})});let a,h,c=!1;s(t.events.firstBytes$,n=>{a=p(),this.logFirstBytes({time:n})}),s(t.events.willStart$,()=>h=p()),s(t.info.currentBuffer$,n=>{!c&&n&&n.end-n.start>0&&y(a)&&(this.logPlayerReady({duration:p()-a}),c=!0)}),s(t.events.firstFrame$,()=>{y(a)&&!c&&(this.logPlayerReady({duration:p()-a}),c=!0),y(h)&&this.logFirstFrame({time:p()-h})}),s(t.info.atLiveEdge$,n=>this.updateContext({liveEdge:n})),s(X({muted:t.info.muted$,volume:t.info.volume$}),({muted:n,volume:u})=>this.updateContext({audible:!n&&u>0})),s(t.info.currentQuality$,n=>this.updateContext({quality:Nt(n)})),s(t.info.isAutoQualityEnabled$,n=>this.updateContext({autoQuality:n})),s(t.info.currentFormat$,n=>this.updateContext({contentType:Ct(n)})),s(t.info.currentPlaybackRate$,n=>this.updateContext({rate:n})),s(t.info.is3DVideo$,n=>this.updateContext({is3d:n}));let d;return s(t.info.hostname$,n=>{const u=d!==void 0&&d!==n;this.updateContext({cdnHostname:n,failover:u}),u&&this.logFailover(n),d=n}),s(t.info.throughputEstimation$,n=>this.updateContext({downloadSpeed:n})),s(t.info.httpConnectionType$,n=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:st(n)}),this.updateContext({connectionType:st(n)})}),s(t.info.httpConnectionReused$,n=>{B(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:n}),this.updateContext({connectionReused:n})}),s(t.info.surface$,n=>this.updateContext({mode:K(n)})),s(X({current:t.info.currentTextTrack$,available:t.info.availableTextTracks$}),({current:n,available:u})=>{const l=u.find(({id:x})=>x===n),E=l&&(l.isAuto?`${l.language}_auto`:l.language);this.updateContext({subtitles:E})}),this.player=t,this.uiEvents&&this.attachToUi(this.uiEvents),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToUi(t){this.uiEvents=t;const{subscription:i,subscribe:s}=z();return this.player&&(s(t.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),s(t.actionSeek$,this.seekAction$),s(t.inPiP$,o=>{const r=o?P.PIP:K(this.player?.info.surface$.getValue());this.updateContext({mode:r})}),s(t.inFullscreen$,o=>{const r=o?P.FULLSCREEN:K(this.player?.info.surface$.getValue());this.updateContext({mode:r})}),s(t.actionSetSubtitle$,o=>this.updateContext({subtitles:o})),s(t.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i)),i}attachToAds(t){const{subscription:i,subscribe:s}=z();return s(t.slotRequested$,()=>this.logAdSlotRequest()),s(t.started$,o=>this.logAdStarted(o)),s(t.paused$,()=>this.logAdPaused()),s(t.resumed$,()=>this.logAdResumed()),s(t.ended$,()=>this.logAdEnded()),s(t.skipped$,()=>this.logAdSkipped()),s(t.clicked$,()=>this.logAdClicked()),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToInteractive(t){const{subscription:i,subscribe:s}=z();return s(t.click$,o=>this.logInterfaceClick(o)),s(t.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i),i}authorize(t){return this.api.authorize(t)}pause(){this.logger.pause(),this.oneStatDebugLog({message:"paused"})}resume(){this.logger.resume(),this.oneStatDebugLog({message:"resumed"})}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.oneStatDebugLog({message:"VSID reset"}),this.vsid$.next(kt())}getDeviceId(){return this.uuid}setFieldBlacklist(){}logInited(){}logReady(t){this.log({operation:"player_ready",param:String(t.time)})}logStarted(...t){this.logActionPlay(...t)}logPlay(){this.log({operation:"play_toggle"})}logPause(t){this.log({operation:"pause",param:String(Math.round(t.position))})}logSeek(t){this.log({operation:"seek",param:t.action,time:t.time})}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:"content_error",param:`${t.fatal?"fatal":"recoverable"}_${t.errorType}`})}logWatchCoverageRecord(t){this.log({operation:"watch_coverage_record",param:`${t.start}-${t.end}`})}logWatchCoverageLive(t){const i=this.timeSynchronisation?.getOffset()??0,s=t.start+i,o=t.end+i;this.log({operation:"watch_coverage_live",param:`${s}-${o}`})}logEmptyBuffer(t){this.log({operation:"empty_buffer",param:String(t.duration)})}logDownloadSpeed(){}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"})}logInterfaceClick(t){this.log({operation:"player_interface_click",param:t})}logNextMovie(t){this.log({operation:"next_movie",param:String(t)})}subscribe(){this.resubscribeBeforeunload();const t=window.navigator.connection;t&&"onchange"in t&&"effectiveType"in t&&this.subscription.add(O(Q(t,"change"),pt(["init"])).subscribe(()=>this.updateContext({network:It(t.effectiveType)}))),this.config.debugLog&&this.debugLogger.log$.subscribe(i=>{console.debug("%c stat ","background:#fa6470;",`component: ${i.component}.`,i.message)})}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=Q(window,"beforeunload").subscribe(()=>this.logger.flush(!0)),this.subscription.add(this.beforeunloadSubscription)}logPlayerReady(t){this.log({operation:"player_ready",param:String(Math.round(t.duration))})}logActionPlay(t){this.log({operation:"action_play",param:String(Math.round(t.position))})}logActionPlayInteractive(t){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(Math.round(t.position))},{vid:this.statContext.projectId})}logFailover(t){this.log({operation:"failover",param:t})}logCloseAtEmptyBuffer(t){this.log({operation:"close_at_empty_buffer",param:String(Math.round(t.duration))})}logActionStop(){this.log({operation:"action_stop"})}log(t,i={}){if(this.disabled){this.oneStatDebugLog({message:`operation ${t.operation} but statistics is disabled`});return}if(this.config.disabledOperations.includes(t.operation)){this.oneStatDebugLog({message:`operation ${t.operation} but it is disabled`});return}this.oneStatDebugLog({message:`operation ${t.operation} ${t.param}`});const s=this.createLogItem(t,i);this.logger.log(s)}createLogItem({operation:t,param:i,time:s},o={}){const r=this.timeSynchronisation?.now()??p(),a=this.vsid$.getValue();mt(a);const h=this.isid$.getValue(),c=t==="empty_buffer"||t==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,d=this.statContext.firstConnectionReused;let n,u;if(this.isEmbed){n=this.embedParent;const E=[...new URLSearchParams(location.search).entries()].filter(([x,V])=>this.config.embedUrlParams.includes(x));u=new URLSearchParams(E).toString()}else this.statContext.place==="direct"&&((this.statContext.refDomain||document.referrer)&&(n=new URL(this.statContext.refDomain||document.referrer).hostname),u=location.href.substring(0,1024));const l={vsid:a,isid:h,vid:this.statContext.movieId,ct:this.statContext.contentType,place:this.isEmbed?"embed":this.statContext.place,quality:this.statContext.quality,cdn_host:this.statContext.cdnHostname,stat_type:this.statContext.autoplay===!0?F.AUTO:this.statContext.autoplay===!1?F.MANUAL:void 0,param:i,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode,connection_type:c,connection_reused:d===!0?A.YES:d===!1?A.NO:void 0,cached_data:this.statContext.cached===!0?A.YES:this.statContext.cached===!1?A.NO:void 0,live:this.statContext.liveEdge?A.YES:void 0,muted:this.statContext.audible===!1?A.YES:void 0,mode:this.statContext.mode,subtitles:this.statContext.subtitles,download_speed:this.statContext.downloadSpeed,manual_quality:this.statContext.autoQuality?void 0:A.YES,ref_domain:n,direct_url:u,rate:this.statContext.rate===1||B(this.statContext.rate)?void 0:this.statContext.rate.toFixed(2),view_360:this.statContext.is3d?1:void 0,aid:this.statContext.albumId,vk_playlist_id:this.statContext.vkPlaylistId,...o};for(const E of this.config.disabledCustomFields)delete l[E];return{operation:t,type:1,time:s,network:this.statContext.network,timestamp:r,custom:l}}}export{_ as ApiEnv,L as ConnectionType,g as ContentType,Z as InteractiveInterfaceClick,Ut as OneStat,m as Quality,U as SeekAction,tt as VERSION};
|
|
6
|
+
var E=(r=>(r.PROD="prod",r.VK_ALIAS="vk_alias",r.VIDEOTEST="videotest",r.TEST="test",r.AUTO="auto",r))(E||{}),N=(u=>(u.Q144P="mobile",u.Q240P="lowest",u.Q360P="low",u.Q480P="medium",u.Q720P="high",u.Q1080P="fullhd",u.Q1440P="quadhd",u.Q2160P="ultrahd",u.UNKNOWN="unknown",u))(N||{}),D=(c=>(c.MP4="mp4",c.DASH="dash",c.DASH_SEP="dash_sep",c.ONDEMAND_DASH="ondemand_dash",c.HLS="hls",c.ONDEMAND_HLS="ondemand_hls",c.WEBM="webm",c.AV1="av1",c.ONDEMAND_DASH_LIVE="ondemand_dash_live",c.ONDEMAND_HLS_LIVE="ondemand_hls_live",c.WEBRTC="webrtc",c.UNKNOWN="unknown",c.RTMP="rtmp",c))(D||{});var M=(t=>(t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3",t))(M||{});var B=(d=>(d.SLIDER="slider",d.DOUBLE_TAP="double_tap",d.TIME_CODE="time_code",d.EPISODE="episode",d.REWIND="rewind",d.LIVE="live",d.UNKNOWN="unknown",d))(B||{}),ee=(r=>(r.GRAPH_SHOW="iGraphShow",r.GRAPH_HIDE="iGraphHide",r.NEXT_AREA="iNextChapterArea",r.NEXT_BUTTON="iNextChapterBtn",r.WATCH_AGAIN="iWatchAgainBtn",r))(ee||{}),te={action_play:"ap",action_play_interactive:"api",first_bytes:"fb",player_ready:"pr",first_frame:"ff",seek:"sk",watch_coverage_record:"wr",watch_coverage_live:"wl",empty_buffer:"eb",action_stop:"as",close_at_empty_buffer:"cb",content_error:"er",player_interface_click:"pc",next_movie:"nm",track_switch:"ts",failover:"fo"},ie={vsid:"si",isid:"is",vid:"vi",place:"pl",quality:"qt",cdn_host:"ch",stat_type:"st",param:"pm",vk_app_id:"va",track_code:"tc",connection_type:"cnt",connection_reused:"cr",cached_data:"cd",live:"lv",muted:"mu",mode:"mo",subtitles:"sb",failover:"fo",download_speed:"ds",manual_quality:"mq",ref_domain:"rd",direct_url:"du"},oe={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},se={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv"};import{fillWithDefault as Ae}from"@vkontakte/videoplayer-shared";var xe={apiEnv:"vk_alias",requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:[],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1}},re=n=>Ae(n,xe);function F(){let n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36),i=0,t,o;for(o=0;o<36;o++)o===8||o===13||o===18||o===23?e[o]="-":o===14?e[o]="4":(i<=2&&(i=33554432+Math.random()*16777216|0),t=i&15,i=i>>4,e[o]=n[o===19?t&3|8:t]);return e.join("")}import{assertNonNullable as Be,combine as Ie,fromEvent as Se,isNonNullable as y,isNullable as ye,merge as Fe,now as m,observableFrom as Ve,once as Ue,safeStorage as Q,Subject as We,Subscription as X,ValueSubject as j}from"@vkontakte/videoplayer-shared";import{Logger as He,detectEmbed as Ke}from"@vkontakte/videoplayer-shared";var ne=n=>{let{operation:e,custom:i}=n,t=Object.fromEntries(Object.entries(i).map(([o,r])=>{let a=ie[o]??o,d=r;return r&&(o==="mode"?d=se[r]??r:o==="quality"&&(d=oe[r]??r)),[a,d]}));return{...n,operation:te[e]??e,custom:t}};var T="1.0.50",ae="CIOPGQJGDIHBABABA",V={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",auto:""};import{ValueSubject as Te,getExponentialDelay as Ce,ErrorCategory as I}from"@vkontakte/videoplayer-shared";var _=class{constructor(e){this.consequentAuthErrors=0;this.authorized$=new Te(!1);this.params=e}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){let i="log.externalLog",t=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(i,t,o)||this.logRequest(e)}async logRequest(e){let i="log.externalLog",t=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;let r=async(a,d=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(i,t,o)}catch(p){if(!p||!("error_code"in p)){this.params.error$.next({id:"logRequestUnknown",category:I.NETWORK,message:`Unknown ${i} error`,thrown:p});return}let u=p?.error_code;switch(u){case 102:case 103:case 104:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),d>0?r(a,d-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),d>0?r(a,d-1):void 0;default:{this.params.error$.next({id:`LogRequest#${u}`,category:I.EXTERNAL_API,message:`${i} error`,data:p});return}}}};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:${T}`,platform:this.params.mobile?"M_WEB":"WEB",items:this.params.config.shorten?e.map(ne):e})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();let e=Ce(this.consequentAuthErrors,this.params.config.backoff);return new Promise(i=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(i).catch(t=>this.params.error$.next({id:"AuthorizeBackoff",category:I.NETWORK,message:"Otherwise unhandled error in authorization",thrown:t})).finally(()=>this.backoffTimeoutId=0)},e))})}async _authorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);let e="auth.anonymLogin",i={session_data:{version:2,device_id:this.params.uuid,client_version:T.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(i.session_data.auth_token=this.authToken,i.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,i).then(t=>((!t||!t.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:I.EXTERNAL_API,message:"No session key",data:t}),this.sessionKey=t?.session_key??void 0,this.sessionKey)).catch(async t=>{this.sessionKey=void 0;let o=t?.error_code;switch(o){case 401:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}o?this.params.error$.next({id:`Authorize#${o}`,category:I.EXTERNAL_API,message:"authorize error",data:t}):this.params.error$.next({id:"AuthorizeUnknown",category:I.NETWORK,message:"authorize error",thrown:t})}).finally(()=>{this.authorizePromise=void 0,this.consequentAuthErrors=this.sessionKey?0:this.consequentAuthErrors+1,this.authorized$.next(this.sessionKey!==void 0)}),this.authorizePromise}};import{ErrorCategory as C,now as U}from"@vkontakte/videoplayer-shared";var A=class{constructor(e){this.params=e,this.apiKey=e.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=V[this.apiEnv],this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}async resolveApiBaseUrl(){if(this.apiEnv!=="auto"||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{let e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),o=(await(await fetch(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!o)throw new Error("Wrong DNS response");return o}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:C.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),V.vk_alias}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,i,t){if(!window.Blob||!window.navigator.sendBeacon)return!1;let o=this._prepareQueryParams({method:e,queryParams:i,sessionKey:t}),r=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,r)}catch(a){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:C.NETWORK,message:"Unhandled beacon error",thrown:a,data:{method:e,params:i}})}return!1}async sendRequest(e,i,t){let o=U(),r=a=>{if(a instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(a.message)){this.params.error$.next({id:"Network",category:C.NETWORK,message:"Request failed",thrown:a});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:C.NETWORK,message:"Unhandled request error",thrown:a,data:{method:e,params:i,sessionKey:t,time:U()-o}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),fetch(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:i,sessionKey:t})}).then(a=>{let d=Number(a.headers.get("content-length"))===0,p=new Date(a.headers.get("date")??"").getTime(),u=U()-o;if(isFinite(p)&&this.timeSynchronisation?.addServerTime(p,u),!d)return a.json().then(s=>Object.prototype.hasOwnProperty.call(s,"error_msg")?Promise.reject(s):s,r)},r)}_prepareQueryParams(e){let i=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&i.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([t,o])=>i.append(t,typeof o=="string"?o:JSON.stringify(o))),i}};import{ErrorCategory as we,now as ke,safeStorage as x,debounceFn as de}from"@vkontakte/videoplayer-shared";var w="onestat_events",W=n=>e=>e.timestamp+n>=ke(),k=class{constructor(e){this.unsaltedStorage=[];this.isPaused=!1;this.isUrgent=e=>{let{operation:i}=e;return["action_play","watch_coverage_record","watch_coverage_live"].includes(i)};this.params=e,this.api=e.api,this.error$=e.error$,this.userSalt=e.userSalt,this.loggerDebugLog=e.debugLogger.createComponentLog("stat logger"),this.firstFlush=de(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let i=x.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=de(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:i}),this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()}),this.housekeepStorage()}safeFlush(){try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:we.WTF,message:String(e)??"Unknown logger error",thrown:e})}}readFromStorage(){let e=x.get(w);try{return e?JSON.parse(e):{}}catch{}return{}}addToStorage(e){if(!this.userSalt){this.unsaltedStorage.push(e);return}let i=this.readFromStorage(),o=(i[this.userSalt]??[]).filter(W(this.params.config.storageExpiration));x.set(w,JSON.stringify({...i,[this.userSalt]:[...o,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(W(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],x.set(w,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[i,t]of Object.entries(e)){let o=t.filter(W(this.params.config.storageExpiration));o.length?e[i]=o:delete e[i],this.loggerDebugLog({message:`${t.length} retrieved from storage, ${o.length} of them actual`})}x.set(w,JSON.stringify(e))}log(e){this.addToStorage(e),!this.isPaused&&(this.isUrgent(e)?this.flush():this.lastVsid!==e.custom.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=e.custom.vsid)}flush(e=!1){let i=this.getFromStorage();i.length!==0&&(this.api.authorized$.getValue()?(e&&this.params.config.useBeacon?(this.loggerDebugLog({message:`Flushing ${i.length} events through beacon`}),this.api.logBeacon(i)):(this.loggerDebugLog({message:`Flushing ${i.length} events`}),this.api.logRequest(i)),this.markStorageSent()):this.api.authorize(),this.firstFlush.cancel(),this.debouncedFlush.cancel())}pause(){this.isPaused=!0,this.debouncedFlush.cancel()}resume(){this.isPaused=!1,this.debouncedFlush()}destroy(){this.subscription.unsubscribe(),this.firstFlush.cancel(),this.debouncedFlush.cancel()}};import{HttpConnectionType as H,Surface as S,VideoFormat as f,VideoQuality as g}from"@vkontakte/videoplayer-core";import{assertNever as ue}from"@vkontakte/videoplayer-shared";var ce=n=>n&&{[g.INVARIANT]:"unknown",[g.Q_144P]:"mobile",[g.Q_240P]:"lowest",[g.Q_360P]:"low",[g.Q_480P]:"medium",[g.Q_720P]:"high",[g.Q_1080P]:"fullhd",[g.Q_1440P]:"quadhd",[g.Q_2160P]:"ultrahd",[g.Q_4320P]:"unknown"}[n],K=n=>n&&{[H.HTTP1]:"http1",[H.HTTP2]:"http2",[H.QUIC]:"http3"}[n],le=n=>{if(n!==void 0)switch(n){case f.MPEG:return"mp4";case f.DASH_LIVE:return"dash";case f.DASH_SEP:return"dash_sep";case f.DASH_ONDEMAND:return"ondemand_dash";case f.DASH_WEBM:case f.DASH_LIVE_WEBM:return"webm";case f.DASH_WEBM_AV1:return"av1";case f.DASH_LIVE_CMAF:return"ondemand_dash_live";case f.HLS:case f.HLS_LIVE:return"hls";case f.HLS_ONDEMAND:return"ondemand_hls";case f.HLS_LIVE_CMAF:return"ondemand_hls_live";case f.WEB_RTC_LIVE:return"webrtc";default:return ue(n)}},L=n=>{if(n!==void 0)switch(n){case S.NONE:case S.INLINE:return;case S.FULLSCREEN:return"fullscreen";case S.SECOND_SCREEN:return"chromecast";case S.PIP:return"pip";case S.INVISIBLE:return"invisible";default:return ue(n)}},pe=n=>{switch(n){case"slow-2g":return"poor";case"2g":return"poor";case"3g":return"good";case"4g":return"excellent"}};var $=class{constructor(e){this.offset=void 0;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,i){let t=Date.now(),o=e-t-i/2;if(Math.abs(o)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(o):this.offset=Math.round(.2*o+(1-.2)*this.offset)}};var he=()=>Math.floor(Math.random()*4294967296).toString(36).padStart(7,"0"),fe=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");import{PlaybackState as ge}from"@vkontakte/videoplayer-core";import{filter as me,filterChanged as $e,fromEvent as Re,isNullable as be,map as Oe,merge as q,Observable as Ne,Subject as z,Subscription as De,ValueSubject as Me}from"@vkontakte/videoplayer-shared";var ve=(n,e)=>new Ne(i=>{let t=new De,o=q(Re(window,"beforeunload"),n.events.willDestruct$),r=new Me(void 0),a;t.add(n.info.isLive$.pipe($e()).subscribe(b=>{a&&(a.unsubscribe(),r.next(void 0)),b?a=n.info.liveTime$.pipe(Oe(O=>O&&O/1e3)).subscribe(r):a=n.info.position$.subscribe(r),t.add(a)}));let{playing$:d,paused$:p}=n.events,u=n.events.willSeek$.pipe(me(()=>n.info.playbackState$.getValue()===ge.PLAYING)),s=n.events.seeked$.pipe(me(()=>n.info.playbackState$.getValue()===ge.PLAYING)),l=!1,h=new z;t.add(u.subscribe(()=>{l||h.next(),l=!0})),t.add(s.subscribe(()=>l=!1));let c=new z,v=new z,R=q(d,s,c),Z=q(p,h,o,n.events.looped$,v),P,Pe=()=>P=r.getValue(),Ee=()=>{let b=r.getValue();be(P)||P===b||be(b)||(i.next({from:P,to:b}),P=void 0)},_e=()=>{v.next(),c.next()};if(t.add(R.subscribe(Pe)),t.add(Z.subscribe(Ee)),e.forceInterval&&isFinite(e.forceInterval)){let b=0;t.add(R.subscribe(()=>b=window.setTimeout(_e,e.forceInterval))),t.add(Z.subscribe(()=>window.clearTimeout(b)))}return t});var qe="_one-stat_",G=`${qe}uuid`,Y=()=>{let n=new X;return{subscription:n,subscribe:(e,i)=>{e&&n.add(e.subscribe(i))}}},J=class{constructor(e,i){this.subscription=new X;this.debugLogger=new He;this.oneStatDebugLog=this.debugLogger.createComponentLog("onestat");this.loopCounter=0;this.disabled=!1;this.vsid$=new j(void 0);this.isid$=new j(void 0);this.seekAction$=new j("unknown");this.statContext=e,this.config=re(i.config??{}),y(i.apiEnv)&&(this.config.apiEnv=i.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new $);let t=new We;this.experimental={error$:t};let o=Q.get(G);o?o.startsWith('"')&&o.endsWith('"')?(this.uuid=o.replaceAll('"',""),Q.set(G,this.uuid)):this.uuid=o:(this.uuid=F(),Q.set(G,this.uuid)),this.resetViewSession(),i.useIsid&&this.isid$.next(i.isid??fe());let r=new A({apiKey:ae,config:this.config,error$:t,timeSynchronisation:this.timeSynchronisation});this.api=new _({config:this.config,apiTransport:r,refreshAuthToken:i.refreshAuthToken,mobile:this.statContext.mobile??!1,uuid:this.uuid,error$:t}),this.logger=new k({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:t,userSalt:i.userSalt});let{isEmbed:a,host:d}=Ke();this.isEmbed=a,this.embedParent=d,this.subscribe()}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let i=new X,t=(s,l)=>i.add(s.subscribe(l));t(e.events.willStart$,()=>{let s=e.info.position$.getValue();this.logActionPlay({position:s}),this.statContext.projectId&&this.logActionPlayInteractive({position:s})}),t(e.events.looped$,()=>{this.resetViewSession(),++this.loopCounter>this.config.maxLoops&&(this.disabled=!0),this.logActionPlay({position:e.info.position$.getValue()})}),t(e.events.seeked$,()=>{this.logSeek({action:this.seekAction$.getValue(),time:e.info.position$.getValue()}),this.seekAction$.next("unknown")}),t(e.events.paused$,()=>{this.logPause({position:e.info.position$.getValue()})}),t(e.events.willResume$,()=>{this.logPlay()}),t(e.events.started$,()=>{this.statContext.clip&&this.logWatchCoverageRecord({start:0,end:0})}),t(ve(e,{forceInterval:this.config.watchCoverageInterval}),s=>{let l=e.info.isLive$.getValue(),h={start:parseFloat(s.from.toFixed(3)),end:parseFloat(s.to.toFixed(3))};l?this.logWatchCoverageLive(h):this.logWatchCoverageRecord(h)});let o;t(e.info.isStalled$,s=>{s?o=m():(y(o)&&this.logEmptyBuffer({duration:m()-o}),o=void 0)});let r=!1;i.add(e.events.fatalError$.pipe(Ue()).subscribe(()=>r=!0)),t(e.events.willStop$,()=>{if(e.info.isStalled$.getValue()){let l=y(o)?m()-o:void 0;this.logCloseAtEmptyBuffer({duration:l??0}),o=void 0}else r||this.logActionStop()}),t(e.events.managedError$,({id:s})=>{this.logError({fatal:!1,errorType:s})}),t(e.events.fatalError$,({id:s})=>{this.logError({fatal:!0,errorType:s})});let a,d,p=!1;t(e.events.firstBytes$,s=>{a=m(),this.logFirstBytes({time:s})}),t(e.events.willStart$,()=>d=m()),t(e.info.currentBuffer$,s=>{!p&&s&&s.end-s.start>0&&y(a)&&(this.logPlayerReady({duration:m()-a}),p=!0)}),t(e.events.firstFrame$,()=>{y(a)&&!p&&(this.logPlayerReady({duration:m()-a}),p=!0),y(d)&&this.logFirstFrame({time:m()-d})}),t(e.info.atLiveEdge$,s=>this.updateContext({liveEdge:s})),t(Ie({muted:e.info.muted$,volume:e.info.volume$}),({muted:s,volume:l})=>this.updateContext({audible:!s&&l>0})),t(e.info.currentQuality$,s=>this.updateContext({quality:ce(s)})),t(e.info.isAutoQualityEnabled$,s=>this.updateContext({autoQuality:s})),t(e.info.currentFormat$,s=>this.updateContext({contentType:le(s)})),t(e.info.currentPlaybackRate$,s=>this.updateContext({rate:s})),t(e.info.is3DVideo$,s=>this.updateContext({is3d:s}));let u;return t(e.info.hostname$,s=>{let l=u!==void 0&&u!==s;this.updateContext({cdnHostname:s,failover:l}),l&&this.logFailover(s),u=s}),t(e.info.throughputEstimation$,s=>this.updateContext({downloadSpeed:s})),t(e.info.httpConnectionType$,s=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:K(s)}),this.updateContext({connectionType:K(s)})}),t(e.info.httpConnectionReused$,s=>{ye(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:s}),this.updateContext({connectionReused:s})}),t(e.info.surface$,s=>this.updateContext({mode:L(s)})),t(Ie({current:e.info.currentTextTrack$,available:e.info.availableTextTracks$}),({current:s,available:l})=>{let h=l.find(({id:v})=>v===s),c=h&&(h.isAuto?`${h.language}_auto`:h.language);this.updateContext({subtitles:c})}),this.player=e,this.uiEvents&&this.attachToUi(this.uiEvents),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToUi(e){this.uiEvents=e;let{subscription:i,subscribe:t}=Y();return this.player&&(t(e.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),t(e.actionSeek$,this.seekAction$),t(e.inPiP$,o=>{let r=o?"pip":L(this.player?.info.surface$.getValue());this.updateContext({mode:r})}),t(e.inFullscreen$,o=>{let r=o?"fullscreen":L(this.player?.info.surface$.getValue());this.updateContext({mode:r})}),t(e.actionSetSubtitle$,o=>this.updateContext({subtitles:o})),t(e.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i)),i}attachToAds(e){let{subscription:i,subscribe:t}=Y();return t(e.slotRequested$,()=>this.logAdSlotRequest()),t(e.started$,o=>this.logAdStarted(o)),t(e.paused$,()=>this.logAdPaused()),t(e.resumed$,()=>this.logAdResumed()),t(e.ended$,()=>this.logAdEnded()),t(e.skipped$,()=>this.logAdSkipped()),t(e.clicked$,()=>this.logAdClicked()),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToInteractive(e){let{subscription:i,subscribe:t}=Y();return t(e.click$,o=>this.logInterfaceClick(o)),t(e.nextMovie$,o=>this.logNextMovie(o)),this.resubscribeBeforeunload(),this.subscription.add(i),i}authorize(e){return this.api.authorize(e)}pause(){this.logger.pause(),this.oneStatDebugLog({message:"paused"})}resume(){this.logger.resume(),this.oneStatDebugLog({message:"resumed"})}destroy(){this.logger.flush(),this.subscription.unsubscribe(),this.api.destroy(),this.logger.destroy()}resetViewSession(){this.oneStatDebugLog({message:"VSID reset"}),this.vsid$.next(he())}getDeviceId(){return this.uuid}setFieldBlacklist(){}logInited(){}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(...e){this.logActionPlay(...e)}logPlay(){this.log({operation:"play_toggle"})}logPause(e){this.log({operation:"pause",param:String(Math.round(e.position))})}logSeek(e){this.log({operation:"seek",param:e.action,time:e.time})}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:"content_error",param:`${e.fatal?"fatal":"recoverable"}_${e.errorType}`})}logWatchCoverageRecord(e){this.log({operation:"watch_coverage_record",param:`${e.start}-${e.end}`})}logWatchCoverageLive(e){let i=this.timeSynchronisation?.getOffset()??0,t=e.start+i,o=e.end+i;this.log({operation:"watch_coverage_live",param:`${t}-${o}`})}logEmptyBuffer(e){this.log({operation:"empty_buffer",param:String(e.duration)})}logDownloadSpeed(){}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"})}logInterfaceClick(e){this.log({operation:"player_interface_click",param:e})}logNextMovie(e){this.log({operation:"next_movie",param:String(e)})}subscribe(){this.resubscribeBeforeunload();let e=window.navigator.connection;e&&"onchange"in e&&"effectiveType"in e&&this.subscription.add(Fe(Se(e,"change"),Ve(["init"])).subscribe(()=>this.updateContext({network:pe(e.effectiveType)}))),this.config.debugLog&&this.debugLogger.log$.subscribe(i=>{console.debug("%c stat ","background:#fa6470;",`component: ${i.component}.`,i.message)})}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=Se(window,"beforeunload").subscribe(()=>this.logger.flush(!0)),this.subscription.add(this.beforeunloadSubscription)}logPlayerReady(e){this.log({operation:"player_ready",param:String(Math.round(e.duration))})}logActionPlay(e){this.log({operation:"action_play",param:String(Math.round(e.position))})}logActionPlayInteractive(e){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(Math.round(e.position))},{vid:this.statContext.projectId})}logFailover(e){this.log({operation:"failover",param:e})}logCloseAtEmptyBuffer(e){this.log({operation:"close_at_empty_buffer",param:String(Math.round(e.duration))})}logActionStop(){this.log({operation:"action_stop"})}log(e,i={}){if(this.disabled){this.oneStatDebugLog({message:`operation ${e.operation} but statistics is disabled`});return}if(this.config.disabledOperations.includes(e.operation)){this.oneStatDebugLog({message:`operation ${e.operation} but it is disabled`});return}this.oneStatDebugLog({message:`operation ${e.operation} ${e.param}`});let t=this.createLogItem(e,i);this.logger.log(t)}createLogItem({operation:e,param:i,time:t},o={}){let r=this.timeSynchronisation?.now()??m(),a=this.vsid$.getValue();Be(a);let d=this.isid$.getValue(),p=e==="empty_buffer"||e==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,u=this.statContext.firstConnectionReused,s,l;if(this.isEmbed){s=this.embedParent;let c=[...new URLSearchParams(location.search).entries()].filter(([v,R])=>this.config.embedUrlParams.includes(v));l=new URLSearchParams(c).toString()}else this.statContext.place==="direct"&&((this.statContext.refDomain||document.referrer)&&(s=new URL(this.statContext.refDomain||document.referrer).hostname),l=location.href.substring(0,1024));let h={vsid:a,isid:d,vid:this.statContext.movieId,ct:this.statContext.contentType,place:this.isEmbed?"embed":this.statContext.place,quality:this.statContext.quality,cdn_host:this.statContext.cdnHostname,stat_type:this.statContext.autoplay===!0?"auto":this.statContext.autoplay===!1?"":void 0,param:i,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode,connection_type:p,connection_reused:u===!0?1:u===!1?0:void 0,cached_data:this.statContext.cached===!0?1:this.statContext.cached===!1?0:void 0,live:this.statContext.liveEdge?1:void 0,muted:this.statContext.audible===!1?1:void 0,mode:this.statContext.mode,subtitles:this.statContext.subtitles,download_speed:this.statContext.downloadSpeed,manual_quality:this.statContext.autoQuality?void 0:1,ref_domain:s,direct_url:l,rate:this.statContext.rate===1||ye(this.statContext.rate)?void 0:this.statContext.rate.toFixed(2),view_360:this.statContext.is3d?1:void 0,aid:this.statContext.albumId,vk_playlist_id:this.statContext.vkPlaylistId,...o};for(let c of this.config.disabledCustomFields)delete h[c];return{operation:e,type:1,time:t,network:this.statContext.network,timestamp:r,custom:h}}};export{E as ApiEnv,M as ConnectionType,D as ContentType,ee as InteractiveInterfaceClick,J as OneStat,N as Quality,B as SeekAction,T as VERSION};
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/videoplayer-statistics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"author": "vk.com",
|
|
5
5
|
"description": "Statistics library for vk.com videoplayer",
|
|
6
6
|
"homepage": "https://vk.com",
|
|
7
7
|
"license": "GPL-3.0",
|
|
8
8
|
"main": "./esnext.cjs.js",
|
|
9
9
|
"module": "./esnext.esm.js",
|
|
10
|
-
"types": "./index.d.ts",
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./esnext.esm.js",
|
|
15
15
|
"require": "./esnext.cjs.js",
|
|
16
|
-
"types": "./index.d.ts"
|
|
16
|
+
"types": "./types/index.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"./evergreen": {
|
|
19
19
|
"import": "./evergreen.esm.js",
|
|
20
20
|
"require": "./evergreen.cjs.js",
|
|
21
|
-
"types": "./index.d.ts"
|
|
21
|
+
"types": "./types/index.d.ts"
|
|
22
22
|
},
|
|
23
23
|
"./esnext": {
|
|
24
24
|
"import": "./esnext.esm.js",
|
|
25
25
|
"require": "./esnext.cjs.js",
|
|
26
|
-
"types": "./index.d.ts"
|
|
26
|
+
"types": "./types/index.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"./es2018": {
|
|
29
29
|
"import": "./es2018.esm.js",
|
|
30
30
|
"require": "./es2018.cjs.js",
|
|
31
|
-
"types": "./index.d.ts"
|
|
31
|
+
"types": "./types/index.d.ts"
|
|
32
32
|
},
|
|
33
33
|
"./es2015": {
|
|
34
34
|
"import": "./es2015.esm.js",
|
|
35
35
|
"require": "./es2015.cjs.js",
|
|
36
|
-
"types": "./index.d.ts"
|
|
36
|
+
"types": "./types/index.d.ts"
|
|
37
37
|
},
|
|
38
38
|
"./evergreen.esm.js": "./evergeen.esm.js",
|
|
39
39
|
"./esnext.esm.js": "./esnext.esm.js",
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"@vkontakte/videoplayer-shared": "^1.0.36"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@vkontakte/videoplayer-core": "^2.0.
|
|
55
|
+
"@vkontakte/videoplayer-core": "^2.0.104"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/types/Api.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IConfig } from './config';
|
|
2
|
+
import { ILogItem } from './types';
|
|
3
|
+
import { IApiTransport } from './ApiTransport';
|
|
4
|
+
import { ISubject, IError, ValueSubject, IValueObservable } from '@vkontakte/videoplayer-shared';
|
|
5
|
+
export interface IApi {
|
|
6
|
+
authorize(authToken?: string): Promise<string | undefined>;
|
|
7
|
+
logRequest(items: ILogItem[]): Promise<void>;
|
|
8
|
+
logBeacon(items: ILogItem[]): void;
|
|
9
|
+
authorized$: IValueObservable<boolean>;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface IApiParams {
|
|
13
|
+
config: IConfig;
|
|
14
|
+
apiTransport: IApiTransport;
|
|
15
|
+
refreshAuthToken?: () => Promise<string | undefined>;
|
|
16
|
+
mobile: boolean;
|
|
17
|
+
uuid: string;
|
|
18
|
+
error$: ISubject<IError>;
|
|
19
|
+
}
|
|
20
|
+
export default class Api implements IApi {
|
|
21
|
+
private params;
|
|
22
|
+
private authToken;
|
|
23
|
+
private sessionKey;
|
|
24
|
+
private authorizePromise?;
|
|
25
|
+
private refreshAuthTokenPromise?;
|
|
26
|
+
private consequentAuthErrors;
|
|
27
|
+
authorized$: ValueSubject<boolean>;
|
|
28
|
+
private backoffTimeoutId;
|
|
29
|
+
constructor(params: IApiParams);
|
|
30
|
+
authorize(authToken?: string): Promise<string | undefined>;
|
|
31
|
+
logBeacon(items: ILogItem[]): void;
|
|
32
|
+
logRequest(items: ILogItem[]): Promise<void>;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
private refreshAuthToken;
|
|
35
|
+
private createLogParams;
|
|
36
|
+
private _authorizeWithBackoff;
|
|
37
|
+
private _authorize;
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IConfig } from './config';
|
|
2
|
+
import { IError, ISubject } from '@vkontakte/videoplayer-shared';
|
|
3
|
+
import type { TimeSynchronisation } from './utils/timeSynchronisation';
|
|
4
|
+
export interface IApiTransportParams {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
config: IConfig;
|
|
7
|
+
error$: ISubject<IError>;
|
|
8
|
+
timeSynchronisation?: TimeSynchronisation;
|
|
9
|
+
}
|
|
10
|
+
export interface IApiTransport {
|
|
11
|
+
sendBeacon(method: string, params: Record<string, unknown>, sessionKey?: string): boolean;
|
|
12
|
+
sendRequest<T = unknown>(method: string, params: Record<string, unknown>, sessionKey?: string): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
export default class ApiTransport implements IApiTransport {
|
|
15
|
+
private apiKey;
|
|
16
|
+
private apiBaseUrl;
|
|
17
|
+
private apiEnv;
|
|
18
|
+
private timeSynchronisation?;
|
|
19
|
+
private isApiBaseUrlFetched;
|
|
20
|
+
private params;
|
|
21
|
+
constructor(params: IApiTransportParams);
|
|
22
|
+
private resolveApiBaseUrl;
|
|
23
|
+
sendBeacon(method: string, params: Record<string, unknown>, sessionKey?: string): boolean;
|
|
24
|
+
sendRequest<T = unknown>(method: string, params: Record<string, unknown>, sessionKey?: string): Promise<T>;
|
|
25
|
+
private _prepareQueryParams;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IConfig } from './config';
|
|
2
|
+
import { ILogger as IDebugLogger, IError, ISubject } from '@vkontakte/videoplayer-shared';
|
|
3
|
+
import { IApi } from './Api';
|
|
4
|
+
import { ILogItem } from './types';
|
|
5
|
+
export interface ILoggerParams {
|
|
6
|
+
config: IConfig;
|
|
7
|
+
api: IApi;
|
|
8
|
+
debugLogger: IDebugLogger;
|
|
9
|
+
error$: ISubject<IError>;
|
|
10
|
+
userSalt?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class Logger {
|
|
13
|
+
private params;
|
|
14
|
+
private api;
|
|
15
|
+
private error$;
|
|
16
|
+
private subscription;
|
|
17
|
+
private userSalt;
|
|
18
|
+
private unsaltedStorage;
|
|
19
|
+
private lastVsid;
|
|
20
|
+
private isPaused;
|
|
21
|
+
private firstFlush;
|
|
22
|
+
private debouncedFlush;
|
|
23
|
+
private loggerDebugLog;
|
|
24
|
+
constructor(params: ILoggerParams);
|
|
25
|
+
private isUrgent;
|
|
26
|
+
private safeFlush;
|
|
27
|
+
private readFromStorage;
|
|
28
|
+
private addToStorage;
|
|
29
|
+
private getFromStorage;
|
|
30
|
+
private markStorageSent;
|
|
31
|
+
private housekeepStorage;
|
|
32
|
+
log(item: ILogItem): void;
|
|
33
|
+
flush(wantBeacon?: boolean): void;
|
|
34
|
+
pause(): void;
|
|
35
|
+
resume(): void;
|
|
36
|
+
destroy(): void;
|
|
37
|
+
}
|