@vkontakte/videoplayer-statistics 1.0.95 → 1.0.96-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/evergreen.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-statistics v1.0.95
3
- * Tue, 16 Dec 2025 09:25:43 GMT
4
- * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-95/doc/
2
+ * @vkontakte/videoplayer-statistics v1.0.96-beta.0
3
+ * Fri, 23 Jan 2026 11:09:42 GMT
4
+ * https://st.mycdn.me/static/vkontakte-videoplayer/1-0-96/doc/
5
5
  */
6
- var Nt=Object.defineProperty;var Mt=(n,e)=>{for(var i in e)Nt(n,i,{get:e[i],enumerable:!0})};var U=(d=>(d.PROD="prod",d.VK_ALIAS="vk_alias",d.VIDEOTEST="videotest",d.TEST="test",d.OKCDN="okcdn",d.AUTO="auto",d))(U||{}),pe=(r=>(r.Q144P="mobile",r.Q240P="lowest",r.Q360P="low",r.Q480P="medium",r.Q720P="high",r.Q1080P="fullhd",r.Q1440P="quadhd",r.Q2160P="ultrahd",r.UNKNOWN="unknown",r))(pe||{}),fe=(f=>(f.MP4="mp4",f.DASH="dash",f.DASH_SEP="dash_sep",f.ONDEMAND_DASH="ondemand_dash",f.HLS="hls",f.HLS_FMP4="hls_fmp4",f.ONDEMAND_HLS="ondemand_hls",f.WEBM="webm",f.AV1="av1",f.ONDEMAND_DASH_LIVE="ondemand_dash_live",f.ONDEMAND_HLS_LIVE="ondemand_hls_live",f.WEBRTC="webrtc",f.UNKNOWN="unknown",f.RTMP="rtmp",f))(fe||{});var ge=(t=>(t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3",t))(ge||{});var me=(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))(me||{}),qe=(s=>(s.GRAPH_SHOW="iGraphShow",s.GRAPH_HIDE="iGraphHide",s.NEXT_AREA="iNextChapterArea",s.NEXT_BUTTON="iNextChapterBtn",s.WATCH_AGAIN="iWatchAgainBtn",s))(qe||{}),Qe={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",quality:"qt"},We={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"},Ke={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},ze={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv",minimal:"minimal"};import{fillWithDefault as Vt}from"@vkontakte/videoplayer-shared/evergreen";var je="CIOPGQJGDIHBABABA",ve={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",okcdn:"https://api.okcdn.ru",auto:""};var Ot={apiEnv:"vk_alias",apiKey:je,apiBaseUrl:null,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:["quality"],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,clearStorageAtUnload:!0,useVKComIsMobileLogic:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1},useKeepalive:!1,watchCoverageTimeoutFix:!1},Ge=n=>Vt(n,Ot);function be(){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 ei,combine as at,fromEvent as dt,isNonNullable as V,isNullable as ct,merge as ti,now as $,observableFrom as ii,once as oi,safeStorage as lt,Subject as ri,Subscription as we,ValueSubject as J}from"@vkontakte/videoplayer-shared/evergreen";import{Logger as si,detectEmbed as ni}from"@vkontakte/videoplayer-shared/evergreen";var Ft=()=>Math.floor(Math.random()*4294967296).toString(36).padStart(13,"0"),R=class n{static getVSID(){return n.vsid}static generateVSID(){return n.vsid=Ft(),n.vsid}};var Ye=n=>{let{operation:e,custom:i}=n,t=Object.fromEntries(Object.entries(i).map(([o,s])=>{let d=We[o]??o,c=s;return s&&(o==="mode"?c=ze[s]??s:o==="quality"&&(c=Ke[s]??s)),[d,c]}));return{...n,operation:Qe[e]??e,custom:t}};var _="1.0.95";import{ValueSubject as Bt,getExponentialDelay as Ut,ErrorCategory as N}from"@vkontakte/videoplayer-shared/evergreen";var Ht=/Mobile|mini|Fennec|Android|iP(ad|od|hone)|opera (mini|mobi)/i,H=class{constructor(e){this.consequentAuthErrors=0;this.authorized$=new Bt(!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).catch(()=>{})}async logRequest(e){let i="log.externalLog",t=this.createLogParams(e),o=this.sessionKey??await this._authorizeWithBackoff();if(!o)return;let s=async(d,c=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(i,t,o)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:N.NETWORK,message:`Unknown ${i} error`,thrown:h});return}let r=h?.error_code;switch(r){case 102:case 103:case 104:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),c>0?s(d,c-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),c>0?s(d,c-1):void 0;default:{this.params.error$.next({id:`LogRequest#${r}`,category:N.EXTERNAL_API,message:`${i} error`,data:h});return}}}};return s(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){let i="WEB",t=!1,o=`@vkontakte/videoplayer-statistics:${_}`;if(this.params.config.useVKComIsMobileLogic){let{appVersion:s}=window.navigator;t=Ht.test(s)}else this.params.mobile&&(t=!0);return t&&(i="M_WEB"),this.params.vktvVersion&&(i="SMART_TV",o=this.params.vktvVersion),{collector:"ok.mobile.apps.video",data:JSON.stringify({application:o,platform:i,items:this.params.config.shorten?e.map(Ye):e})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();let e=Ut(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:N.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.deviceId,client_version:_.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:N.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:N.EXTERNAL_API,message:"authorize error",data:t}):this.params.error$.next({id:"AuthorizeUnknown",category:N.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 z,now as Ie}from"@vkontakte/videoplayer-shared/evergreen";var q=class{constructor(e){this.params=e,this.apiKey=e.config.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=e.config.apiBaseUrl??ve[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:z.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),ve.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}),s=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,s)}catch(d){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:z.NETWORK,message:"Unhandled beacon error",thrown:d,data:{method:e,params:i}})}return!1}async sendRequest(e,i,t){let o=Ie(),s=c=>{if(c instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(c.message)){this.params.error$.next({id:"Network",category:z.NETWORK,message:"Request failed",thrown:c});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:z.NETWORK,message:"Unhandled request error",thrown:c,data:{method:e,params:i,sessionKey:t,time:Ie()-o}})};this.apiBaseUrl=await this.resolveApiBaseUrl();let d={method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:i,sessionKey:t})};return this.params.config.useKeepalive&&(d.keepalive=!0),fetch(`${this.apiBaseUrl}/fb.do`,d).then(c=>{let h=Number(c.headers.get("content-length"))===0,r=new Date(c.headers.get("date")??"").getTime(),l=Ie()-o;if(isFinite(r)&&this.timeSynchronisation?.addServerTime(r,l),!h)return c.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,s)},s)}_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 qt,now as Qt,safeStorage as Q,debounceFn as Xe}from"@vkontakte/videoplayer-shared/evergreen";var j="onestat_events",ye=n=>e=>e.timestamp+n>=Qt(),G=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=Xe(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let i=Q.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=Xe(()=>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:qt.WTF,message:e?String(e):"Unknown logger error",thrown:e})}}readFromStorage(){let e=Q.get(j);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(ye(this.params.config.storageExpiration));Q.set(j,JSON.stringify({...i,[this.userSalt]:[...o,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(ye(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],Q.set(j,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[i,t]of Object.entries(e)){let o=t.filter(ye(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`})}Q.set(j,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({wantBeacon:e,clearStorage:i}={wantBeacon:!1,clearStorage:!0}){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)),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 Se,Surface as M,VideoFormat as I,VideoQuality as T}from"@vkontakte/videoplayer-core/evergreen";import{assertNever as Je}from"@vkontakte/videoplayer-shared/evergreen";var Ze=n=>n&&{[T.INVARIANT]:"unknown",[T.Q_144P]:"mobile",[T.Q_240P]:"lowest",[T.Q_360P]:"low",[T.Q_480P]:"medium",[T.Q_576P]:"unknown",[T.Q_720P]:"high",[T.Q_1080P]:"fullhd",[T.Q_1440P]:"quadhd",[T.Q_2160P]:"ultrahd",[T.Q_4320P]:"unknown"}[n],_e=n=>n&&{[Se.HTTP1]:"http1",[Se.HTTP2]:"http2",[Se.QUIC]:"http3"}[n],et=n=>{if(n!==void 0)switch(n){case I.MPEG:return"mp4";case I.DASH:case I.DASH_LIVE:case I.DASH_STREAMS:return"dash";case I.DASH_SEP:return"dash_sep";case I.DASH_ONDEMAND:return"ondemand_dash";case I.DASH_WEBM:case I.DASH_LIVE_WEBM:return"webm";case I.DASH_WEBM_AV1:return"av1";case I.DASH_LIVE_CMAF:return"ondemand_dash_live";case I.HLS:case I.HLS_LIVE:return"hls";case I.HLS_FMP4:return"hls_fmp4";case I.HLS_ONDEMAND:return"ondemand_hls";case I.HLS_LIVE_CMAF:return"ondemand_hls_live";case I.WEB_RTC_LIVE:return"webrtc";default:return Je(n)}},Pe=(n,e)=>{if(e)return"minimal";switch(n){case void 0:case M.NONE:case M.INLINE:return;case M.FULLSCREEN:return"fullscreen";case M.SECOND_SCREEN:return"chromecast";case M.PIP:return"pip";case M.INVISIBLE:return"invisible";default:return Je(n)}},tt=n=>{switch(n){case"slow-2g":return"poor";case"2g":return"poor";case"3g":return"good";case"4g":return"excellent"}};var Y=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 it=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");import{PlaybackState as ot}from"@vkontakte/videoplayer-core/evergreen";import{filter as rt,filterChanged as Wt,fromEvent as Kt,isNullable as st,map as zt,merge as Te,Observable as jt,Subject as Ee,Subscription as Gt,ValueSubject as Yt}from"@vkontakte/videoplayer-shared/evergreen";var nt=(n,e)=>new jt(i=>{let t=new Gt,o=Te(Kt(window,"beforeunload"),n.events.willDestruct$),s=new Yt(void 0),d;t.add(n.info.isLive$.pipe(Wt()).subscribe(g=>{d&&(d.unsubscribe(),s.next(void 0)),g?d=n.info.liveTime$.pipe(zt(w=>w&&w/1e3)).subscribe(s):d=n.info.position$.subscribe(s),t.add(d)}));let{playing$:c,paused$:h}=n.events,r=n.events.willSeek$.pipe(rt(()=>n.info.playbackState$.getValue()===ot.PLAYING)),l=n.events.seeked$.pipe(rt(()=>n.info.playbackState$.getValue()===ot.PLAYING)),u=!1,a=new Ee;t.add(r.subscribe(()=>{u||a.next(),u=!0})),t.add(l.subscribe(()=>u=!1));let p=new Ee,f=new Ee,v=Te(c,l,p),m=Te(h,a,o,n.events.looped$,f),y,C=()=>y=s.getValue(),P=()=>{let g=s.getValue();st(y)||y===g||st(g)||(i.next({from:y,to:g}),y=void 0)},S=()=>{f.next(),p.next()};if(t.add(v.subscribe(C)),t.add(m.subscribe(P)),e.forceInterval&&isFinite(e.forceInterval))if(e.watchCoverageTimeoutFix){let g,w=()=>{g!==void 0&&(window.clearTimeout(g),g=void 0)};t.add(v.subscribe(()=>{w(),g=window.setTimeout(S,e.forceInterval)})),t.add(m.subscribe(()=>w())),t.add(()=>w())}else{let g=0;t.add(v.subscribe(()=>g=window.setTimeout(S,e.forceInterval))),t.add(m.subscribe(()=>window.clearTimeout(g)))}return t});import{Surface as x}from"@vkontakte/videoplayer-core/evergreen";import{debounce as Xt,filterChanged as Jt,Subject as Zt}from"@vkontakte/videoplayer-shared/evergreen";var X=(n,e,i)=>{let t=new Zt,o=t.pipe(Xt(0),Jt()),s=!1,d=!1,c=!1;return e(n.inPiP$,h=>{s=h,t.next(h?x.PIP:d?x.FULLSCREEN:c?x.INLINE:void 0)}),e(n.inFullscreen$,h=>{d=h,t.next(h?x.FULLSCREEN:s?x.PIP:c?x.INLINE:void 0)}),i&&e(i.info.surface$,h=>{switch(h){case x.SECOND_SCREEN:case x.NONE:case x.INLINE:{!d&&!s&&(h===x.INLINE&&(c=!0),t.next(h));break}}}),{surface$:o}};var ai="_one-stat_",ut=`${ai}deviceId`,Ae=()=>{let n=new we;return{subscription:n,subscribe:(e,i)=>{e&&n.add(e.subscribe(i))}}},xe=class{constructor(e,i){this.subscription=new we;this.debugLogger=new si;this.oneStatDebugLog=this.debugLogger.createComponentLog("onestat");this.loopCounter=0;this.disabled=!1;this.isid$=new J(void 0);this.zenUid$=new J(void 0);this.seekAction$=new J("unknown");this.statContext=e,this.config=Ge(i.config??{}),V(i.apiEnv)&&(this.config.apiEnv=i.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new Y);let t=new ri;this.experimental={error$:t};let o=lt.get(ut);this.statContext.deviceId?this.deviceId=this.statContext.deviceId:o?this.deviceId=o:(this.deviceId=be(),lt.set(ut,this.deviceId)),this.resetViewSession(),i.useIsid&&this.isid$.next(i.isid??it()),this.zenUid$.next(i.zenUid);let s=new q({config:this.config,error$:t,timeSynchronisation:this.timeSynchronisation});this.api=new H({config:this.config,apiTransport:s,refreshAuthToken:i.refreshAuthToken,mobile:this.statContext.mobile??!1,deviceId:this.deviceId,error$:t,vktvVersion:i.vktvVersion}),this.logger=new G({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:t,userSalt:i.userSalt});let{isEmbed:d,topOrigin:c}=ni();this.isEmbed=d,this.embedParent=c?new URL(c).hostname:void 0,this.subscribe()}get vsid$(){return new J(R.getVSID())}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let i=new we,t=(a,p)=>i.add(a.subscribe(p));t(e.events.willStart$,()=>{let a=e.info.position$.getValue();this.logActionPlay({position:a}),this.statContext.projectId&&this.logActionPlayInteractive()}),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(e.events.playing$,()=>{this.logPlaying()}),t(nt(e,{forceInterval:this.config.watchCoverageInterval,watchCoverageTimeoutFix:this.config.watchCoverageTimeoutFix}),a=>{let p=e.info.isLive$.getValue(),f=e.info.atLiveEdge$.getValue(),v={start:parseFloat(a.from.toFixed(3)),end:parseFloat(a.to.toFixed(3))};if(f){let m=e.info.liveLatency$.getValue()??0,y=e.info.currentBuffer$.getValue()?.end??0,C=e.info.liveBufferTime$.getValue()??0,P=Math.round((m-(y-C))*1e3),S=Math.round(m*1e3);P&&S&&(v.latency=P,v.bufferLatency=S)}p?this.logWatchCoverageLive(v):this.logWatchCoverageRecord(v)});let o;t(e.info.isStalled$,a=>{a?o=$():(V(o)&&this.logEmptyBuffer({duration:$()-o}),o=void 0)});let s=!1;i.add(e.events.fatalError$.pipe(oi()).subscribe(()=>s=!0)),t(e.events.willStop$,()=>{if(e.info.isStalled$.getValue()){let p=V(o)?$()-o:void 0;this.logCloseAtEmptyBuffer({duration:p??0}),o=void 0}else s||this.logActionStop()}),t(e.events.managedError$,({id:a})=>{this.logError({fatal:!1,errorType:a})}),t(e.events.fatalError$,({id:a})=>{this.logError({fatal:!0,errorType:a})});let d,c,h=!1;t(e.events.firstBytes$,a=>{d=$(),this.logFirstBytes({time:a})}),t(e.events.willStart$,()=>c=$()),t(e.info.currentBuffer$,a=>{!h&&a&&a.end-a.start>0&&V(d)&&(this.logPlayerReady({duration:$()-d}),h=!0)}),t(e.events.firstFrame$,()=>{V(d)&&!h&&(this.logPlayerReady({duration:$()-d}),h=!0),V(c)&&this.logFirstFrame({time:$()-c})});let r;t(e.info.currentVideoStream$,a=>{a&&(r&&a.id!==r&&this.logTrackSwitch(a),r=a.id)});let l;t(e.info.currentAudioStream$,a=>{a&&(l&&a.id!==l&&this.logTrackSwitch(a),l=a.id)}),t(e.info.atLiveEdge$,a=>this.updateContext({liveEdge:a})),t(at({muted:e.info.muted$,volume:e.info.volume$}),({muted:a,volume:p})=>this.updateContext({audible:!a&&p>0})),t(e.info.currentQuality$,a=>{let p=Ze(a);this.updateContext({quality:p}),p&&this.logQuality(p)}),t(e.info.isAutoQualityEnabled$,a=>this.updateContext({autoQuality:a})),t(e.info.currentFormat$,a=>this.updateContext({contentType:et(a)})),t(e.info.currentPlaybackRate$,a=>this.updateContext({rate:a})),t(e.info.is3DVideo$,a=>this.updateContext({is3d:a}));let u;return t(e.info.hostname$,a=>{let p=u!==void 0&&u!==a;this.updateContext({cdnHostname:a,failover:p}),p&&this.logFailover(a),u=a}),t(e.info.throughputEstimation$,a=>this.updateContext({downloadSpeed:a})),t(e.info.httpConnectionType$,a=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:_e(a)}),this.updateContext({connectionType:_e(a)})}),t(e.info.httpConnectionReused$,a=>{ct(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:a}),this.updateContext({connectionReused:a})}),t(e.info.surface$,a=>{this.uiEvents||this.updateContext({mode:Pe(a,this.statContext.isPreviewPlayerView)})}),t(at({current:e.info.currentTextTrack$,available:e.info.availableTextTracks$}),({current:a,available:p})=>{let f=p.find(({id:m})=>m===a),v=f&&(f.isAuto?`${f.language}_auto`:f.language);this.updateContext({subtitles:v?.split(".")[0]})}),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}=Ae();if(!this.player)return i;t(e.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),t(e.actionSeek$,this.seekAction$);let{surface$:o}=X(this.uiEvents,t,this.player);return t(o,s=>{this.updateContext({mode:Pe(s,this.statContext.isPreviewPlayerView)})}),t(e.actionSetSubtitle$,s=>this.updateContext({subtitles:s?.split(".")[0]})),t(e.nextMovie$,s=>this.logNextMovie(s)),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToAds(e){let{subscription:i,subscribe:t}=Ae();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()),t(e.error$,o=>this.logError({errorType:o,fatal:!1})),this.resubscribeBeforeunload(),this.subscription.add(i),i}attachToInteractive(e){let{subscription:i,subscribe:t}=Ae();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"}),R.generateVSID()}getDeviceId(){return this.deviceId}setFieldBlacklist(){}logInited(){}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(...e){this.logActionPlay(...e)}logPlay(){this.log({operation:"play_toggle"})}logPlaying(){this.log({operation:"playing"})}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}`},{in_history:this.statContext.inHistory?1:void 0})}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}`},{in_history:this.statContext.inHistory?1:void 0,latency:e.latency,buffer_latency:e.bufferLatency})}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(ti(dt(e,"change"),ii(["init"])).subscribe(()=>this.updateContext({network:tt(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=dt(window,"beforeunload").subscribe(()=>this.logger.flush({wantBeacon:!0,clearStorage:this.config.clearStorageAtUnload})),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(){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(this.statContext.movieId)},{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"})}logTrackSwitch(e){this.log({operation:"track_switch",param:e.id})}logQuality(e){this.log({operation:"quality",param:e})}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 s=this.timeSynchronisation?.now()??$(),d=this.vsid$.getValue();ei(d);let c=this.isid$.getValue(),h=e==="empty_buffer"||e==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,r=this.statContext.firstConnectionReused,l,u;if(this.isEmbed||this.statContext.place==="embed"){l=this.embedParent;let p=[...new URLSearchParams(location.search).entries()].filter(([f,v])=>this.config.embedUrlParams.includes(f));u=new URLSearchParams(p).toString()}else if(this.statContext.place==="direct"){let p=this.statContext.refDomain||document.referrer;p&&URL.canParse(p)?l=new URL(p).hostname:l=p,u=location.href.substring(0,1024)}let a={vsid:d,isid:c,vid:this.statContext.movieId,uid:this.zenUid$.getValue(),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:h,connection_reused:r===!0?1:r===!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:l,direct_url:u,rate:this.statContext.rate===1||ct(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 p of this.config.disabledCustomFields)delete a[p];return{operation:e,type:1,time:t,network:this.statContext.network,timestamp:s,custom:a}}};var Ct={};Mt(Ct,{ActionSeekType:()=>Z,ThinOneStat:()=>le,VERSION:()=>_});import{assertNonNullable as _i,detectEmbed as Pi,fromEvent as Ti,Logger as Ei,merge as Ve,combine as ce,filter as B,filterChanged as Ai,safeStorage as wt,Subject as wi,Subscription as Fe,ValueSubject as Oe}from"@vkontakte/videoplayer-shared/evergreen";import{clientChecker as k}from"@vkontakte/videoplayer-core/evergreen";import{fillWithDefault as di}from"@vkontakte/videoplayer-shared/evergreen";var ke=(t=>(t.AUTO="auto",t.AUTO_POOR="auto_poor",t.AUTO_RICH="auto_rich",t))(ke||{});var Z=(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))(Z||{});var pt="CIOPGQJGDIHBABABA",Ce={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",okcdn:"https://api.okcdn.ru",auto:""};var ci={apiKey:pt,apiEnv:"okcdn",apiBaseUrl:null,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageHeartbeatInterval:30,synchronizeTime:!0,useBeacon:!1,alwaysSendDesktop:!1,watchedNFirstTvtLog:1e3,watchedNDefaultTargetDuration:1e4},ft=n=>di(n,ci);import{getExponentialDelay as li,ErrorCategory as O,ValueSubject as ui}from"@vkontakte/videoplayer-shared/evergreen";var ee=class{constructor(e){this.params=e,this.authorized$=new ui(!1),this.consequentAuthErrors=0}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this.authorizeWithBackoff()}logBeacon(e){let i="log.logUvStat",t=this.createLogParams(e),o=this.sessionKey;if(!o)return;this.params.apiTransport.sendBeacon(i,t,o)||this.logRequest(e).catch(()=>{})}async logRequest(e){let i="log.logUvStat",t=this.createLogParams(e),o={},s=this.sessionKey??await this.authorizeWithBackoff();if(!s)return;let d=async(c,h=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(i,t,s,o)}catch(r){if(!r||!("error_code"in r)){this.params.error$.next({id:"logRequestUnknown",category:O.NETWORK,message:`Unknown ${i} error`,thrown:r});return}let l=r?.error_code;switch(l){case 102:case 103:case 104:return this.authorized$.next(!1),this.sessionKey=await this.authorizeWithBackoff(),h>0?d(c,h-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this.authorizeWithBackoff(),h>0?d(c,h-1):void 0;default:{this.params.error$.next({id:`LogRequest#${l}`,category:O.EXTERNAL_API,message:`${i} error`,data:r});return}}}};return d(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",uv_stat_data:JSON.stringify({application:`@vkontakte/videoplayer-statistics:${_}`,platform:e[0].platform,product:e[0].product,events:e})}}authorizeWithBackoff(){if(!this.consequentAuthErrors)return this.doAuthorize();let e=li(this.consequentAuthErrors);return new Promise(i=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(async()=>{try{let t=await this.doAuthorize();i(t)}catch(t){this.params.error$.next({id:"AuthorizeBackoff",category:O.NETWORK,message:"Otherwise unhandled error in authorization",thrown:t})}finally{this.backoffTimeoutId=0}},e))})}doAuthorize(){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.deviceId,client_version:_.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:O.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:O.EXTERNAL_API,message:"authorize error",data:t}):this.params.error$.next({id:"AuthorizeUnknown",category:O.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{now as Le,ErrorCategory as te}from"@vkontakte/videoplayer-shared/evergreen";var ie=class{constructor(e){this.params=e,this.apiKey=e.config.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=e.config.apiBaseUrl??Ce[this.apiEnv],this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}sendBeacon(e,i,t){if(!window.Blob||!window.navigator.sendBeacon)return!1;let o=this.prepareQueryParams({method:e,queryParams:i,sessionKey:t}),s=new window.Blob([o.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,s)}catch(d){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:te.NETWORK,message:"Unhandled beacon error",thrown:d,data:{method:e,params:i}})}return!1}async sendRequest(e,i,t,o){let s=Le(),d=c=>{if(c instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(c.message)){this.params.error$.next({id:"Network",category:te.NETWORK,message:"Request failed",thrown:c});return}this.params.error$.next({id:"ThinOneStat:ApiTransport:sendRequest",category:te.NETWORK,message:"Unhandled request error",thrown:c,data:{method:e,params:i,sessionKey:t,time:Le()-s}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),fetch(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded",...o},body:this.prepareQueryParams({method:e,queryParams:i,sessionKey:t})}).then(c=>{let h=Number(c.headers.get("content-length"))===0,r=new Date(c.headers.get("date")??"").getTime(),l=Le()-s;if(isFinite(r)&&this.timeSynchronisation?.addServerTime(r,l),!h)return c.json().then(u=>Object.prototype.hasOwnProperty.call(u,"error_msg")?Promise.reject(u):u,d)},d)}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:"ThinOneStat:ApiTransport:resolveApiBaseUrl",category:te.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),Ce.vk_alias}finally{this.isApiBaseUrlFetched=!0}}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 hi,now as pi,safeStorage as W,debounceFn as gt}from"@vkontakte/videoplayer-shared/evergreen";var oe="thinonestat_events",$e=n=>e=>e.client_time+n>=pi(),re=class{constructor(e){this.unsaltedStorage=[];this.isPaused=!1;this.isUrgent=e=>{let{event_name:i}=e;return["watch_coverage","watch_coverage_live","watched_n","playback_started"].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=gt(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let i=W.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=gt(()=>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:hi.WTF,message:String(e)||"Unknown logger error",thrown:e})}}readFromStorage(){let e=W.get(oe);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($e(this.params.config.storageExpiration));W.set(oe,JSON.stringify({...i,[this.userSalt]:[...o,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter($e(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],W.set(oe,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[i,t]of Object.entries(e)){let o=t.filter($e(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`})}W.set(oe,JSON.stringify(e))}log(e){this.addToStorage(e),!this.isPaused&&(this.isUrgent(e)?this.flush():this.lastVsid!==e.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=e.vsid)}flush({wantBeacon:e,clearStorage:i}={wantBeacon:!1,clearStorage:!0}){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)),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()}};function Re(){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("")}var se=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)}};import{PlaybackState as mt}from"@vkontakte/videoplayer-core/evergreen";import{Observable as fi,Subscription as gi,ValueSubject as mi,Subject as De,fromEvent as vi,isNullable as vt,merge as K,filter as bt,filterChanged as It}from"@vkontakte/videoplayer-shared/evergreen";var yt=(n,e,i)=>new fi(t=>{let o=new gi,s=new mi(void 0),d;o.add(n.info.isLive$.pipe(It()).subscribe(L=>{d&&(d.unsubscribe(),s.next(void 0)),L?d=n.info.liveTime$.pipe(It()).subscribe(s):d=n.info.position$.subscribe(s),o.add(d)}));let{playing$:c,paused$:h,ended$:r,looped$:l}=n.events,u=n.events.willSeek$.pipe(bt(()=>n.info.playbackState$.getValue()===mt.PLAYING)),a=n.events.seeked$.pipe(bt(()=>n.info.playbackState$.getValue()===mt.PLAYING)),p=!1,f=new De;o.add(u.subscribe(()=>{p||f.next(),p=!0})).add(a.subscribe(()=>p=!1));let v=K(vi(window,"beforeunload"),n.events.willDestruct$),m,y=()=>m=s.getValue(),C=()=>{let L=s.getValue();vt(m)||vt(L)||m===L||(t.next({from:m,to:L}),m=void 0)},P=new De,S=new De,g=K(c,f,P),w=K(h,a,v,r,l,S),Ue=e.started$&&e.ended$?K(g,e.ended$):g,He=e.started$&&e.ended$?K(w,e.started$):w;if(o.add(Ue.subscribe(y)).add(He.subscribe(C)),i.heartbeatInterval&&isFinite(i.heartbeatInterval)){let L=[],Rt=i.heartbeatInterval*1e3,Dt=()=>{S.next(),P.next()};o.add(Ue.subscribe(()=>{let he=window.setTimeout(Dt,Rt);L.push(he)})).add(He.subscribe(()=>{L.forEach(he=>{window.clearTimeout(he)}),L=[]}))}return o});import{Subscription as bi}from"@vkontakte/videoplayer-core/evergreen";import{Observable as Ii}from"@vkontakte/videoplayer-shared/evergreen";var St=(n,e)=>new Ii(i=>{let t=new bi,o=0;return t.add(n.info.position$.subscribe(()=>{let s=e.getTotalViewTime()*1e3;s>o&&(s===e.firstTvtLog||s%e.targetDuration===0)&&(o=s,i.next({target_duration:e.targetDuration,current_tvt:s}))})),t});import{Observable as yi,Subscription as Si,merge as _t}from"@vkontakte/videoplayer-shared/evergreen";var Pt=n=>new yi(e=>{let i=new Si,t=0,o=1,s=0,d=!1,c=!1,h=()=>{if(!d)return;let g=Date.now();s+=(g-t)*o,t=g},r=()=>{(!d||c)&&(t=Date.now(),d=!0,c=!1)},l=()=>{d&&(h(),d=!1)},u=()=>{d&&(h(),d=!1,c=!0)},a=g=>{d&&h(),o=g,t=Date.now()},{started$:p,playing$:f,paused$:v,willSeek$:m,ended$:y,willDestruct$:C}=n.events,{currentPlaybackRate$:P}=n.info;i.add(m.subscribe(u)).add(_t(p,f).subscribe(r)).add(_t(v,y,C).subscribe(l)).add(P.subscribe(a));let S=()=>{let g=s;return d&&(g+=(Date.now()-t)*o),g};return e.next(S),i});import{assertNever as Tt}from"@vkontakte/videoplayer-shared/evergreen";import{HttpConnectionType as Ne,Surface as F,VideoFormat as b,VideoQuality as E}from"@vkontakte/videoplayer-core/evergreen";var Me=n=>n&&{[Ne.HTTP1]:"http1",[Ne.HTTP2]:"http2",[Ne.QUIC]:"http3"}[n],ne=n=>{if(n!==void 0)switch(n){case b.MPEG:return"MP4";case b.DASH:case b.DASH_LIVE:return"DASH";case b.DASH_SEP:return"DASH_SEP";case b.DASH_ONDEMAND:return"ONDEMAND_DASH";case b.HLS_ONDEMAND:return"ONDEMAND_HLS";case b.HLS:case b.HLS_LIVE:return"HLS";case b.HLS_FMP4:return"HLS_FMP4";case b.DASH_WEBM:case b.DASH_LIVE_WEBM:return"WEBM";case b.DASH_LIVE_CMAF:return"ONDEMAND_DASH_LIVE";case b.HLS_LIVE_CMAF:return"ONDEMAND_HLS_LIVE";case b.WEB_RTC_LIVE:return"WEBRTC";case b.DASH_WEBM_AV1:return"AV1";case b.DASH_STREAMS:return"MULTI_DASH";default:return Tt(n)}},A=n=>{if(n!==void 0)switch(n){case E.Q_144P:return"144p";case E.Q_240P:return"240p";case E.Q_360P:return"360p";case E.Q_480P:return"480p";case E.Q_720P:return"720p";case E.Q_1080P:return"1080p";case E.Q_1440P:return"1440p";case E.Q_2160P:return"2160p";case E.INVARIANT:case E.Q_576P:case E.Q_4320P:return"UNKNOWN";default:return Tt(n)}},Et=n=>{if(n!==void 0)switch(n){case"MP4":case"ONDEMAND_DASH":case"ONDEMAND_DASH_LIVE":case"ONDEMAND_HLS":case"ONDEMAND_HLS_LIVE":case"MULTI_DASH":case"WEBM":case"AV1":return"vod";case"DASH":case"HLS":case"HLS_FMP4":case"WEBRTC":return"live";default:return}},D=(n,e,i)=>{if(n&&e)switch(n){case b.MPEG:return i&&e[n]&&e[n][i];default:return e[n]?.url}},ae=(n,e=!1)=>{if(e)return"minimal";switch(n){case void 0:case F.NONE:return;case F.INLINE:return"inline";case F.FULLSCREEN:return"fullscreen";case F.SECOND_SCREEN:return"chromecast";case F.PIP:return"pip_external"}},de=n=>{switch(n){case void 0:return;case F.INVISIBLE:return"background";default:return"foreground"}};var At=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");var xi="_thin-one-stat_",xt=`${xi}deviceId`,kt=()=>{let n=new Fe;return{subscription:n,subscribe:(e,i)=>{e&&n.add(e.subscribe(i))}}},le=class{constructor(e,i){this.debugLogger=new Ei;this.thinOneStatDebugLog=this.debugLogger.createComponentLog("ThinOneStat");this.eventNumber=1;this.playerSize={width:0,height:0};this.seekAction$=new Oe("unknown");this.isid$=new Oe(void 0);this.statContext=e,this.config=ft(i.config??{}),this.subscription=new Fe,this.config.synchronizeTime&&(this.timeSynchronisation=new se);let t=new wi,o=wt.get(xt);this.statContext.deviceId?this.deviceId=this.statContext.deviceId:o?this.deviceId=o:(this.deviceId=Re(),wt.set(xt,this.deviceId)),this.statContext.targetDuration?this.targetDuration=this.statContext.targetDuration:this.targetDuration=this.config.watchedNDefaultTargetDuration,this.resetViewSession(),i.useIsid&&this.isid$.next(i.isid??At());let s=new ie({error$:t,config:this.config,timeSynchronisation:this.timeSynchronisation});this.api=new ee({config:this.config,apiTransport:s,error$:t,deviceId:this.deviceId,refreshAuthToken:i.refreshAuthToken}),this.logger=new re({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:t,userSalt:i.userSalt});let{isEmbed:d,topOrigin:c}=Pi();this.isEmbed=d,this.embedHostname=c?new URL(c).hostname:void 0}get vsid$(){return new Oe(R.getVSID())}authorize(e){return this.api.authorize(e)}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e,i){let t=new Fe,o=(r,l)=>t.add(r.subscribe(l));o(Pt(e),r=>{this.getTotalViewTime=r}),o(e.info.isLive$,r=>this.isLive=r);let s;o(ce({hostname:e.info.hostname$,connectionType:e.info.httpConnectionType$,connectionReused:e.info.httpConnectionReused$}).pipe(B(({hostname:r})=>r!==void 0),B(({connectionType:r})=>r!==void 0),B(({connectionReused:r})=>r!==void 0)),({hostname:r,connectionType:l,connectionReused:u})=>{if(s!==void 0&&s!==r){let p={cdn_host:r,connection_type:Me(l),connection_reused:u,content_type:ne(e.info.currentFormat$.getValue())};this.logFailover(p)}this.cdnHostname=s=r}),o(e.info.httpConnectionType$,r=>{this.connectionType=Me(r)}),o(e.info.httpConnectionReused$,r=>{this.connectionReused=r}),o(yt(e,i,{heartbeatInterval:this.config.watchCoverageHeartbeatInterval}),r=>{let l=Math.round(r.from*1e3),u=Math.round(r.to*1e3),a={watch_interval:`${l}-${u}`,in_history:!!this.statContext.inHistory,content_type:ne(e.info.currentFormat$.getValue()),playback_quality:A(e.info.currentQuality$.getValue()),recom_info:this.statContext.recomInfo};if(!e.info.isLive$.getValue())this.logWatchCoverage(a);else{let f=e.info.atLiveEdge$.getValue();this.logWatchCoverageLive({...a,live:!!f})}}),o(St(e,{targetDuration:this.targetDuration,firstTvtLog:this.config.watchedNFirstTvtLog,getTotalViewTime:this.getTotalViewTime}),r=>{this.logWatchedN(r)}),o(e.events.willReady$,()=>{if(this.statContext.preload){let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentBuffer$.getValue(),a=e.info.currentQuality$.getValue(),p={target_buffer_time:this.calcBufferTime(u),playback_url:D(r,l,a),playback_quality:A(a)};this.logPreloadStarted(p)}}),o(e.events.ready$,()=>{let r=e.info.currentBuffer$.getValue();if(this.statContext.preload){let l={buffer_time:this.calcBufferTime(r)};this.logPreloadEnded(l)}this.logReady({buffer_time:this.calcBufferTime(r)})}),o(e.events.manifestRequested$,()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logManifestRequest(a)}),o(e.events.firstBytesManifest$,()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstByteManifest(a)}),o(e.events.manifestReceived$,()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logManifestReceived(a)}),o(e.events.firstBytesRequested$,()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstMediaRequest(a)}),o(e.events.firstBytesReceived$,()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstByteMedia(a)}),o(Ve(e.events.willStart$,e.events.looped$),r=>{r&&this.resetViewSession();let u={isid:this.isid$.getValue(),stream_profile:Et(ne(e.info.currentFormat$.getValue())),dpi:96*k.display.pixelRatio,web_layout:this.statContext.isMobile||k.device.isMobile?"mobile":"desktop",preloaded:this.statContext.preload,navigation:this.statContext.navigation,recom_info:this.statContext.recomInfo};this.isEmbed&&(u.iframe_host=this.embedHostname??"unknown"),this.logStartSession(u)}),o(e.events.started$,()=>{this.isStarted=!0;let r=e.info.currentBuffer$.getValue(),l=e.info.currentQuality$.getValue(),u=e.info.isAutoQualityEnabled$.getValue(),a=e.info.muted$.getValue(),p=e.info.volume$.getValue(),f=e.info.surface$.getValue(),v=e.info.availableTextTracks$.getValue(),m=e.info.currentTextTrack$.getValue(),y=e.info.currentAudioStream$.getValue(),C=e.info.currentPlaybackRate$.getValue(),P={playback_quality:A(l),user_quality:u?"auto":A(l),player_width:this.playerSize.width,player_height:this.playerSize.height,muted:a,sound_volume:Math.round(p*100),buffer_time:this.calcBufferTime(r),mode:ae(f,this.statContext.isPreviewPlayerView),visibility:de(f),subtitles_enabled:m?!!m:this.currentSubtitle?.enabled,auto_subtitles:v.find(({id:S})=>S===m)?.isAuto??this.currentSubtitle?.auto,audio_track_lang:y?.language,playback_rate:C,recom_info:this.statContext.recomInfo};this.logPlaybackStarted(P)}),o(Ve(e.events.willStart$,e.events.willResume$),()=>{this.logPlay()}),o(e.events.playing$,()=>{let r=e.info.currentBuffer$.getValue(),l={buffer_time:this.calcBufferTime(r)};this.logPlaying(l),this.wasPaused&&this.logResume()}),o(e.events.paused$,()=>{this.wasPaused=!0,this.logPause()}),o(e.events.willStop$,()=>{this.logStop()}),o(Ve(e.events.fetcherRecoverableError$,e.events.fatalError$),()=>{this.statContext.preload&&this.logPreloadError()}),o(ce({connectionType:e.info.httpConnectionType$,connectionReused:e.info.httpConnectionReused$}).pipe(B(({connectionReused:r})=>r!==void 0),Ai((r,l)=>r.connectionType===l.connectionType)),()=>{let r=e.info.currentFormat$.getValue(),l=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),a=e.info.rttEstimation$.getValue(),p={playback_url:D(r,l,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused,rtt:a?Math.round(a):void 0};this.logConnectionEstablished(p)}),o(e.events.firstFrame$,()=>{this.logFirstVideoFrameDecoded()}),o(e.events.willSeek$,()=>{let r={seek_type:this.seekAction$.getValue()};this.logSeeking(r)}),o(e.events.seeked$,()=>{let r={seek_type:this.seekAction$.getValue()};this.logSeeked(r),this.seekAction$.next("unknown")}),o(e.info.isStalled$,r=>{let l=e.info.currentBuffer$.getValue(),u=this.calcBufferTime(l);r&&u&&u>0&&this.logBufferStarvation({buffer_time:u})});let d;o(ce({videoStream:e.info.currentVideoStream$,audioStream:e.info.currentAudioStream$,quality:e.info.currentQuality$}).pipe(B(({videoStream:r,audioStream:l})=>r!==void 0&&l!==void 0),B(({quality:r})=>r!==void 0)),({videoStream:r,audioStream:l,quality:u})=>{if(d!==u){let a=e.info.isAutoQualityEnabled$.getValue(),p=r?.codec,f=l?.codec,v={user_quality:a?"auto":A(u),playback_quality:A(u),download_quality:A(u),codec_info:p&&f?`${p},${f}`:void 0};d=u,this.logQualityChanged(v)}});let c,h;return o(e.info.surface$,r=>{let l=ae(r,this.statContext.isPreviewPlayerView);l&&!this.uiEvents&&this.isStarted&&this.logModeChanged({mode:l}),h=de(r),c!==h&&this.isStarted&&(c=de(r),this.logVisibilityChanged({visibility:h}))}),o(ce({muted:e.info.muted$,volume:e.info.volume$}),({muted:r,volume:l})=>{if(this.isStarted){let u={muted:r,sound_volume:Math.round(l*100)};this.logSoundChanged(u)}}),this.player=e,this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToUi(e){this.uiEvents=e;let{subscribe:i,subscription:t}=kt();i(e.actionSeek$,this.seekAction$),i(e.playerSize$,({width:s,height:d})=>{s&&d&&(this.playerSize={width:s,height:d},this.logViewPortChanged({player_width:s,player_height:d}))}),i(e.isLoaderVisible$,s=>{s&&this.isStarted&&this.logShowLoader()}),i(e.actionSubtitlesSwitched$,s=>{if(this.currentSubtitle={...s},this.isStarted){let d={subtitles_enabled:s.enabled,subtitles_track_lang:s.lang,auto_subtitles:s.auto};this.logSubtitlesSwitched(d)}});let{surface$:o}=X(this.uiEvents,i,this.player);return i(o,s=>{this.isStarted&&this.logModeChanged({mode:ae(s)})}),i(e.actionQuality$,s=>{let d=l=>Object.values(ke).includes(l),c=this.player?.info.currentVideoStream$.getValue()?.codec,h=this.player?.info.currentAudioStream$.getValue()?.codec,r={user_quality:d(s)?"auto":A(s),playback_quality:A(this.player?.info.currentQuality$.getValue()),download_quality:A(this.player?.info.currentQuality$.getValue()),codec_info:c&&h?`${c},${h}`:void 0};this.logQualityChangeRequested(r)}),this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToAds(e){let{subscription:i,subscribe:t}=kt();return t(e.init$,o=>{let s={slot:o};this.logAdvConfiguration(s)}),t(e.slotRequested$,()=>{this.logAdvRequest()}),t(e.started$,o=>{let s={adv_section:o};this.logAdvBreakStarted(s)}),t(e.ended$,o=>{let s={adv_section:o};this.logAdvBreakEnded(s)}),t(e.error$,o=>{let s={error_message:o};this.logAdvError(s)}),this.resubscribeBeforeunload(),this.subscription.add(i),i}getDeviceId(){return this.deviceId}resetViewSession(){this.thinOneStatDebugLog({message:"VSID reset"}),R.generateVSID(),this.eventNumber=0}destroy(){this.api.destroy()}calcBufferTime(e){return e?Math.round((e.end??0)-(e.start??0))*1e3:void 0}createRequiredParams(e){let i=this.vsid$.getValue();_i(i);let t=this.eventNumber++,o=((this.isLive?this.player?.info.liveTime$.getValue():this.player?.info.position$.getValue())??0)*1e3;return{vsid:i,uv_movie_id:this.statContext.movieId,event_name:e,client_time:Date.now(),application:this.statContext.application??`@vkontakte/videoplayer-statistics:${_}`,platform:this.statContext.platform??`web:${this.statContext.isMobile||k.device.isMobile?"mobile":"desktop"}`,product:this.statContext.product,event_number:t,playback_position:o,current_tvt:this.getTotalViewTime(),cdn_host:this.cdnHostname}}createRequiredFatParams(){return{stats_version:"2.1.1",browser:this.statContext.browser??k.browser.current,browser_version:this.statContext.browserVersion??String(k.browser.currentVersion),os:this.statContext.os??k.device.os.name,os_version:this.statContext.osVersion??k.device.os.version,device_type:this.statContext.deviceType??(this.statContext.isMobile||k.device.isMobile?"mobile":"desktop"),device_manufacturer:this.statContext.deviceManufacturer??k.device.details.vendor,device_model:this.statContext.deviceModel??k.device.details.model,navigation:this.statContext.navigation}}log(e,i,t=!1){let o=this.createRequiredParams(e),s={};t&&(s=this.createRequiredFatParams()),this.logger.log({...o,...s,...i})}logWatchCoverage(e){this.log("watch_coverage",e,!0)}logWatchCoverageLive(e){this.log("watch_coverage_live",e,!0)}logWatchedN(e){this.log("watched_n",e,!0)}logStartSession(e){this.log("start_session",e,!0)}logPreloadStarted(e){this.log("preload_started",e)}logPreloadEnded(e){this.log("preload_ended",e)}logPreloadError(){this.log("preload_error")}logPlaybackStarted(e){this.log("playback_started",e,!0)}logPlay(){this.log("play")}logManifestRequest(e){this.log("manifest_request",e)}logFirstByteManifest(e){this.log("first_byte_manifest",e)}logFirstMediaRequest(e){this.log("first_media_request",e)}logFirstByteMedia(e){this.log("first_byte_media",e)}logManifestReceived(e){this.log("manifest_received",e)}logConnectionEstablished(e){this.log("connection_established",e)}logFirstVideoFrameDecoded(){this.log("first_video_frame_decoded")}logReady(e){this.log("ready",e)}logPlaying(e){this.log("playing",e)}logPause(){this.log("pause")}logResume(){this.log("resume")}logSeeking(e){this.log("seeking",e)}logSeeked(e){this.log("seeked",e)}logStop(){this.log("stop")}logBufferStarvation(e){this.log("buffer_starvation",e)}logShowLoader(){this.log("show_loader")}logQualityChangeRequested(e){this.log("quality_change_requested",e)}logQualityChanged(e){this.log("quality_changed",e)}logCdnHostChanged(e){this.log("cdn_host_changed",e)}logViewPortChanged(e){this.log("view_port_changed",e)}logModeChanged(e){this.log("mode_changed",e)}logVisibilityChanged(e){this.log("visibility_changed",e)}logSubtitlesSwitched(e){this.log("subtitles_switched",e)}logSoundChanged(e){this.log("sound_changed",e)}logFailover(e){this.log("failover",e)}logAdvConfiguration(e){this.log("adv_configuration",e)}logAdvRequest(){this.log("adv_request")}logAdvBreakStarted(e){this.log("adv_break_started",e)}logAdvBreakEnded(e){this.log("adv_break_ended",e)}logAdvError(e){this.log("adv_error",e)}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=Ti(window,"beforeunload").subscribe(()=>{}),this.subscription.add(this.beforeunloadSubscription)}};var ki={};import{PlaybackState as $t,Subscription as Ci}from"@vkontakte/videoplayer-core/evergreen";import{Logger as Li}from"@vkontakte/videoplayer-shared/evergreen";var ue=class{constructor(){this.startTime=null;this.stopTime=null;this.accumulatedTime=0}get time(){return Math.floor(this.timeMs/1e3)}get timeMs(){return this.startTime===null?0:(this.stopTime??this.now())-this.startTime-this.accumulatedTime}get isRunning(){return this.startTime!==null&&this.stopTime===null}start(){this.isRunning||(this.stopTime!==null?(this.accumulatedTime+=this.now()-this.stopTime,this.stopTime=null):this.startTime=this.now())}stop(){this.isRunning&&(this.stopTime=this.now())}reset(){this.startTime=null,this.stopTime=null,this.accumulatedTime=0}now(){return Date.now()}};var Lt=()=>window.Image?new Image:document.createElement("img");var Be=class{constructor(e){this.position=0;this.started=!1;this.heartbeatPixels=[];this.heartbeatLastTimeSent={};this.idleCallbackIds=[];this.stopwatch=new ue;this.subscription=new Ci;this.params=e;let i=new Li;this.log=i.createComponentLog("MediascopePixel")}attachTo(e){this.subscription.add(e.info.playbackState$.subscribe(i=>this.onPlaybackState(i))).add(e.info.position$.subscribe(i=>this.onPosition(i))).add(e.info.atLiveEdge$.subscribe(i=>this.isActiveLive=i)),this.subscription.add(e.events.willSeek$.subscribe(()=>this.onWillSeek())).add(e.events.seeked$.subscribe(()=>this.onSeeked())).add(e.events.ended$.subscribe(()=>this.onEnded()))}destroy(){this.stopwatch.reset(),this.subscription.unsubscribe(),window.clearTimeout(this.heartbeatFirstTimeoutId),this.idleCallbackIds.forEach(e=>window.cancelIdleCallback(e)),this.send("stop")}onPlaybackState(e){e===$t.PLAYING?this.started?this.play():this.start():e===$t.PAUSED&&this.pause()}start(){this.started=!0,this.stopwatch.start(),this.send("start"),this.heartbeatPixels=this.prepareHeartbeatPixels(),this.heartbeatInterval=this.heartbeatPixels[0]?.interval;let e=this.heartbeatPixels[0]?.url,i=this.heartbeatPixels[0]?.delay;if(i!==void 0&&e)try{this.heartbeatFirstTimeoutId=window.setTimeout(()=>{this.sendHeartbeat(e)},i*1e3)}catch(t){this.log({message:t.message})}}play(){this.stopwatch.start(),this.send("resume")}pause(){this.stopwatch.stop(),this.send("pause")}onPosition(e){if(this.position=e,this.heartbeatInterval&&this.stopwatch.time!==0&&this.stopwatch.time%this.heartbeatInterval===0)for(let[i,{url:t}]of this.heartbeatPixels.entries())this.heartbeatLastTimeSent[i]!==this.stopwatch.time&&(this.heartbeatLastTimeSent[i]=this.stopwatch.time,this.sendHeartbeat(t))}onWillSeek(){this.started&&this.send("stop")}onSeeked(){this.started&&this.send("start")}onEnded(){this.stopwatch.stop(),this.send("stop")}validatePixels(e,i){return e?.filter(t=>t.event===i.event&&i.keys.every(o=>!!t[o]))}getFrameTimestamp(){let e;if(this.isActiveLive){let i=Math.floor(Math.random()*25)+5;e=Date.now()/1e3-i}else e=this.position||0;return Math.floor(e)}getUTC(){return Math.floor(Date.now()/1e3)}prepareUrl(e){return e.replace("{@fts_fake_sec}",String(this.getFrameTimestamp())).replace("{@utc_sec}",String(this.getUTC())).split("&").filter(i=>!/={@[a-zA-Z_]+}/.test(i)).join("&")}preparePixels(e){return this.validatePixels(this.params.pixels,{event:e,keys:["url"]})}prepareHeartbeatPixels(){return this.validatePixels(this.params.pixels,{event:"heartbeat",keys:["url","interval"]})}call(e){try{this.idleCallbackIds.push(requestIdleCallback(()=>Lt().src=this.prepareUrl(e)))}catch(i){this.log({message:i.message})}}send(e){let i=this.preparePixels(e);for(let{url:t}of i)this.call(t)}sendHeartbeat(e){this.call(e)}};export{U as ApiEnv,ge as ConnectionType,fe as ContentType,qe as InteractiveInterfaceClick,Be as MediascopePixel,ki as MediascopePixelTypes,xe as OneStat,pe as Quality,me as SeekAction,Ct as ThinOneStat,_ as VERSION};
6
+ var Ft=Object.defineProperty;var Bt=(a,e)=>{for(var o in e)Ft(a,o,{get:e[o],enumerable:!0})};var H=(d=>(d.PROD="prod",d.VK_ALIAS="vk_alias",d.VIDEOTEST="videotest",d.TEST="test",d.OKCDN="okcdn",d.AUTO="auto",d))(H||{}),fe=(p=>(p.Q144P="mobile",p.Q240P="lowest",p.Q360P="low",p.Q480P="medium",p.Q720P="high",p.Q1080P="fullhd",p.Q1440P="quadhd",p.Q2160P="ultrahd",p.UNKNOWN="unknown",p))(fe||{}),ge=(u=>(u.MP4="mp4",u.DASH="dash",u.DASH_SEP="dash_sep",u.ONDEMAND_DASH="ondemand_dash",u.HLS="hls",u.HLS_FMP4="hls_fmp4",u.ONDEMAND_HLS="ondemand_hls",u.WEBM="webm",u.AV1="av1",u.ONDEMAND_DASH_LIVE="ondemand_dash_live",u.ONDEMAND_HLS_LIVE="ondemand_hls_live",u.WEBRTC="webrtc",u.UNKNOWN="unknown",u.RTMP="rtmp",u))(ge||{});var me=(t=>(t.HTTP1="http1",t.HTTP2="http2",t.HTTP3="http3",t))(me||{});var ve=(l=>(l.SLIDER="slider",l.DOUBLE_TAP="double_tap",l.TIME_CODE="time_code",l.EPISODE="episode",l.REWIND="rewind",l.LIVE="live",l.UNKNOWN="unknown",l))(ve||{}),Qe=(n=>(n.GRAPH_SHOW="iGraphShow",n.GRAPH_HIDE="iGraphHide",n.NEXT_AREA="iNextChapterArea",n.NEXT_BUTTON="iNextChapterBtn",n.WATCH_AGAIN="iWatchAgainBtn",n))(Qe||{}),Ke={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",quality:"qt"},ze={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"},je={unknown:"un",mobile:"m",lowest:"ls",low:"l",medium:"md",high:"h",fullhd:"f",quadhd:"q",ultrahd:"u"},Ge={pip:"pi",fullscreen:"fs",external:"ex",prefetch:"pr",airplay:"ap",chromecast:"cc",invisible:"iv",minimal:"minimal"};import{fillWithDefault as Ut}from"@vkontakte/videoplayer-shared/evergreen";var Ye="CIOPGQJGDIHBABABA",be={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",okcdn:"https://api.okcdn.ru",auto:""};var Ht={apiEnv:"vk_alias",apiKey:Ye,apiBaseUrl:null,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageInterval:15e3,disabledOperations:["quality"],disabledCustomFields:[],shorten:!0,maxLoops:100,embedUrlParams:[],useBeacon:!0,synchronizeTime:!0,debugLog:!1,clearStorageAtUnload:!0,useVKComIsMobileLogic:!1,backoff:{start:1e3,factor:1.5,max:5*60*1e3,random:.1},useKeepalive:!1,watchCoverageTimeoutFix:!1},Xe=a=>Ut(a,Ht);function Ie(){let a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36),o=0,t,i;for(i=0;i<36;i++)i===8||i===13||i===18||i===23?e[i]="-":i===14?e[i]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),t=o&15,o=o>>4,e[i]=a[i===19?t&3|8:t]);return e.join("")}import{assertNonNullable as ri,combine as ct,fromEvent as lt,isNonNullable as V,isNullable as ut,merge as si,now as D,observableFrom as ni,once as ai,safeStorage as ht,Subject as di,Subscription as xe,ValueSubject as ee}from"@vkontakte/videoplayer-shared/evergreen";import{Logger as ci,detectEmbed as li}from"@vkontakte/videoplayer-shared/evergreen";var qt=()=>Math.floor(Math.random()*4294967296).toString(36).padStart(13,"0"),R=class a{static getVSID(){return a.vsid}static generateVSID(){return a.vsid=qt(),a.vsid}};var Je=a=>{let{operation:e,custom:o}=a,t=Object.fromEntries(Object.entries(o).map(([i,n])=>{let d=ze[i]??i,l=n;return n&&(i==="mode"?l=Ge[n]??n:i==="quality"&&(l=je[n]??n)),[d,l]}));return{...a,operation:Ke[e]??e,custom:t}};var P="1.0.96-beta.0";import{ValueSubject as Wt,getExponentialDelay as Qt,ErrorCategory as N}from"@vkontakte/videoplayer-shared/evergreen";var Kt=/Mobile|mini|Fennec|Android|iP(ad|od|hone)|opera (mini|mobi)/i,q=class{constructor(e){this.consequentAuthErrors=0;this.authorized$=new Wt(!1);this.params=e}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this._authorizeWithBackoff()}logBeacon(e){let o="log.externalLog",t=this.createLogParams(e),i=this.sessionKey;if(!i)return;this.params.apiTransport.sendBeacon(o,t,i)||this.logRequest(e).catch(()=>{})}async logRequest(e){let o="log.externalLog",t=this.createLogParams(e),i=this.sessionKey??await this._authorizeWithBackoff();if(!i)return;let n=async(d,l=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(o,t,i)}catch(h){if(!h||!("error_code"in h)){this.params.error$.next({id:"logRequestUnknown",category:N.NETWORK,message:`Unknown ${o} error`,thrown:h});return}let p=h?.error_code;switch(p){case 102:case 103:case 104:return this.authorized$.next(!1),this.sessionKey=await this._authorizeWithBackoff(),l>0?n(d,l-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this._authorizeWithBackoff(),l>0?n(d,l-1):void 0;default:{this.params.error$.next({id:`LogRequest#${p}`,category:N.EXTERNAL_API,message:`${o} error`,data:h});return}}}};return n(e)}destroy(){window.clearTimeout(this.backoffTimeoutId),this.backoffTimeoutId=0}async refreshAuthToken(){if(this.params.refreshAuthToken)return this.refreshAuthTokenPromise||(this.refreshAuthTokenPromise=this.params.refreshAuthToken().finally(()=>{this.refreshAuthTokenPromise=void 0})),this.refreshAuthTokenPromise}createLogParams(e){let o="WEB",t=!1,i=`@vkontakte/videoplayer-statistics:${P}`;if(this.params.config.useVKComIsMobileLogic){let{appVersion:n}=window.navigator;t=Kt.test(n)}else this.params.mobile&&(t=!0);return t&&(o="M_WEB"),this.params.vktvVersion&&(o="SMART_TV",i=this.params.vktvVersion),{collector:"ok.mobile.apps.video",data:JSON.stringify({application:i,platform:o,items:this.params.config.shorten?e.map(Je):e})}}_authorizeWithBackoff(){if(!this.consequentAuthErrors)return this._authorize();let e=Qt(this.consequentAuthErrors,this.params.config.backoff);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(()=>{this._authorize().then(o).catch(t=>this.params.error$.next({id:"AuthorizeBackoff",category:N.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",o={session_data:{version:2,device_id:this.params.deviceId,client_version:P.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(t=>((!t||!t.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:N.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 i=t?.error_code;switch(i){case 401:return this.authToken=await this.refreshAuthToken(),this._authorizeWithBackoff()}i?this.params.error$.next({id:`Authorize#${i}`,category:N.EXTERNAL_API,message:"authorize error",data:t}):this.params.error$.next({id:"AuthorizeUnknown",category:N.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 G,now as ye}from"@vkontakte/videoplayer-shared/evergreen";var W=class{constructor(e){this.params=e,this.apiKey=e.config.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=e.config.apiBaseUrl??be[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="),i=(await(await fetch(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!i)throw new Error("Wrong DNS response");return i}catch(e){return this.params.error$.next({id:"OneStat:ApiTransport:resolveApiBaseUrl",category:G.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),be.vk_alias}finally{this.isApiBaseUrlFetched=!0}}sendBeacon(e,o,t){if(!window.Blob||!window.navigator.sendBeacon)return!1;let i=this._prepareQueryParams({method:e,queryParams:o,sessionKey:t}),n=new window.Blob([i.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,n)}catch(d){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:G.NETWORK,message:"Unhandled beacon error",thrown:d,data:{method:e,params:o}})}return!1}async sendRequest(e,o,t){let i=ye(),n=l=>{if(l instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(l.message)){this.params.error$.next({id:"Network",category:G.NETWORK,message:"Request failed",thrown:l});return}this.params.error$.next({id:"OneStat:ApiTransport:sendRequest",category:G.NETWORK,message:"Unhandled request error",thrown:l,data:{method:e,params:o,sessionKey:t,time:ye()-i}})};this.apiBaseUrl=await this.resolveApiBaseUrl();let d={method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:e,queryParams:o,sessionKey:t})};return this.params.config.useKeepalive&&(d.keepalive=!0),fetch(`${this.apiBaseUrl}/fb.do`,d).then(l=>{let h=Number(l.headers.get("content-length"))===0,p=new Date(l.headers.get("date")??"").getTime(),f=ye()-i;if(isFinite(p)&&this.timeSynchronisation?.addServerTime(p,f),!h)return l.json().then(r=>Object.prototype.hasOwnProperty.call(r,"error_msg")?Promise.reject(r):r,n)},n)}_prepareQueryParams(e){let o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([t,i])=>o.append(t,typeof i=="string"?i:JSON.stringify(i))),o}};import{ErrorCategory as zt,now as jt,safeStorage as Q,debounceFn as Ze}from"@vkontakte/videoplayer-shared/evergreen";var Y="onestat_events",Se=a=>e=>e.timestamp+a>=jt(),X=class{constructor(e){this.unsaltedStorage=[];this.isPaused=!1;this.isUrgent=e=>{let{operation:o}=e;return["action_play","watch_coverage_record","watch_coverage_live"].includes(o)};this.params=e,this.api=e.api,this.error$=e.error$,this.userSalt=e.userSalt,this.loggerDebugLog=e.debugLogger.createComponentLog("stat logger"),this.firstFlush=Ze(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let o=Q.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=Ze(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:o}),this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()}),this.housekeepStorage()}safeFlush(){try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:zt.WTF,message:e?String(e):"Unknown logger error",thrown:e})}}readFromStorage(){let e=Q.get(Y);try{return e?JSON.parse(e):{}}catch{}return{}}addToStorage(e){if(!this.userSalt){this.unsaltedStorage.push(e);return}let o=this.readFromStorage(),i=(o[this.userSalt]??[]).filter(Se(this.params.config.storageExpiration));Q.set(Y,JSON.stringify({...o,[this.userSalt]:[...i,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(Se(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],Q.set(Y,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[o,t]of Object.entries(e)){let i=t.filter(Se(this.params.config.storageExpiration));i.length?e[o]=i:delete e[o],this.loggerDebugLog({message:`${t.length} retrieved from storage, ${i.length} of them actual`})}Q.set(Y,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({wantBeacon:e,clearStorage:o}={wantBeacon:!1,clearStorage:!0}){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)),o&&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 _e,Surface as O,VideoFormat as y,VideoQuality as w}from"@vkontakte/videoplayer-core/evergreen";import{assertNever as et}from"@vkontakte/videoplayer-shared/evergreen";var tt=a=>a&&{[w.INVARIANT]:"unknown",[w.Q_144P]:"mobile",[w.Q_240P]:"lowest",[w.Q_360P]:"low",[w.Q_480P]:"medium",[w.Q_576P]:"unknown",[w.Q_720P]:"high",[w.Q_1080P]:"fullhd",[w.Q_1440P]:"quadhd",[w.Q_2160P]:"ultrahd",[w.Q_4320P]:"unknown"}[a],Pe=a=>a&&{[_e.HTTP1]:"http1",[_e.HTTP2]:"http2",[_e.QUIC]:"http3"}[a],it=a=>{if(a!==void 0)switch(a){case y.MPEG:return"mp4";case y.DASH:case y.DASH_LIVE:case y.DASH_STREAMS:return"dash";case y.DASH_SEP:return"dash_sep";case y.DASH_ONDEMAND:return"ondemand_dash";case y.DASH_WEBM:case y.DASH_LIVE_WEBM:return"webm";case y.DASH_WEBM_AV1:return"av1";case y.DASH_LIVE_CMAF:return"ondemand_dash_live";case y.HLS:case y.HLS_LIVE:return"hls";case y.HLS_FMP4:return"hls_fmp4";case y.HLS_ONDEMAND:return"ondemand_hls";case y.HLS_LIVE_CMAF:return"ondemand_hls_live";case y.WEB_RTC_LIVE:return"webrtc";default:return et(a)}},Te=(a,e)=>{if(e)return"minimal";switch(a){case void 0:case O.NONE:case O.INLINE:return;case O.FULLSCREEN:return"fullscreen";case O.SECOND_SCREEN:return"chromecast";case O.PIP:return"pip";case O.INVISIBLE:return"invisible";default:return et(a)}},ot=a=>{switch(a){case"slow-2g":return"poor";case"2g":return"poor";case"3g":return"good";case"4g":return"excellent"}};var J=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,o){let t=Date.now(),i=e-t-o/2;if(Math.abs(i)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(i):this.offset=Math.round(.2*i+(1-.2)*this.offset)}};var rt=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");import{PlaybackState as st}from"@vkontakte/videoplayer-core/evergreen";import{filter as nt,filterChanged as Gt,fromEvent as Yt,isNullable as at,map as Xt,merge as Ee,Observable as Jt,Subject as we,Subscription as Zt,ValueSubject as ei}from"@vkontakte/videoplayer-shared/evergreen";var dt=(a,e)=>new Jt(o=>{let t=new Zt,i=Ee(Yt(window,"beforeunload"),a.events.willDestruct$),n=new ei(void 0),d;t.add(a.info.isLive$.pipe(Gt()).subscribe(v=>{d&&(d.unsubscribe(),n.next(void 0)),v?d=a.info.liveTime$.pipe(Xt(_=>_&&_/1e3)).subscribe(n):d=a.info.position$.subscribe(n),t.add(d)}));let{playing$:l,paused$:h}=a.events,p=a.events.willSeek$.pipe(nt(()=>a.info.playbackState$.getValue()===st.PLAYING)),f=a.events.seeked$.pipe(nt(()=>a.info.playbackState$.getValue()===st.PLAYING)),r=!1,s=new we;t.add(p.subscribe(()=>{r||s.next(),r=!0})),t.add(f.subscribe(()=>r=!1));let c=new we,u=new we,g=Ee(l,f,c),m=Ee(h,s,i,a.events.looped$,u),b,T=()=>b=n.getValue(),E=()=>{let v=n.getValue();at(b)||b===v||at(v)||(o.next({from:b,to:v}),b=void 0)},S=()=>{u.next(),c.next()};if(t.add(g.subscribe(T)),t.add(m.subscribe(E)),e.forceInterval&&isFinite(e.forceInterval))if(e.watchCoverageTimeoutFix){let v,_=()=>{v!==void 0&&(window.clearTimeout(v),v=void 0)};t.add(g.subscribe(()=>{_(),v=window.setTimeout(S,e.forceInterval)})),t.add(m.subscribe(()=>_())),t.add(()=>_())}else{let v=0;t.add(g.subscribe(()=>v=window.setTimeout(S,e.forceInterval))),t.add(m.subscribe(()=>window.clearTimeout(v)))}return t});import{Surface as C}from"@vkontakte/videoplayer-core/evergreen";import{debounce as ti,filterChanged as ii,Subject as oi}from"@vkontakte/videoplayer-shared/evergreen";var Z=(a,e,o)=>{let t=new oi,i=t.pipe(ti(0),ii()),n=!1,d=!1,l=!1;return e(a.inPiP$,h=>{n=h,t.next(h?C.PIP:d?C.FULLSCREEN:l?C.INLINE:void 0)}),e(a.inFullscreen$,h=>{d=h,t.next(h?C.FULLSCREEN:n?C.PIP:l?C.INLINE:void 0)}),o&&e(o.info.surface$,h=>{switch(h){case C.SECOND_SCREEN:case C.NONE:case C.INLINE:{!d&&!n&&(h===C.INLINE&&(l=!0),t.next(h));break}}}),{surface$:i}};var ui="_one-stat_",pt=`${ui}deviceId`,Ae=()=>{let a=new xe;return{subscription:a,subscribe:(e,o)=>{e&&a.add(e.subscribe(o))}}},ke=class{constructor(e,o){this.subscription=new xe;this.debugLogger=new ci;this.oneStatDebugLog=this.debugLogger.createComponentLog("onestat");this.loopCounter=0;this.disabled=!1;this.isid$=new ee(void 0);this.zenUid$=new ee(void 0);this.seekAction$=new ee("unknown");this.statContext=e,this.config=Xe(o.config??{}),V(o.apiEnv)&&(this.config.apiEnv=o.apiEnv),this.config.synchronizeTime&&(this.timeSynchronisation=new J);let t=new di;this.experimental={error$:t};let i=ht.get(pt);this.statContext.deviceId?this.deviceId=this.statContext.deviceId:i?this.deviceId=i:(this.deviceId=Ie(),ht.set(pt,this.deviceId)),this.resetViewSession(),o.useIsid&&this.isid$.next(o.isid??rt()),this.zenUid$.next(o.zenUid);let n=new W({config:this.config,error$:t,timeSynchronisation:this.timeSynchronisation});this.api=new q({config:this.config,apiTransport:n,refreshAuthToken:o.refreshAuthToken,mobile:this.statContext.mobile??!1,deviceId:this.deviceId,error$:t,vktvVersion:o.vktvVersion}),this.logger=new X({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:t,userSalt:o.userSalt});let{isEmbed:d,topOrigin:l}=li();this.isEmbed=d,this.embedParent=l?new URL(l).hostname:void 0,this.subscribe()}get vsid$(){return new ee(R.getVSID())}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e){let o=new xe,t=(s,c)=>o.add(s.subscribe(c));t(e.events.willStart$,()=>{let s=e.info.position$.getValue();this.logActionPlay({position:s}),this.statContext.projectId&&this.logActionPlayInteractive()}),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(e.events.playing$,()=>{this.logPlaying()}),t(dt(e,{forceInterval:this.config.watchCoverageInterval,watchCoverageTimeoutFix:this.config.watchCoverageTimeoutFix}),s=>{let c=e.info.isLive$.getValue(),u=e.info.atLiveEdge$.getValue(),g={start:parseFloat(s.from.toFixed(3)),end:parseFloat(s.to.toFixed(3))};if(u){let m=e.info.liveLatency$.getValue()??0,b=e.info.currentBuffer$.getValue()?.end??0,T=e.info.liveBufferTime$.getValue()??0,E=Math.round((m-(b-T))*1e3),S=Math.round(m*1e3);E&&S&&(g.latency=E,g.bufferLatency=S)}c?this.logWatchCoverageLive(g):this.logWatchCoverageRecord(g)});let i;t(e.info.isStalled$,s=>{s?i=D():(V(i)&&this.logEmptyBuffer({duration:D()-i}),i=void 0)});let n=!1;o.add(e.events.fatalError$.pipe(ai()).subscribe(()=>n=!0)),t(e.events.willStop$,()=>{if(e.info.isStalled$.getValue()){let c=V(i)?D()-i:void 0;this.logCloseAtEmptyBuffer({duration:c??0}),i=void 0}else n||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 d,l,h=!1;t(e.events.firstBytes$,s=>{d=D(),this.logFirstBytes({time:s})}),t(e.events.willStart$,()=>l=D()),t(e.info.currentBuffer$,s=>{!h&&s&&s.end-s.start>0&&V(d)&&(this.logPlayerReady({duration:D()-d}),h=!0)}),t(e.events.firstFrame$,()=>{V(d)&&!h&&(this.logPlayerReady({duration:D()-d}),h=!0),V(l)&&this.logFirstFrame({time:D()-l})});let p;t(e.info.currentVideoStream$,s=>{s&&(p&&s.id!==p&&this.logTrackSwitch(s),p=s.id)});let f;t(e.info.currentAudioStream$,s=>{s&&(f&&s.id!==f&&this.logTrackSwitch(s),f=s.id)}),t(e.info.atLiveEdge$,s=>this.updateContext({liveEdge:s})),t(ct({muted:e.info.muted$,volume:e.info.volume$}),({muted:s,volume:c})=>this.updateContext({audible:!s&&c>0})),t(e.info.currentQuality$,s=>{let c=tt(s);this.updateContext({quality:c}),c&&this.logQuality(c)}),t(e.info.isAutoQualityEnabled$,s=>this.updateContext({autoQuality:s})),t(e.info.currentFormat$,s=>this.updateContext({contentType:it(s)})),t(e.info.currentPlaybackRate$,s=>this.updateContext({rate:s})),t(e.info.is3DVideo$,s=>this.updateContext({is3d:s}));let r;return t(e.info.hostname$,s=>{let c=r!==void 0&&r!==s;this.updateContext({cdnHostname:s,failover:c}),c&&this.logFailover(s),r=s}),t(e.info.throughputEstimation$,s=>this.updateContext({downloadSpeed:s})),t(e.info.httpConnectionType$,s=>{this.statContext.firstConnectionType||this.updateContext({firstConnectionType:Pe(s)}),this.updateContext({connectionType:Pe(s)})}),t(e.info.httpConnectionReused$,s=>{ut(this.statContext.firstConnectionReused)&&this.updateContext({firstConnectionReused:s}),this.updateContext({connectionReused:s})}),t(e.info.surface$,s=>{this.uiEvents||this.updateContext({mode:Te(s,this.statContext.isPreviewPlayerView)})}),t(ct({current:e.info.currentTextTrack$,available:e.info.availableTextTracks$}),({current:s,available:c})=>{let u=c.find(({id:m})=>m===s),g=u&&(u.isAuto?`${u.language}_auto`:u.language);this.updateContext({subtitles:g?.split(".")[0]})}),this.player=e,this.uiEvents&&this.attachToUi(this.uiEvents),this.resubscribeBeforeunload(),this.subscription.add(o),o}attachToUi(e){this.uiEvents=e;let{subscription:o,subscribe:t}=Ae();if(!this.player)return o;t(e.actionRewind$,()=>{this.player&&(this.resetViewSession(),this.logActionPlay({position:this.player.info.position$.getValue()}))}),t(e.actionSeek$,this.seekAction$);let{surface$:i}=Z(this.uiEvents,t,this.player);return t(i,n=>{this.updateContext({mode:Te(n,this.statContext.isPreviewPlayerView)})}),t(e.actionSetSubtitle$,n=>this.updateContext({subtitles:n?.split(".")[0]})),t(e.nextMovie$,n=>this.logNextMovie(n)),this.resubscribeBeforeunload(),this.subscription.add(o),o}attachToAds(e){let{subscription:o,subscribe:t}=Ae();return t(e.slotRequested$,()=>this.logAdSlotRequest()),t(e.started$,i=>this.logAdStarted(i)),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()),t(e.error$,i=>this.logError({errorType:i,fatal:!1})),this.resubscribeBeforeunload(),this.subscription.add(o),o}attachToInteractive(e){let{subscription:o,subscribe:t}=Ae();return t(e.click$,i=>this.logInterfaceClick(i)),t(e.nextMovie$,i=>this.logNextMovie(i)),this.resubscribeBeforeunload(),this.subscription.add(o),o}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"}),R.generateVSID()}getDeviceId(){return this.deviceId}setFieldBlacklist(){}logInited(){}logReady(e){this.log({operation:"player_ready",param:String(e.time)})}logStarted(...e){this.logActionPlay(...e)}logPlay(){this.log({operation:"play_toggle"})}logPlaying(){this.log({operation:"playing"})}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}`},{in_history:this.statContext.inHistory?1:void 0})}logWatchCoverageLive(e){let o=this.timeSynchronisation?.getOffset()??0,t=e.start+o,i=e.end+o;this.log({operation:"watch_coverage_live",param:`${t}-${i}`},{in_history:this.statContext.inHistory?1:void 0,latency:e.latency,buffer_latency:e.bufferLatency})}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(si(lt(e,"change"),ni(["init"])).subscribe(()=>this.updateContext({network:ot(e.effectiveType)}))),this.config.debugLog&&this.debugLogger.log$.subscribe(o=>{console.debug("%c stat ","background:#fa6470;",`component: ${o.component}.`,o.message)})}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=lt(window,"beforeunload").subscribe(()=>this.logger.flush({wantBeacon:!0,clearStorage:this.config.clearStorageAtUnload})),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(){this.statContext.projectId&&this.log({operation:"action_play_interactive",param:String(this.statContext.movieId)},{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"})}logTrackSwitch(e){this.log({operation:"track_switch",param:e.id})}logQuality(e){this.log({operation:"quality",param:e})}log(e,o={}){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,o);this.logger.log(t)}createLogItem({operation:e,param:o,time:t},i={}){let n=this.timeSynchronisation?.now()??D(),d=this.vsid$.getValue();ri(d);let l=this.isid$.getValue(),h=e==="empty_buffer"||e==="close_at_empty_buffer"?this.statContext.connectionType:this.statContext.firstConnectionType,p=this.statContext.firstConnectionReused,f,r;if(this.isEmbed||this.statContext.place==="embed"){f=this.embedParent;let c=[...new URLSearchParams(location.search).entries()].filter(([u,g])=>this.config.embedUrlParams.includes(u));r=new URLSearchParams(c).toString()}else if(this.statContext.place==="direct"){let c=this.statContext.refDomain||document.referrer;c&&URL.canParse(c)?f=new URL(c).hostname:f=c,r=location.href.substring(0,1024)}let s={vsid:d,isid:l,vid:this.statContext.movieId,uid:this.zenUid$.getValue(),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:o,vk_app_id:this.statContext.vkAppId,track_code:this.statContext.trackCode,connection_type:h,connection_reused:p===!0?1:p===!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:f,direct_url:r,rate:this.statContext.rate===1||ut(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,...i};for(let c of this.config.disabledCustomFields)delete s[c];return{operation:e,type:1,time:t,network:this.statContext.network,timestamp:n,custom:s}}};var Rt={};Bt(Rt,{ActionSeekType:()=>te,ThinOneStat:()=>ue,VERSION:()=>P});import{assertNonNullable as Ci,detectEmbed as Li,fromEvent as $i,Logger as Di,merge as Ve,combine as le,filter as k,filterChanged as Ri,once as Mi,skip as Fe,safeStorage as Lt,getWindow as Ni,Subject as Oi,Subscription as Ue,ValueSubject as Be,ErrorCategory as U}from"@vkontakte/videoplayer-shared/evergreen";import{clientChecker as L}from"@vkontakte/videoplayer-core/evergreen";import{fillWithDefault as hi}from"@vkontakte/videoplayer-shared/evergreen";var Ce=(t=>(t.AUTO="auto",t.AUTO_POOR="auto_poor",t.AUTO_RICH="auto_rich",t))(Ce||{});var te=(l=>(l.SLIDER="slider",l.DOUBLE_TAP="double_tap",l.TIME_CODE="time_code",l.EPISODE="episode",l.REWIND="rewind",l.LIVE="live",l.UNKNOWN="unknown",l))(te||{});var gt="CIOPGQJGDIHBABABA",Le={prod:"https://api.ok.ru",vk_alias:"https://api.mycdn.me",videotest:"https://videotestapi.ok.ru/api",test:"https://apitest.ok.ru",okcdn:"https://api.okcdn.ru",auto:""};var pi={apiKey:gt,apiEnv:"okcdn",apiBaseUrl:null,requestRetryCount:1,firstFlushTime:5e3,flushDebounceTime:1e4,flushMaxWait:6e4,storageExpiration:36*60*60*1e3,watchCoverageHeartbeatInterval:30,synchronizeTime:!0,useBeacon:!1,alwaysSendDesktop:!1,watchedNFirstTvtLog:1e3,watchedNDefaultTargetDuration:1e4},mt=a=>hi(a,pi);import{getExponentialDelay as fi,ErrorCategory as F,ValueSubject as gi}from"@vkontakte/videoplayer-shared/evergreen";var ie=class{constructor(e){this.params=e,this.authorized$=new gi(!1),this.consequentAuthErrors=0}async authorize(e){return this.authToken=e??await this.refreshAuthToken(),this.authorizeWithBackoff()}logBeacon(e){let o="log.logUvStat",t=this.createLogParams(e),i=this.sessionKey;if(!i)return;this.params.apiTransport.sendBeacon(o,t,i)||this.logRequest(e).catch(()=>{})}async logRequest(e){let o="log.logUvStat",t=this.createLogParams(e),i={},n=this.sessionKey??await this.authorizeWithBackoff();if(!n)return;let d=async(l,h=this.params.config.requestRetryCount)=>{try{return await this.params.apiTransport.sendRequest(o,t,n,i)}catch(p){if(!p||!("error_code"in p)){this.params.error$.next({id:"logRequestUnknown",category:F.NETWORK,message:`Unknown ${o} 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(),h>0?d(l,h-1):void 0;case 401:return this.authorized$.next(!1),this.authToken=await this.refreshAuthToken(),this.sessionKey=await this.authorizeWithBackoff(),h>0?d(l,h-1):void 0;default:{this.params.error$.next({id:`LogRequest#${f}`,category:F.EXTERNAL_API,message:`${o} error`,data:p});return}}}};return d(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",uv_stat_data:JSON.stringify({application:`@vkontakte/videoplayer-statistics:${P}`,platform:e[0].platform,product:e[0].product,events:e})}}authorizeWithBackoff(){if(!this.consequentAuthErrors)return this.doAuthorize();let e=fi(this.consequentAuthErrors);return new Promise(o=>{this.backoffTimeoutId||(this.backoffTimeoutId=window.setTimeout(async()=>{try{let t=await this.doAuthorize();o(t)}catch(t){this.params.error$.next({id:"AuthorizeBackoff",category:F.NETWORK,message:"Otherwise unhandled error in authorization",thrown:t})}finally{this.backoffTimeoutId=0}},e))})}doAuthorize(){if(this.authorizePromise)return this.authorizePromise;this.sessionKey=void 0,this.authorized$.next(!1);let e="auth.anonymLogin",o={session_data:{version:2,device_id:this.params.deviceId,client_version:P.split("-")[0],client_type:"SDK_JS"}};return this.authToken!==void 0&&(o.session_data.auth_token=this.authToken,o.session_data.version=3),this.authorizePromise=this.params.apiTransport.sendRequest(e,o).then(t=>((!t||!t.session_key)&&this.params.error$.next({id:"AuthorizeFailed",category:F.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 i=t?.error_code;switch(i){case 401:return this.authToken=await this.refreshAuthToken(),this.authorizeWithBackoff()}i?this.params.error$.next({id:`Authorize#${i}`,category:F.EXTERNAL_API,message:"authorize error",data:t}):this.params.error$.next({id:"AuthorizeUnknown",category:F.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{now as $e,ErrorCategory as oe}from"@vkontakte/videoplayer-shared/evergreen";var re=class{constructor(e){this.params=e,this.apiKey=e.config.apiKey,this.apiEnv=e.config.apiEnv,this.apiBaseUrl=e.config.apiBaseUrl??Le[this.apiEnv],this.timeSynchronisation=e.timeSynchronisation,this.isApiBaseUrlFetched=!1}sendBeacon(e,o,t){if(!window.Blob||!window.navigator.sendBeacon)return!1;let i=this.prepareQueryParams({method:e,queryParams:o,sessionKey:t}),n=new window.Blob([i.toString()],{type:"application/x-www-form-urlencoded"});try{return window.navigator.sendBeacon(`${this.apiBaseUrl}/fb.do`,n)}catch(d){this.params.error$.next({id:"OneStat:ApiTransport:sendBeacon",category:oe.NETWORK,message:"Unhandled beacon error",thrown:d,data:{method:e,params:o}})}return!1}async sendRequest(e,o,t,i){let n=$e(),d=l=>{if(l instanceof TypeError&&["Failed to fetch","NetworkError when attempting to fetch resource."].includes(l.message)){this.params.error$.next({id:"Network",category:oe.NETWORK,message:"Request failed",thrown:l});return}this.params.error$.next({id:"ThinOneStat:ApiTransport:sendRequest",category:oe.NETWORK,message:"Unhandled request error",thrown:l,data:{method:e,params:o,sessionKey:t,time:$e()-n}})};return this.apiBaseUrl=await this.resolveApiBaseUrl(),fetch(`${this.apiBaseUrl}/fb.do`,{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded",...i},body:this.prepareQueryParams({method:e,queryParams:o,sessionKey:t})}).then(l=>{let h=Number(l.headers.get("content-length"))===0,p=new Date(l.headers.get("date")??"").getTime(),f=$e()-n;if(isFinite(p)&&this.timeSynchronisation?.addServerTime(p,f),!h)return l.json().then(r=>Object.prototype.hasOwnProperty.call(r,"error_msg")?Promise.reject(r):r,d)},d)}async resolveApiBaseUrl(){if(this.apiEnv!=="auto"||this.isApiBaseUrlFetched)return this.apiBaseUrl;try{let e=atob("aHR0cHM6Ly9kbnMuZ29vZ2xlL3Jlc29sdmU/bmFtZT12aWRlby5fZW5kcG9pbnQub2sucnUmdHlwZT1UWFQ="),i=(await(await fetch(e,{method:"GET",mode:"cors",cache:"no-cache"})).json())?.Answer[0]?.data;if(!i)throw new Error("Wrong DNS response");return i}catch(e){return this.params.error$.next({id:"ThinOneStat:ApiTransport:resolveApiBaseUrl",category:oe.NETWORK,message:"Unhandled resolve api base url error",thrown:e}),Le.vk_alias}finally{this.isApiBaseUrlFetched=!0}}prepareQueryParams(e){let o=new URLSearchParams({format:"JSON",method:e.method,application_key:this.apiKey});return e.sessionKey!==void 0&&o.append("session_key",e.sessionKey),Object.entries(e.queryParams).forEach(([t,i])=>o.append(t,typeof i=="string"?i:JSON.stringify(i))),o}};import{ErrorCategory as mi,now as vi,safeStorage as K,debounceFn as vt}from"@vkontakte/videoplayer-shared/evergreen";var se="thinonestat_events",De=a=>e=>e.client_time+a>=vi(),ne=class{constructor(e){this.unsaltedStorage=[];this.isPaused=!1;this.isUrgent=e=>{let{event_name:o}=e;return["watch_coverage","watch_coverage_live","watched_n","playback_started"].includes(o)};this.params=e,this.api=e.api,this.error$=e.error$,this.userSalt=e.userSalt,this.loggerDebugLog=e.debugLogger.createComponentLog("stat logger"),this.firstFlush=vt(()=>this.safeFlush(),this.params.config.firstFlushTime,{maxWait:this.params.config.firstFlushTime});let o=K.isPersistent()?this.params.config.flushMaxWait:0;this.debouncedFlush=vt(()=>this.safeFlush(),this.params.config.flushDebounceTime,{maxWait:o}),this.subscription=this.api.authorized$.subscribe(t=>{t&&this.debouncedFlush()}),this.housekeepStorage()}safeFlush(){try{this.flush()}catch(e){this.error$.next({id:"LoggerError",category:mi.WTF,message:String(e)||"Unknown logger error",thrown:e})}}readFromStorage(){let e=K.get(se);try{return e?JSON.parse(e):{}}catch{}return{}}addToStorage(e){if(!this.userSalt){this.unsaltedStorage.push(e);return}let o=this.readFromStorage(),i=(o[this.userSalt]??[]).filter(De(this.params.config.storageExpiration));K.set(se,JSON.stringify({...o,[this.userSalt]:[...i,e]}))}getFromStorage(){return this.userSalt?(this.readFromStorage()[this.userSalt]??[]).filter(De(this.params.config.storageExpiration)):this.unsaltedStorage}markStorageSent(){if(!this.userSalt){this.unsaltedStorage=[];return}let e=this.readFromStorage();delete e[this.userSalt],K.set(se,JSON.stringify(e))}housekeepStorage(){let e=this.readFromStorage();for(let[o,t]of Object.entries(e)){let i=t.filter(De(this.params.config.storageExpiration));i.length?e[o]=i:delete e[o],this.loggerDebugLog({message:`${t.length} retrieved from storage, ${i.length} of them actual`})}K.set(se,JSON.stringify(e))}log(e){this.addToStorage(e),!this.isPaused&&(this.isUrgent(e)?this.flush():this.lastVsid!==e.vsid?this.firstFlush():this.debouncedFlush(),this.lastVsid=e.vsid)}flush({wantBeacon:e,clearStorage:o}={wantBeacon:!1,clearStorage:!0}){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)),o&&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()}};function Re(){let a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),e=new Array(36),o=0,t,i;for(i=0;i<36;i++)i===8||i===13||i===18||i===23?e[i]="-":i===14?e[i]="4":(o<=2&&(o=33554432+Math.random()*16777216|0),t=o&15,o=o>>4,e[i]=a[i===19?t&3|8:t]);return e.join("")}var ae=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,o){let t=Date.now(),i=e-t-o/2;if(Math.abs(i)<1e3){this.offset=0;return}this.offset===void 0?this.offset=Math.round(i):this.offset=Math.round(.2*i+(1-.2)*this.offset)}};import{PlaybackState as bt}from"@vkontakte/videoplayer-core/evergreen";import{Observable as bi,Subscription as Ii,ValueSubject as yi,Subject as Me,fromEvent as Si,isNullable as It,merge as z,filter as yt,filterChanged as St}from"@vkontakte/videoplayer-shared/evergreen";var _t=(a,e,o)=>new bi(t=>{let i=new Ii,n=new yi(void 0),d;i.add(a.info.isLive$.pipe(St()).subscribe($=>{d&&(d.unsubscribe(),n.next(void 0)),$?d=a.info.liveTime$.pipe(St()).subscribe(n):d=a.info.position$.subscribe(n),i.add(d)}));let{playing$:l,paused$:h,ended$:p,looped$:f}=a.events,r=a.events.willSeek$.pipe(yt(()=>a.info.playbackState$.getValue()===bt.PLAYING)),s=a.events.seeked$.pipe(yt(()=>a.info.playbackState$.getValue()===bt.PLAYING)),c=!1,u=new Me;i.add(r.subscribe(()=>{c||u.next(),c=!0})).add(s.subscribe(()=>c=!1));let g=z(Si(window,"beforeunload"),a.events.willDestruct$),m,b=()=>m=n.getValue(),T=()=>{let $=n.getValue();It(m)||It($)||m===$||(t.next({from:m,to:$}),m=void 0)},E=new Me,S=new Me,v=z(l,u,E),_=z(h,s,g,p,f,S),qe=e.started$&&e.ended$?z(v,e.ended$):v,We=e.started$&&e.ended$?z(_,e.started$):_;if(i.add(qe.subscribe(b)).add(We.subscribe(T)),o.heartbeatInterval&&isFinite(o.heartbeatInterval)){let $=[],Ot=o.heartbeatInterval*1e3,Vt=()=>{S.next(),E.next()};i.add(qe.subscribe(()=>{let pe=window.setTimeout(Vt,Ot);$.push(pe)})).add(We.subscribe(()=>{$.forEach(pe=>{window.clearTimeout(pe)}),$=[]}))}return i});import{Subscription as _i}from"@vkontakte/videoplayer-core/evergreen";import{Observable as Pi,merge as Ti}from"@vkontakte/videoplayer-shared/evergreen";var Pt=(a,e)=>new Pi(o=>{let t=new _i,i=0;return t.add(Ti(a.info.position$,a.info.liveTime$).subscribe(()=>{let n=e.getTotalViewTime();if(n>i){let d=e.firstTvtLog>i&&e.firstTvtLog<=n,l=Math.floor(n/e.targetDuration)>Math.floor(i/e.targetDuration);(d||l)&&(i=n,o.next({target_duration:e.targetDuration,current_tvt:n}))}})),t});import{Subscription as Ei}from"@vkontakte/videoplayer-core/evergreen";import{Observable as wi,filter as Ai,getWindow as Tt}from"@vkontakte/videoplayer-shared/evergreen";var Et=a=>new wi(e=>{let o=new Ei,t={maxBytesThreshold:10*1024*1024,minBytesThreshold:100*1024,maxTimeWindow:1e4,minTimeWindow:2e3},i={bytes:0,startTime:0,lastEmitTime:0,timeoutId:0},n=()=>{i.timeoutId&&(Tt().clearTimeout(i.timeoutId),i.timeoutId=null)},d=()=>{i.bytes=0,i.startTime=0,i.lastEmitTime=0,n()},l=f=>{if(i.bytes<t.minBytesThreshold||f-i.lastEmitTime<t.minTimeWindow&&i.lastEmitTime>0)return!1;let s=i.startTime>0?f-i.startTime:0,c=i.bytes>=t.maxBytesThreshold,u=s>=t.maxTimeWindow;return c||u},h=(f=!1)=>{let r=Date.now();if(!f&&!l(r))return;n();let s=i.startTime>0?r-i.startTime:Math.max(t.minTimeWindow,1),c=i.bytes/(s/1e3);e.next({download_bytes:Math.round(i.bytes),download_speed:Math.round(c)}),i.lastEmitTime=r,d()},p=()=>{if(n(),i.startTime>0&&i.bytes>=t.minBytesThreshold){let r=Date.now()-i.startTime,s=t.maxTimeWindow-r;s>100?i.timeoutId=Tt().setTimeout(()=>{i.timeoutId=null,h()},s):s>0&&h()}};return o.add(a.info.httpDownloadMetrics$.pipe(Ai(f=>f!==void 0)).subscribe(f=>{let r=Date.now();i.startTime===0&&(i.startTime=r),i.bytes+=f.bytes,l(r)?h():p()})),o.add(()=>{if(n(),i.bytes>0){let f=Date.now(),r=i.startTime>0?f-i.startTime:t.minTimeWindow,s=i.bytes/(r/1e3);e.next({download_bytes:Math.round(i.bytes),download_speed:Math.round(s)})}d()}),o});import{Observable as xi,Subscription as ki,merge as wt}from"@vkontakte/videoplayer-shared/evergreen";var At=a=>new xi(e=>{let o=new ki,t=0,i=1,n=0,d=!1,l=!1,h=()=>{if(!d)return;let v=Date.now();n+=(v-t)*i,t=v},p=()=>{(!d||l)&&(t=Date.now(),d=!0,l=!1)},f=()=>{d&&(h(),d=!1)},r=()=>{d&&(h(),d=!1,l=!0)},s=v=>{d&&h(),i=v,t=Date.now()},{started$:c,playing$:u,paused$:g,willSeek$:m,ended$:b,willDestruct$:T}=a.events,{currentPlaybackRate$:E}=a.info;o.add(m.subscribe(r)).add(wt(c,u).subscribe(p)).add(wt(g,b,T).subscribe(f)).add(E.subscribe(s));let S=()=>{let v=n;return d&&(v+=(Date.now()-t)*i),v};return e.next(S),o});import{assertNever as xt}from"@vkontakte/videoplayer-shared/evergreen";import{HttpConnectionType as Ne,Surface as B,VideoFormat as I,VideoQuality as A}from"@vkontakte/videoplayer-core/evergreen";var Oe=a=>a&&{[Ne.HTTP1]:"http1",[Ne.HTTP2]:"http2",[Ne.QUIC]:"http3"}[a],j=a=>{if(a!==void 0)switch(a){case I.MPEG:return"MP4";case I.DASH:case I.DASH_LIVE:return"DASH";case I.DASH_SEP:return"DASH_SEP";case I.DASH_ONDEMAND:return"ONDEMAND_DASH";case I.HLS_ONDEMAND:return"ONDEMAND_HLS";case I.HLS:case I.HLS_LIVE:return"HLS";case I.HLS_FMP4:return"HLS_FMP4";case I.DASH_WEBM:case I.DASH_LIVE_WEBM:return"WEBM";case I.DASH_LIVE_CMAF:return"ONDEMAND_DASH_LIVE";case I.HLS_LIVE_CMAF:return"ONDEMAND_HLS_LIVE";case I.WEB_RTC_LIVE:return"WEBRTC";case I.DASH_WEBM_AV1:return"AV1";case I.DASH_STREAMS:return"MULTI_DASH";default:return xt(a)}},x=a=>{if(a!==void 0)switch(a){case A.Q_144P:return"144p";case A.Q_240P:return"240p";case A.Q_360P:return"360p";case A.Q_480P:return"480p";case A.Q_720P:return"720p";case A.Q_1080P:return"1080p";case A.Q_1440P:return"1440p";case A.Q_2160P:return"2160p";case A.INVARIANT:case A.Q_576P:case A.Q_4320P:return"UNKNOWN";default:return xt(a)}},kt=a=>{if(a!==void 0)switch(a){case"MP4":case"ONDEMAND_DASH":case"ONDEMAND_DASH_LIVE":case"ONDEMAND_HLS":case"ONDEMAND_HLS_LIVE":case"MULTI_DASH":case"WEBM":case"AV1":return"vod";case"DASH":case"HLS":case"HLS_FMP4":case"WEBRTC":return"live";default:return}},M=(a,e,o)=>{if(a&&e)switch(a){case I.MPEG:return o&&e[a]&&e[a][o];default:return e[a]?.url}},de=(a,e=!1)=>{if(e)return"minimal";switch(a){case void 0:case B.NONE:return;case B.INLINE:return"inline";case B.FULLSCREEN:return"fullscreen";case B.SECOND_SCREEN:return"chromecast";case B.PIP:return"pip_external"}},ce=a=>{switch(a){case void 0:return;case B.INVISIBLE:return"background";default:return"foreground"}};var Ct=()=>Math.floor(Math.random()*18446744073709552e3).toString(36).padStart(13,"0");var Vi="_thin-one-stat_",$t=`${Vi}deviceId`,Dt=()=>{let a=new Ue;return{subscription:a,subscribe:(e,o)=>{e&&a.add(e.subscribe(o))}}},ue=class{constructor(e,o){this.debugLogger=new Di;this.thinOneStatDebugLog=this.debugLogger.createComponentLog("ThinOneStat");this.eventNumber=1;this.playerSize={width:0,height:0};this.seekAction$=new Be("unknown");this.isid$=new Be(void 0);this.statContext=e,this.config=mt(o.config??{}),this.subscription=new Ue,this.config.synchronizeTime&&(this.timeSynchronisation=new ae);let t=new Oi,i=Lt.get($t);this.statContext.deviceId?this.deviceId=this.statContext.deviceId:i?this.deviceId=i:(this.deviceId=Re(),Lt.set($t,this.deviceId)),this.statContext.targetDuration?this.targetDuration=this.statContext.targetDuration:this.targetDuration=this.config.watchedNDefaultTargetDuration,this.resetViewSession(),o.useIsid&&this.isid$.next(o.isid??Ct());let n=new re({error$:t,config:this.config,timeSynchronisation:this.timeSynchronisation});this.api=new ie({config:this.config,apiTransport:n,error$:t,deviceId:this.deviceId,refreshAuthToken:o.refreshAuthToken}),this.logger=new ne({config:this.config,debugLogger:this.debugLogger,api:this.api,error$:t,userSalt:o.userSalt});let{isEmbed:d,topOrigin:l}=Li();this.isEmbed=d,this.embedHostname=l?new URL(l).hostname:void 0}get vsid$(){return new Be(R.getVSID())}authorize(e){return this.api.authorize(e)}updateContext(e){this.statContext={...this.statContext,...e}}attachTo(e,o){let t=new Ue,i=(r,s)=>t.add(r.subscribe(s));i(At(e),r=>{this.getTotalViewTime=r}),i(e.info.isLive$,r=>this.isLive=r);let n;i(le({hostname:e.info.hostname$,connectionType:e.info.httpConnectionType$,connectionReused:e.info.httpConnectionReused$}).pipe(k(({hostname:r})=>r!==void 0),k(({connectionType:r})=>r!==void 0),k(({connectionReused:r})=>r!==void 0)),({hostname:r,connectionType:s,connectionReused:c})=>{if(n!==void 0&&n!==r){let g={cdn_host:r,connection_type:Oe(s),connection_reused:c,content_type:j(e.info.currentFormat$.getValue())};this.logFailover(g)}this.cdnHostname=n=r}),i(e.info.httpConnectionType$,r=>{this.connectionType=Oe(r)}),i(e.info.httpConnectionReused$,r=>{this.connectionReused=r}),i(_t(e,o,{heartbeatInterval:this.config.watchCoverageHeartbeatInterval}),r=>{let s=Math.round(r.from*1e3),c=Math.round(r.to*1e3),u={watch_interval:`${s}-${c}`,in_history:!!this.statContext.inHistory,content_type:j(e.info.currentFormat$.getValue()),playback_quality:x(e.info.currentQuality$.getValue()),recom_info:this.statContext.recomInfo};if(!e.info.isLive$.getValue())this.logWatchCoverage(u);else{let m=e.info.atLiveEdge$.getValue();this.logWatchCoverageLive({...u,live:!!m})}}),i(Pt(e,{targetDuration:this.targetDuration,firstTvtLog:this.config.watchedNFirstTvtLog,getTotalViewTime:this.getTotalViewTime}),r=>{this.logWatchedN(r)}),i(e.events.willReady$,()=>{if(this.statContext.preload){let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentBuffer$.getValue(),u=e.info.currentQuality$.getValue(),g={target_buffer_time:this.calcBufferTime(c),playback_url:M(r,s,u),playback_quality:x(u)};this.logPreloadStarted(g)}}),i(e.events.manifestRequested$,()=>{let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentQuality$.getValue(),u={playback_url:M(r,s,c),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logManifestRequest(u)}),i(e.events.firstBytesManifest$,()=>{let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentQuality$.getValue(),u={playback_url:M(r,s,c),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstByteManifest(u)}),i(e.events.manifestReceived$,()=>{let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentQuality$.getValue(),u={playback_url:M(r,s,c),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logManifestReceived(u)}),i(e.events.firstBytesRequested$,()=>{let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentQuality$.getValue(),u={playback_url:M(r,s,c),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstMediaRequest(u)}),i(e.events.firstBytesReceived$,()=>{let r=e.info.currentFormat$.getValue(),s=e.info.availableSources$.getValue(),c=e.info.currentQuality$.getValue(),u={playback_url:M(r,s,c),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logFirstByteMedia(u)}),i(Ve(e.events.willStart$,e.events.looped$),r=>{r&&this.resetViewSession();let c={isid:this.isid$.getValue(),stream_profile:kt(j(e.info.currentFormat$.getValue())),dpi:96*L.display.pixelRatio,web_layout:this.statContext.isMobile||L.device.isMobile?"mobile":"desktop",preloaded:this.statContext.preload,navigation:this.statContext.navigation,recom_info:this.statContext.recomInfo};this.isEmbed&&(c.iframe_host=this.embedHostname??"unknown"),this.logStartSession(c)}),i(e.events.started$,()=>{this.isStarted=!0;let r=e.info.currentBuffer$.getValue(),s=e.info.currentQuality$.getValue(),c=e.info.isAutoQualityEnabled$.getValue(),u=e.info.muted$.getValue(),g=e.info.volume$.getValue(),m=e.info.surface$.getValue(),b=e.info.availableTextTracks$.getValue(),T=e.info.currentTextTrack$.getValue(),E=e.info.currentAudioStream$.getValue(),S=e.info.currentPlaybackRate$.getValue(),v={playback_quality:x(s),user_quality:c?"auto":x(s),player_width:this.playerSize.width,player_height:this.playerSize.height,muted:u,sound_volume:Math.round(g*100),buffer_time:this.calcBufferTime(r),mode:de(m,this.statContext.isPreviewPlayerView),visibility:ce(m),subtitles_enabled:T?!!T:this.currentSubtitle?.enabled,auto_subtitles:b.find(({id:_})=>_===T)?.isAuto??this.currentSubtitle?.auto,audio_track_lang:E?.language,playback_rate:S,recom_info:this.statContext.recomInfo};this.logPlaybackStarted(v)}),i(Ve(e.events.willStart$,e.events.willResume$),()=>{this.logPlay()}),i(e.events.playing$,()=>{let r=e.info.currentBuffer$.getValue(),s={buffer_time:this.calcBufferTime(r)};this.logPlaying(s),this.wasPaused&&this.logResume()}),i(e.events.paused$,()=>{this.wasPaused=!0,this.logPause()}),i(e.events.willStop$,()=>{this.logStop()}),i(Ve(e.events.fetcherRecoverableError$,e.events.fatalError$),()=>{this.statContext.preload&&this.logPreloadError()});let d=r=>{switch(r){case U.NETWORK:return"network";case U.VIDEO_PIPELINE:return"video_pipeline";case U.EXTERNAL_API:return"external_api";case U.PARSER:return"parser";case U.DOM:return"dom";default:return"wtf"}},l=r=>U.FATAL===r?"critical":"informative";i(e.events.fetcherRecoverableError$,({id:r,category:s,data:c,message:u,httpCode:g,UVBackendErrorCode:m})=>{let b={error_severity:l(s),error_category:d(s),player_error_code:r,player_error_trace:c,http_error_code:g,uv_backend_error_code_subcode:m,error_message:u};this.logError(b)}),i(e.events.managedError$,({id:r,category:s,data:c,message:u})=>{let g={error_severity:l(s),error_category:d(s),player_error_code:r,player_error_trace:c,error_message:u};this.logError(g)}),i(e.events.fatalError$,({id:r,category:s,data:c,message:u})=>{let g={error_severity:"critical",error_category:d(s),player_error_code:r,player_error_trace:c,error_message:u};this.logError(g)}),i(le({connectionType:e.info.httpConnectionType$,connectionReused:e.info.httpConnectionReused$,connectionMetrics:e.info.httpConnectionMetrics$}).pipe(k(({connectionReused:r})=>r!==void 0),k(({connectionMetrics:r})=>r!==void 0),Ri((r,s)=>r.connectionType===s.connectionType)),({connectionMetrics:r})=>{let s=e.info.currentFormat$.getValue(),c=e.info.availableSources$.getValue(),u=e.info.currentQuality$.getValue(),g=e.info.rttEstimation$.getValue(),m={playback_url:M(s,c,u),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused,rtt:g?Math.round(g):void 0,network_type:r?.networkType,dns_resolve_time:r?.dnsResolveTime,tcp_handshake_time:r?.tcpHandshakeTime,tls_handshake_time:r?.tlsHandshakeTime};this.logConnectionEstablished(m)}),i(Et(e),r=>{this.logDownloadBytes(r)}),i(e.events.firstFrame$,()=>{this.logFirstVideoFrameDecoded()}),i(e.events.willSeek$,()=>{let r={seek_type:this.seekAction$.getValue()};this.logSeeking(r)}),i(e.events.seeked$,()=>{let r={seek_type:this.seekAction$.getValue()};this.logSeeked(r),this.seekAction$.next("unknown")}),i(e.info.isStalled$,r=>{let s=e.info.currentBuffer$.getValue(),c=this.calcBufferTime(s);r&&c&&c>0&&this.logBufferStarvation({buffer_time:c})}),i(e.info.currentBuffer$.pipe(k(r=>!!this.calcBufferTime(r)),Mi()),r=>{let s=this.calcBufferTime(r);if(this.statContext.preload){let c={buffer_time:s};this.logPreloadEnded(c)}this.logReady({buffer_time:s})});let h;i(le({videoStream:e.info.currentVideoStream$,audioStream:e.info.currentAudioStream$,quality:e.info.currentQuality$}).pipe(k(({videoStream:r,audioStream:s})=>r!==void 0&&s!==void 0),k(({quality:r})=>r!==void 0)),({videoStream:r,audioStream:s,quality:c})=>{if(h!==c){let u=e.info.isAutoQualityEnabled$.getValue(),g=r?.codec,m=s?.codec,b={user_quality:u?"auto":x(c),playback_quality:x(c),download_quality:x(c),codec_info:g&&m?`${g},${m}`:void 0};h=c,this.logQualityChanged(b)}});let p,f;return i(e.info.surface$,r=>{let s=de(r,this.statContext.isPreviewPlayerView);s&&!this.uiEvents&&this.isStarted&&this.logModeChanged({mode:s}),f=ce(r),p!==f&&this.isStarted&&(p=ce(r),this.logVisibilityChanged({visibility:f}))}),i(le({muted:e.info.muted$,volume:e.info.volume$}),({muted:r,volume:s})=>{if(this.isStarted){let c={muted:r,sound_volume:Math.round(s*100)};this.logSoundChanged(c)}}),i(e.info.currentFormat$.pipe(k(r=>r!==void 0),Fe(1)),r=>{let s={content_type:j(r),cdn_host:this.cdnHostname,connection_type:this.connectionType,connection_reused:this.connectionReused};this.logContentTypeChange(s)}),i(e.info.currentAudioStream$.pipe(k(r=>r!==void 0),Fe(1)),r=>{let s={audio_track_lang:r.language,codec_info:r.codec};this.logAudioTrackSwitched(s)}),i(e.info.currentVideoStream$.pipe(k(r=>r!==void 0),Fe(1)),r=>{let s={hdr:r.hdr,codec_info:r.codec};this.logVideoTrackSwitched(s)}),this.player=e,this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToUi(e){this.uiEvents=e;let{subscribe:o,subscription:t}=Dt();o(e.actionSeek$,this.seekAction$),o(e.playerSize$,({width:n,height:d})=>{n&&d&&(this.playerSize={width:n,height:d},this.logViewPortChanged({player_width:n,player_height:d}))}),o(e.isLoaderVisible$,n=>{n&&this.isStarted&&this.logShowLoader()}),o(e.actionSubtitlesSwitched$,n=>{if(this.currentSubtitle={...n},this.isStarted){let d={subtitles_enabled:n.enabled,subtitles_track_lang:n.lang,auto_subtitles:n.auto};this.logSubtitlesSwitched(d)}});let{surface$:i}=Z(this.uiEvents,o,this.player);return o(i,n=>{this.isStarted&&this.logModeChanged({mode:de(n)})}),o(e.actionQuality$,n=>{let d=f=>Object.values(Ce).includes(f),l=this.player?.info.currentVideoStream$.getValue()?.codec,h=this.player?.info.currentAudioStream$.getValue()?.codec,p={user_quality:d(n)?"auto":x(n),playback_quality:x(this.player?.info.currentQuality$.getValue()),download_quality:x(this.player?.info.currentQuality$.getValue()),codec_info:l&&h?`${l},${h}`:void 0};this.logQualityChangeRequested(p)}),this.resubscribeBeforeunload(),this.subscription.add(t),t}attachToAds(e){let{subscription:o,subscribe:t}=Dt();return t(e.init$,i=>{let n={slot:i};this.logAdvConfiguration(n)}),t(e.slotRequested$,()=>{this.logAdvRequest()}),t(e.started$,i=>{let n={adv_section:i};this.logAdvBreakStarted(n)}),t(e.ended$,i=>{let n={adv_section:i};this.logAdvBreakEnded(n)}),t(e.error$,i=>{let n={error_message:i};this.logAdvError(n)}),this.resubscribeBeforeunload(),this.subscription.add(o),o}getDeviceId(){return this.deviceId}resetViewSession(){this.thinOneStatDebugLog({message:"VSID reset"}),R.generateVSID(),this.eventNumber=0}destroy(){this.api.destroy()}calcBufferTime(e){return e?Math.round((e.end??0)-(e.start??0))*1e3:void 0}createRequiredParams(e){let o=this.vsid$.getValue();Ci(o);let t=this.eventNumber++,i=((this.isLive?this.player?.info.liveTime$.getValue():this.player?.info.position$.getValue())??0)*1e3;return{vsid:o,uv_movie_id:this.statContext.movieId,event_name:e,client_time:Date.now(),application:this.statContext.application??`@vkontakte/videoplayer-statistics:${P}`,platform:this.statContext.platform??`web:${this.statContext.isMobile||L.device.isMobile?"mobile":"desktop"}`,product:this.statContext.product,event_number:t,playback_position:i,current_tvt:this.getTotalViewTime(),cdn_host:this.cdnHostname}}createRequiredFatParams(){return{stats_version:"2.1.1",browser:this.statContext.browser??L.browser.current,browser_version:this.statContext.browserVersion??String(L.browser.currentVersion),os:this.statContext.os??L.device.os.name,os_version:this.statContext.osVersion??L.device.os.version,device_type:this.statContext.deviceType??(this.statContext.isMobile||L.device.isMobile?"mobile":"desktop"),device_manufacturer:this.statContext.deviceManufacturer??L.device.details.vendor,device_model:this.statContext.deviceModel??L.device.details.model,navigation:this.statContext.navigation}}log(e,o,t=!1){let i=this.createRequiredParams(e),n={};t&&(n=this.createRequiredFatParams()),this.logger.log({...i,...n,...o})}logWatchCoverage(e){this.log("watch_coverage",e,!0)}logWatchCoverageLive(e){this.log("watch_coverage_live",e,!0)}logWatchedN(e){this.log("watched_n",e,!0)}logStartSession(e){this.log("start_session",e,!0)}logPreloadStarted(e){this.log("preload_started",e)}logPreloadEnded(e){this.log("preload_ended",e)}logPreloadError(){this.log("preload_error")}logPlaybackStarted(e){this.log("playback_started",e,!0)}logPlay(){this.log("play")}logManifestRequest(e){this.log("manifest_request",e)}logFirstByteManifest(e){this.log("first_byte_manifest",e)}logFirstMediaRequest(e){this.log("first_media_request",e)}logFirstByteMedia(e){this.log("first_byte_media",e)}logManifestReceived(e){this.log("manifest_received",e)}logConnectionEstablished(e){this.log("connection_established",e)}logFirstVideoFrameDecoded(){this.log("first_video_frame_decoded")}logReady(e){this.log("ready",e)}logPlaying(e){this.log("playing",e)}logPause(){this.log("pause")}logResume(){this.log("resume")}logSeeking(e){this.log("seeking",e)}logSeeked(e){this.log("seeked",e)}logStop(){this.log("stop")}logBufferStarvation(e){this.log("buffer_starvation",e)}logShowLoader(){this.log("show_loader")}logQualityChangeRequested(e){this.log("quality_change_requested",e)}logQualityChanged(e){this.log("quality_changed",e)}logCdnHostChanged(e){this.log("cdn_host_changed",e)}logViewPortChanged(e){this.log("view_port_changed",e)}logModeChanged(e){this.log("mode_changed",e)}logVisibilityChanged(e){this.log("visibility_changed",e)}logAudioTrackSwitched(e){this.log("audio_track_switched",e)}logVideoTrackSwitched(e){this.log("video_track_switched",e)}logSubtitlesSwitched(e){this.log("subtitles_switched",e)}logSoundChanged(e){this.log("sound_changed",e)}logFailover(e){this.log("failover",e)}logContentTypeChange(e){this.log("content_type_change",e)}logError(e){this.log("error",e,!0)}logDownloadBytes(e){this.log("download_bytes",e)}logAdvConfiguration(e){this.log("adv_configuration",e)}logAdvRequest(){this.log("adv_request")}logAdvBreakStarted(e){this.log("adv_break_started",e)}logAdvBreakEnded(e){this.log("adv_break_ended",e)}logAdvError(e){this.log("adv_error",e)}resubscribeBeforeunload(){this.beforeunloadSubscription?.unsubscribe(),this.beforeunloadSubscription=$i(Ni(),"beforeunload").subscribe(()=>{}),this.subscription.add(this.beforeunloadSubscription)}};var Fi={};import{PlaybackState as Nt,Subscription as Bi}from"@vkontakte/videoplayer-core/evergreen";import{Logger as Ui}from"@vkontakte/videoplayer-shared/evergreen";var he=class{constructor(){this.startTime=null;this.stopTime=null;this.accumulatedTime=0}get time(){return Math.floor(this.timeMs/1e3)}get timeMs(){return this.startTime===null?0:(this.stopTime??this.now())-this.startTime-this.accumulatedTime}get isRunning(){return this.startTime!==null&&this.stopTime===null}start(){this.isRunning||(this.stopTime!==null?(this.accumulatedTime+=this.now()-this.stopTime,this.stopTime=null):this.startTime=this.now())}stop(){this.isRunning&&(this.stopTime=this.now())}reset(){this.startTime=null,this.stopTime=null,this.accumulatedTime=0}now(){return Date.now()}};var Mt=()=>window.Image?new Image:document.createElement("img");var He=class{constructor(e){this.position=0;this.started=!1;this.heartbeatPixels=[];this.heartbeatLastTimeSent={};this.idleCallbackIds=[];this.stopwatch=new he;this.subscription=new Bi;this.params=e;let o=new Ui;this.log=o.createComponentLog("MediascopePixel")}attachTo(e){this.subscription.add(e.info.playbackState$.subscribe(o=>this.onPlaybackState(o))).add(e.info.position$.subscribe(o=>this.onPosition(o))).add(e.info.atLiveEdge$.subscribe(o=>this.isActiveLive=o)),this.subscription.add(e.events.willSeek$.subscribe(()=>this.onWillSeek())).add(e.events.seeked$.subscribe(()=>this.onSeeked())).add(e.events.ended$.subscribe(()=>this.onEnded()))}destroy(){this.stopwatch.reset(),this.subscription.unsubscribe(),window.clearTimeout(this.heartbeatFirstTimeoutId),this.idleCallbackIds.forEach(e=>window.cancelIdleCallback(e)),this.send("stop")}onPlaybackState(e){e===Nt.PLAYING?this.started?this.play():this.start():e===Nt.PAUSED&&this.pause()}start(){this.started=!0,this.stopwatch.start(),this.send("start"),this.heartbeatPixels=this.prepareHeartbeatPixels(),this.heartbeatInterval=this.heartbeatPixels[0]?.interval;let e=this.heartbeatPixels[0]?.url,o=this.heartbeatPixels[0]?.delay;if(o!==void 0&&e)try{this.heartbeatFirstTimeoutId=window.setTimeout(()=>{this.sendHeartbeat(e)},o*1e3)}catch(t){this.log({message:t.message})}}play(){this.stopwatch.start(),this.send("resume")}pause(){this.stopwatch.stop(),this.send("pause")}onPosition(e){if(this.position=e,this.heartbeatInterval&&this.stopwatch.time!==0&&this.stopwatch.time%this.heartbeatInterval===0)for(let[o,{url:t}]of this.heartbeatPixels.entries())this.heartbeatLastTimeSent[o]!==this.stopwatch.time&&(this.heartbeatLastTimeSent[o]=this.stopwatch.time,this.sendHeartbeat(t))}onWillSeek(){this.started&&this.send("stop")}onSeeked(){this.started&&this.send("start")}onEnded(){this.stopwatch.stop(),this.send("stop")}validatePixels(e,o){return e?.filter(t=>t.event===o.event&&o.keys.every(i=>!!t[i]))}getFrameTimestamp(){let e;if(this.isActiveLive){let o=Math.floor(Math.random()*25)+5;e=Date.now()/1e3-o}else e=this.position||0;return Math.floor(e)}getUTC(){return Math.floor(Date.now()/1e3)}prepareUrl(e){return e.replace("{@fts_fake_sec}",String(this.getFrameTimestamp())).replace("{@utc_sec}",String(this.getUTC())).split("&").filter(o=>!/={@[a-zA-Z_]+}/.test(o)).join("&")}preparePixels(e){return this.validatePixels(this.params.pixels,{event:e,keys:["url"]})}prepareHeartbeatPixels(){return this.validatePixels(this.params.pixels,{event:"heartbeat",keys:["url","interval"]})}call(e){try{this.idleCallbackIds.push(requestIdleCallback(()=>Mt().src=this.prepareUrl(e)))}catch(o){this.log({message:o.message})}}send(e){let o=this.preparePixels(e);for(let{url:t}of o)this.call(t)}sendHeartbeat(e){this.call(e)}};export{H as ApiEnv,me as ConnectionType,ge as ContentType,Qe as InteractiveInterfaceClick,He as MediascopePixel,Fi as MediascopePixelTypes,ke as OneStat,fe as Quality,ve as SeekAction,Rt as ThinOneStat,P as VERSION};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@vkontakte/videoplayer-statistics",
3
- "version": "1.0.95",
3
+ "version": "1.0.96-beta.0",
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
- "main": "./esnext.cjs.js",
8
+ "main": "./esnext.cjs",
9
9
  "module": "./esnext.esm.js",
10
10
  "types": "./types/index.d.ts",
11
11
  "type": "module",
@@ -13,48 +13,48 @@
13
13
  ".": {
14
14
  "types": "./types/index.d.ts",
15
15
  "import": "./esnext.esm.js",
16
- "require": "./esnext.cjs.js"
16
+ "require": "./esnext.cjs"
17
17
  },
18
18
  "./evergreen": {
19
19
  "types": "./types/index.d.ts",
20
20
  "import": "./evergreen.esm.js",
21
- "require": "./evergreen.cjs.js"
21
+ "require": "./evergreen.cjs"
22
22
  },
23
23
  "./esnext": {
24
24
  "types": "./types/index.d.ts",
25
25
  "import": "./esnext.esm.js",
26
- "require": "./esnext.cjs.js"
26
+ "require": "./esnext.cjs"
27
27
  },
28
28
  "./es2024": {
29
29
  "types": "./types/index.d.ts",
30
30
  "import": "./es2024.esm.js",
31
- "require": "./es2024.cjs.js"
31
+ "require": "./es2024.cjs"
32
32
  },
33
33
  "./es2018": {
34
34
  "types": "./types/index.d.ts",
35
35
  "import": "./es2018.esm.js",
36
- "require": "./es2018.cjs.js"
36
+ "require": "./es2018.cjs"
37
37
  },
38
38
  "./es2015": {
39
39
  "types": "./types/index.d.ts",
40
40
  "import": "./es2015.esm.js",
41
- "require": "./es2015.cjs.js"
41
+ "require": "./es2015.cjs"
42
42
  },
43
43
  "./evergreen.esm.js": "./evergeen.esm.js",
44
44
  "./esnext.esm.js": "./esnext.esm.js",
45
- "./esnext.cjs.js": "./esnext.cjs.js",
45
+ "./esnext.cjs": "./esnext.cjs",
46
46
  "./es2018.esm.js": "./es2018.esm.js",
47
- "./es2018.cjs.js": "./es2018.cjs.js",
47
+ "./es2018.cjs": "./es2018.cjs",
48
48
  "./es2015.esm.js": "./es2015.esm.js",
49
- "./es2015.cjs.js": "./es2015.cjs.js"
49
+ "./es2015.cjs": "./es2015.cjs"
50
50
  },
51
51
  "files": [
52
- "*.cjs.js",
52
+ "*.cjs",
53
53
  "*.esm.js",
54
54
  "**/*.d.ts"
55
55
  ],
56
56
  "dependencies": {
57
- "@vkontakte/videoplayer-core": "2.0.149",
58
- "@vkontakte/videoplayer-shared": "1.0.78"
57
+ "@vkontakte/videoplayer-core": "2.0.150-beta.0",
58
+ "@vkontakte/videoplayer-shared": "1.0.79-beta.0"
59
59
  }
60
60
  }
@@ -1,4 +1,4 @@
1
- import { ISubscription, IValueObservable, Milliseconds } from '@vkontakte/videoplayer-shared';
1
+ import type { ISubscription, IValueObservable, Milliseconds } from '@vkontakte/videoplayer-shared';
2
2
  import { ValueSubject } from '@vkontakte/videoplayer-shared';
3
3
  import type { IPlayer } from '@vkontakte/videoplayer-core';
4
4
  import type { IOptionalConfig } from './config';
@@ -150,6 +150,10 @@ export interface IConnectionEstablishedPayload {
150
150
  connection_type?: ConnectionType;
151
151
  connection_reused?: boolean;
152
152
  rtt?: Milliseconds;
153
+ network_type?: string;
154
+ dns_resolve_time?: number;
155
+ tcp_handshake_time?: number;
156
+ tls_handshake_time?: number;
153
157
  }
154
158
  export interface IReadyPayload {
155
159
  buffer_time?: Milliseconds;
@@ -194,6 +198,14 @@ export interface IModeChangedPayload {
194
198
  export interface IVisibilityChangedPayload {
195
199
  visibility?: Visibility;
196
200
  }
201
+ export interface IAudioTrackSwitchedPayload {
202
+ audio_track_lang?: string;
203
+ codec_info?: string;
204
+ }
205
+ export interface IVideoTrackSwitchedPayload {
206
+ hdr?: boolean;
207
+ codec_info?: string;
208
+ }
197
209
  export interface ISubtitlesSwitchedPayload {
198
210
  subtitles_enabled?: boolean;
199
211
  subtitles_track_lang?: string;
@@ -209,6 +221,26 @@ export interface IFailoverPayload {
209
221
  connection_reused?: boolean;
210
222
  content_type?: ContentType;
211
223
  }
224
+ export interface IContentTypeChangePayload {
225
+ content_type?: ContentType;
226
+ cdn_host?: string;
227
+ connection_type?: ConnectionType;
228
+ connection_reused?: boolean;
229
+ }
230
+ export interface IErrorPayload {
231
+ error_severity?: 'informative' | 'critical';
232
+ error_category?: 'network' | 'video_pipeline' | 'external_api' | 'parser' | 'dom' | 'wtf' | // контентные
233
+ 'sdk_init' | 'playback' | 'timeout' | 'other';
234
+ player_error_code?: string;
235
+ player_error_trace?: string;
236
+ http_error_code?: number;
237
+ uv_backend_error_code_subcode?: string;
238
+ error_message?: string;
239
+ }
240
+ export interface IDownloadBytes {
241
+ download_bytes?: number;
242
+ download_speed?: number;
243
+ }
212
244
  export interface IAdvConfigurationPayload {
213
245
  slot?: number;
214
246
  }
@@ -295,9 +327,14 @@ export declare class ThinOneStat implements IThinOneStat {
295
327
  private logViewPortChanged;
296
328
  private logModeChanged;
297
329
  private logVisibilityChanged;
330
+ private logAudioTrackSwitched;
331
+ private logVideoTrackSwitched;
298
332
  private logSubtitlesSwitched;
299
333
  private logSoundChanged;
300
334
  private logFailover;
335
+ private logContentTypeChange;
336
+ private logError;
337
+ private logDownloadBytes;
301
338
  private logAdvConfiguration;
302
339
  private logAdvRequest;
303
340
  private logAdvBreakStarted;
@@ -0,0 +1,4 @@
1
+ import type { IPlayer } from '@vkontakte/videoplayer-core';
2
+ import type { IObservable } from '@vkontakte/videoplayer-shared';
3
+ import { IDownloadBytes } from '../ThinOneStat';
4
+ export declare const downloadBytes: (player: IPlayer) => IObservable<IDownloadBytes>;
@@ -1,9 +1,9 @@
1
1
  import type { IPlayer } from '@vkontakte/videoplayer-core';
2
- import type { IObservable, Milliseconds, Seconds } from '@vkontakte/videoplayer-shared';
2
+ import type { IObservable, Milliseconds } from '@vkontakte/videoplayer-shared';
3
3
  import { IWatchedNPayload } from '../ThinOneStat';
4
4
  export type IParams = {
5
5
  targetDuration: Milliseconds;
6
6
  firstTvtLog: Milliseconds;
7
- getTotalViewTime: () => Seconds;
7
+ getTotalViewTime: () => Milliseconds;
8
8
  };
9
9
  export declare const watchedN: (player: IPlayer, params: IParams) => IObservable<IWatchedNPayload>;
@@ -1,5 +1,5 @@
1
1
  import type { VideoQuality } from '@vkontakte/videoplayer-shared';
2
- export type EventName = 'watch_coverage' | 'watch_coverage_live' | 'watched_n' | 'start_session' | 'preload_started' | 'preload_ended' | 'preload_error' | 'playback_started' | 'play' | 'manifest_request' | 'first_media_request' | 'first_byte_manifest' | 'first_byte_media' | 'manifest_received' | 'connection_established' | 'first_video_frame_decoded' | 'ready' | 'playing' | 'pause' | 'resume' | 'seeking' | 'seeked' | 'stop' | 'buffer_starvation' | 'show_loader' | 'quality_change_requested' | 'quality_changed' | 'cdn_host_changed' | 'view_port_changed' | 'mode_changed' | 'visibility_changed' | 'subtitles_switched' | 'sound_changed' | 'failover' | 'adv_configuration' | 'adv_request' | 'adv_break_started' | 'adv_break_ended' | 'adv_error';
2
+ export type EventName = 'watch_coverage' | 'watch_coverage_live' | 'watched_n' | 'start_session' | 'preload_started' | 'preload_ended' | 'preload_error' | 'playback_started' | 'play' | 'manifest_request' | 'first_media_request' | 'first_byte_manifest' | 'first_byte_media' | 'manifest_received' | 'connection_established' | 'first_video_frame_decoded' | 'ready' | 'playing' | 'pause' | 'resume' | 'seeking' | 'seeked' | 'stop' | 'buffer_starvation' | 'show_loader' | 'quality_change_requested' | 'quality_changed' | 'cdn_host_changed' | 'view_port_changed' | 'mode_changed' | 'visibility_changed' | 'audio_track_switched' | 'video_track_switched' | 'subtitles_switched' | 'sound_changed' | 'failover' | 'content_type_change' | 'error' | 'download_bytes' | 'adv_configuration' | 'adv_request' | 'adv_break_started' | 'adv_break_ended' | 'adv_error';
3
3
  export declare enum ApiEnv {
4
4
  PROD = "prod",
5
5
  VK_ALIAS = "vk_alias",