@vkontakte/videoplayer-statistics 1.0.96-beta.0 → 1.0.96-dev.0b96aed5.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/es2015.cjs +3 -3
- package/es2015.esm.js +3 -3
- package/es2018.cjs +3 -3
- package/es2018.esm.js +3 -3
- package/es2024.cjs +3 -3
- package/es2024.esm.js +3 -3
- package/esnext.cjs +3 -3
- package/esnext.esm.js +3 -3
- package/evergreen.esm.js +3 -3
- package/package.json +3 -3
package/evergreen.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-statistics v1.0.96-
|
|
3
|
-
*
|
|
2
|
+
* @vkontakte/videoplayer-statistics v1.0.96-dev.0b96aed5.0
|
|
3
|
+
* Tue, 27 Jan 2026 06:11:29 GMT
|
|
4
4
|
* https://st.mycdn.me/static/vkontakte-videoplayer/1-0-96/doc/
|
|
5
5
|
*/
|
|
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};
|
|
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-dev.0b96aed5.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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vkontakte/videoplayer-statistics",
|
|
3
|
-
"version": "1.0.96-
|
|
3
|
+
"version": "1.0.96-dev.0b96aed5.0",
|
|
4
4
|
"author": "vk.com",
|
|
5
5
|
"description": "Statistics library for vk.com videoplayer",
|
|
6
6
|
"homepage": "https://vk.com",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"**/*.d.ts"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@vkontakte/videoplayer-core": "2.0.150-
|
|
58
|
-
"@vkontakte/videoplayer-shared": "1.0.79-
|
|
57
|
+
"@vkontakte/videoplayer-core": "2.0.150-dev.0b96aed5.0",
|
|
58
|
+
"@vkontakte/videoplayer-shared": "1.0.79-dev.0b96aed5.0"
|
|
59
59
|
}
|
|
60
60
|
}
|