@odnoklassniki/player-one-stat
Advanced tools
Comparing version 0.0.2 to 0.0.3-dev.4590f59.0
/** | ||
* @odnoklassniki/player-one-stat v0.0.2 | ||
* Tue, 08 Jun 2021 17:23:29 GMT | ||
* @odnoklassniki/player-one-stat v0.0.3-dev.4590f59.0 | ||
* Tue, 22 Jun 2021 18:30:28 GMT | ||
*/ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("lodash.debounce")),r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var i=function(){try{var t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);var r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}}();var a=function(t){return function(t){var e=i?i.getItem("_one-stat_"+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null},s=function(t,e){!function(t,e){try{i&&i.setItem("_one-stat_"+t,JSON.stringify(e))}catch(t){}}(t,e)};var u;!function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE"}(u||(u={}));var c=function(){function t(t){this.apiTransport=t.apiTransport;var e=a("uuid");e?this.uuid=String(e):(this.uuid=function(){var t,e,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=new Array(36),o=0;for(e=0;e<36;e++)8===e||13===e||18===e||23===e?n[e]="-":14===e?n[e]="4":(o<=2&&(o=33554432+16777216*Math.random()|0),t=15&o,o>>=4,n[e]=r[19===e?3&t|8:t]);return n.join("")}(),s("uuid",this.uuid))}return t.prototype.authorize=function(){return n(this,void 0,void 0,(function(){var t,e=this;return o(this,(function(r){return this.authorizePromise||(this.sessionKey=void 0,"auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:"0.0.2",client_type:"SDK_JS"}},this.authorizePromise=this.apiTransport.sendRequest("auth.anonymLogin",t).then((function(t){return t.session_key})).catch((function(t){console.error(t)})).then((function(t){return e.authorizePromise=void 0,e.sessionKey=t,t}))),[2,this.authorizePromise]}))}))},t.prototype.logBeacon=function(t){var e="log.externalLog",r=this.createLogParams(t),n=this.sessionKey;void 0!==n&&this.apiTransport.sendBeacon(e,r,n)||this.apiTransport.sendRequest(e,r,n)},t.prototype.logRequest=function(t){var e,r;return n(this,void 0,void 0,(function(){var n,i,a,s,c,p;return o(this,(function(o){switch(o.label){case 0:return n="log.externalLog",i=this.createLogParams(t),null===(e=this.sessionKey)||void 0===e?[3,1]:(s=e,[3,3]);case 1:return[4,this.authorize()];case 2:s=o.sent(),o.label=3;case 3:a=s,o.label=4;case 4:return o.trys.push([4,6,,11]),[4,this.apiTransport.sendRequest(n,i,a)];case 5:return[2,o.sent()];case 6:switch(c=o.sent(),null===(r=c)||void 0===r?void 0:r.error_code){case u.PARAM_SESSION_EXPIRED:case u.PARAM_SESSION_KEY:case u.PARAM_SIGNATURE:return[3,7]}return[3,9];case 7:return[4,this.authorize()];case 8:return p=o.sent(),[2,this.apiTransport.sendRequest(n,i,p)];case 9:throw c;case 10:return[3,11];case 11:return[2]}}))}))},t.prototype.createLogParams=function(t){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:"@odnoklassniki/player-one-stat:0.0.2",platform:"WEB",items:t.map((function(t){return r(r({},t),{time:0,type:1})}))})}},t}(),p=function(){function t(t){this.apiKey=t.apiKey,this.apiBaseUrl=t.apiBaseUrl,"/"!==this.apiBaseUrl[this.apiBaseUrl.length-1]&&(this.apiBaseUrl+="/")}return t.prototype.sendBeacon=function(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;var n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:"application/x-www-form-urlencoded"});return window.navigator.sendBeacon(this.apiBaseUrl+"fb.do",o)},t.prototype.sendRequest=function(t,e,r){return n(this,void 0,void 0,(function(){return o(this,(function(n){return[2,fetch(this.apiBaseUrl+"fb.do",{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:r})}).then((function(t){return Number(t.headers.get("content-length"))>0?t.json().then((function(t){return Object.prototype.hasOwnProperty.call(t,"error_msg")?Promise.reject(t):t})):void 0}))]}))}))},t.prototype._prepareQueryParams=function(t){var e=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach((function(t){var r=t[0],n=t[1];return e.append(r,"string"==typeof n?n:JSON.stringify(n))})),e},t}(),l=function(){function t(t){var r=this;this.requestQueue=[],this.debouncedFlush=e.default((function(){return r.flush()}),3e3,{maxWait:15e3}),this.api=t.api}return t.prototype.log=function(t){this.requestQueue.push(t),this.debouncedFlush()},t.prototype.flush=function(t){void 0===t&&(t=!1),t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[],this.debouncedFlush.cancel()},t}(),h=function(){function t(t){var e=this;this.statContext=t;var r=new p({apiKey:"CIOPGQJGDIHBABABA",apiBaseUrl:"https://apitest.ok.ru/api/"}),n=new c({apiTransport:r});this.logger=new l({api:n}),n.authorize(),window.addEventListener("beforeunload",(function(){return e.logger.flush(!0)}))}return t.prototype.logStarted=function(){this.log({operation:"play"})},t.prototype.logPlay=function(){this.log({operation:"play_toggle"})},t.prototype.logPause=function(t){this.log({operation:"pause",param:String(t.position)})},t.prototype.logSeek=function(){this.log({operation:"seek"})},t.prototype.logFirstBytes=function(t){this.log({operation:"firstBytes",param:String(t.time)})},t.prototype.logFirstFrame=function(t){this.log({operation:"firstFrame",param:String(t.time)})},t.prototype.logError=function(t){this.log({operation:"error",param:t.errorType})},t.prototype.logWatchCoverageRecord=function(t){this.log({operation:"watch_coverage_record",param:t.start+"-"+t.end})},t.prototype.log=function(t){var e=this.crateLogItem(t);this.logger.log(e)},t.prototype.crateLogItem=function(t){var e=t.operation,r=t.param,n=Date.now(),o={vid:this.statContext.movieId};return void 0!==r&&(o.param=r),{operation:e,timestamp:n,custom:o}},t}();exports.OneStat=h; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("lodash.debounce")),r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var i=function(){try{var t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);var r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}}();var a=function(t){return function(t){var e=i?i.getItem("_one-stat_"+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null},s=function(t,e){!function(t,e){try{i&&i.setItem("_one-stat_"+t,JSON.stringify(e))}catch(t){}}(t,e)};var u;!function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"}(u||(u={}));var c=function(){function t(t){this.apiTransport=t.apiTransport;var e=a("uuid");e?this.uuid=String(e):(this.uuid=function(){var t,e,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=new Array(36),o=0;for(e=0;e<36;e++)8===e||13===e||18===e||23===e?n[e]="-":14===e?n[e]="4":(o<=2&&(o=33554432+16777216*Math.random()|0),t=15&o,o>>=4,n[e]=r[19===e?3&t|8:t]);return n.join("")}(),s("uuid",this.uuid))}return t.prototype.authorize=function(t){return this.authToken=t,this._authorize()},t.prototype.logBeacon=function(t){var e="log.externalLog",r=this.createLogParams(t),n=this.sessionKey;void 0!==n&&this.apiTransport.sendBeacon(e,r,n)||this.apiTransport.sendRequest(e,r,n)},t.prototype.logRequest=function(t){var e,r;return n(this,void 0,void 0,(function(){var n,i,a,s,c,p;return o(this,(function(o){switch(o.label){case 0:return n="log.externalLog",i=this.createLogParams(t),null===(e=this.sessionKey)||void 0===e?[3,1]:(s=e,[3,3]);case 1:return[4,this._authorize()];case 2:s=o.sent(),o.label=3;case 3:a=s,o.label=4;case 4:return o.trys.push([4,6,,12]),[4,this.apiTransport.sendRequest(n,i,a)];case 5:return[2,o.sent()];case 6:switch(c=o.sent(),null===(r=c)||void 0===r?void 0:r.error_code){case u.PARAM_SESSION_EXPIRED:case u.PARAM_SESSION_KEY:case u.PARAM_SIGNATURE:return[3,7];case u.AUTH_LOGIN:return[3,9]}return[3,10];case 7:return[4,this._authorize()];case 8:return p=o.sent(),[2,this.apiTransport.sendRequest(n,i,p)];case 9:throw new Error("authToken");case 10:throw c;case 11:return[3,12];case 12:return[2]}}))}))},t.prototype.createLogParams=function(t){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:"@odnoklassniki/player-one-stat:0.0.3-dev.4590f59.0",platform:"WEB",items:t.map((function(t){return r(r({},t),{time:0,type:1})}))})}},t.prototype._authorize=function(){return n(this,void 0,void 0,(function(){var t,e=this;return o(this,(function(r){return this.authorizePromise||(this.sessionKey=void 0,"auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_type:"SDK_JS"}},void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=this.apiTransport.sendRequest("auth.anonymLogin",t).then((function(t){return t.session_key})).catch((function(t){console.error(t)})).then((function(t){return e.authorizePromise=void 0,e.sessionKey=t,t}))),[2,this.authorizePromise]}))}))},t}(),p=function(){function t(t){this.apiKey=t.apiKey,this.apiBaseUrl=t.apiBaseUrl,"/"!==this.apiBaseUrl[this.apiBaseUrl.length-1]&&(this.apiBaseUrl+="/")}return t.prototype.sendBeacon=function(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;var n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:"application/x-www-form-urlencoded"});return window.navigator.sendBeacon(this.apiBaseUrl+"fb.do",o)},t.prototype.sendRequest=function(t,e,r){return n(this,void 0,void 0,(function(){return o(this,(function(n){return[2,fetch(this.apiBaseUrl+"fb.do",{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:r})}).then((function(t){return Number(t.headers.get("content-length"))>0?t.json().then((function(t){return Object.prototype.hasOwnProperty.call(t,"error_msg")?Promise.reject(t):t})):void 0}))]}))}))},t.prototype._prepareQueryParams=function(t){var e=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach((function(t){var r=t[0],n=t[1];return e.append(r,"string"==typeof n?n:JSON.stringify(n))})),e},t}(),h=function(){function t(t){var r=this;this.requestQueue=[],this.debouncedFlush=e.default((function(){return r.flush()}),3e3,{maxWait:15e3}),this.api=t.api}return t.prototype.log=function(t){this.requestQueue.push(t),this.debouncedFlush()},t.prototype.flush=function(t){void 0===t&&(t=!1),t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[],this.debouncedFlush.cancel()},t}(),l=function(){function t(t){var e=this;this.statContext=t;var r=new p({apiKey:"CIOPGQJGDIHBABABA",apiBaseUrl:"https://api.ok.ru"});this.api=new c({apiTransport:r}),this.logger=new h({api:this.api}),window.addEventListener("beforeunload",(function(){return e.logger.flush(!0)}))}return t.prototype.authorize=function(t){return this.api.authorize(t)},t.prototype.logStarted=function(){this.log({operation:"play"})},t.prototype.logPlay=function(){this.log({operation:"play_toggle"})},t.prototype.logPause=function(t){this.log({operation:"pause",param:String(t.position)})},t.prototype.logSeek=function(){this.log({operation:"seek"})},t.prototype.logFirstBytes=function(t){this.log({operation:"firstBytes",param:String(t.time)})},t.prototype.logFirstFrame=function(t){this.log({operation:"firstFrame",param:String(t.time)})},t.prototype.logError=function(t){this.log({operation:"error",param:t.errorType})},t.prototype.logWatchCoverageRecord=function(t){this.log({operation:"watch_coverage_record",param:t.start+"-"+t.end})},t.prototype.log=function(t){var e=this.crateLogItem(t);this.logger.log(e)},t.prototype.crateLogItem=function(t){var e=t.operation,r=t.param,n=Date.now(),o={vid:this.statContext.movieId};return void 0!==r&&(o.param=r),{operation:e,timestamp:n,custom:o}},t}();exports.OneStat=l; |
/** | ||
* @odnoklassniki/player-one-stat v0.0.2 | ||
* Tue, 08 Jun 2021 17:23:29 GMT | ||
* @odnoklassniki/player-one-stat v0.0.3-dev.4590f59.0 | ||
* Tue, 22 Jun 2021 18:30:28 GMT | ||
*/ | ||
import t from"lodash.debounce";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var o=function(){try{var t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);var r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}}();var i=function(t){return function(t){var e=o?o.getItem("_one-stat_"+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null},a=function(t,e){!function(t,e){try{o&&o.setItem("_one-stat_"+t,JSON.stringify(e))}catch(t){}}(t,e)};var s;!function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE"}(s||(s={}));var u=function(){function t(t){this.apiTransport=t.apiTransport;var e=i("uuid");e?this.uuid=String(e):(this.uuid=function(){var t,e,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=new Array(36),o=0;for(e=0;e<36;e++)8===e||13===e||18===e||23===e?n[e]="-":14===e?n[e]="4":(o<=2&&(o=33554432+16777216*Math.random()|0),t=15&o,o>>=4,n[e]=r[19===e?3&t|8:t]);return n.join("")}(),a("uuid",this.uuid))}return t.prototype.authorize=function(){return r(this,void 0,void 0,(function(){var t,e=this;return n(this,(function(r){return this.authorizePromise||(this.sessionKey=void 0,"auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_version:"0.0.2",client_type:"SDK_JS"}},this.authorizePromise=this.apiTransport.sendRequest("auth.anonymLogin",t).then((function(t){return t.session_key})).catch((function(t){console.error(t)})).then((function(t){return e.authorizePromise=void 0,e.sessionKey=t,t}))),[2,this.authorizePromise]}))}))},t.prototype.logBeacon=function(t){var e="log.externalLog",r=this.createLogParams(t),n=this.sessionKey;void 0!==n&&this.apiTransport.sendBeacon(e,r,n)||this.apiTransport.sendRequest(e,r,n)},t.prototype.logRequest=function(t){var e,o;return r(this,void 0,void 0,(function(){var r,i,a,u,c,p;return n(this,(function(n){switch(n.label){case 0:return r="log.externalLog",i=this.createLogParams(t),null===(e=this.sessionKey)||void 0===e?[3,1]:(u=e,[3,3]);case 1:return[4,this.authorize()];case 2:u=n.sent(),n.label=3;case 3:a=u,n.label=4;case 4:return n.trys.push([4,6,,11]),[4,this.apiTransport.sendRequest(r,i,a)];case 5:return[2,n.sent()];case 6:switch(c=n.sent(),null===(o=c)||void 0===o?void 0:o.error_code){case s.PARAM_SESSION_EXPIRED:case s.PARAM_SESSION_KEY:case s.PARAM_SIGNATURE:return[3,7]}return[3,9];case 7:return[4,this.authorize()];case 8:return p=n.sent(),[2,this.apiTransport.sendRequest(r,i,p)];case 9:throw c;case 10:return[3,11];case 11:return[2]}}))}))},t.prototype.createLogParams=function(t){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:"@odnoklassniki/player-one-stat:0.0.2",platform:"WEB",items:t.map((function(t){return e(e({},t),{time:0,type:1})}))})}},t}(),c=function(){function t(t){this.apiKey=t.apiKey,this.apiBaseUrl=t.apiBaseUrl,"/"!==this.apiBaseUrl[this.apiBaseUrl.length-1]&&(this.apiBaseUrl+="/")}return t.prototype.sendBeacon=function(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;var n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:"application/x-www-form-urlencoded"});return window.navigator.sendBeacon(this.apiBaseUrl+"fb.do",o)},t.prototype.sendRequest=function(t,e,o){return r(this,void 0,void 0,(function(){return n(this,(function(r){return[2,fetch(this.apiBaseUrl+"fb.do",{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:o})}).then((function(t){return Number(t.headers.get("content-length"))>0?t.json().then((function(t){return Object.prototype.hasOwnProperty.call(t,"error_msg")?Promise.reject(t):t})):void 0}))]}))}))},t.prototype._prepareQueryParams=function(t){var e=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach((function(t){var r=t[0],n=t[1];return e.append(r,"string"==typeof n?n:JSON.stringify(n))})),e},t}(),p=function(){function e(e){var r=this;this.requestQueue=[],this.debouncedFlush=t((function(){return r.flush()}),3e3,{maxWait:15e3}),this.api=e.api}return e.prototype.log=function(t){this.requestQueue.push(t),this.debouncedFlush()},e.prototype.flush=function(t){void 0===t&&(t=!1),t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[],this.debouncedFlush.cancel()},e}(),l=function(){function t(t){var e=this;this.statContext=t;var r=new c({apiKey:"CIOPGQJGDIHBABABA",apiBaseUrl:"https://apitest.ok.ru/api/"}),n=new u({apiTransport:r});this.logger=new p({api:n}),n.authorize(),window.addEventListener("beforeunload",(function(){return e.logger.flush(!0)}))}return t.prototype.logStarted=function(){this.log({operation:"play"})},t.prototype.logPlay=function(){this.log({operation:"play_toggle"})},t.prototype.logPause=function(t){this.log({operation:"pause",param:String(t.position)})},t.prototype.logSeek=function(){this.log({operation:"seek"})},t.prototype.logFirstBytes=function(t){this.log({operation:"firstBytes",param:String(t.time)})},t.prototype.logFirstFrame=function(t){this.log({operation:"firstFrame",param:String(t.time)})},t.prototype.logError=function(t){this.log({operation:"error",param:t.errorType})},t.prototype.logWatchCoverageRecord=function(t){this.log({operation:"watch_coverage_record",param:t.start+"-"+t.end})},t.prototype.log=function(t){var e=this.crateLogItem(t);this.logger.log(e)},t.prototype.crateLogItem=function(t){var e=t.operation,r=t.param,n=Date.now(),o={vid:this.statContext.movieId};return void 0!==r&&(o.param=r),{operation:e,timestamp:n,custom:o}},t}();export{l as OneStat}; | ||
import t from"lodash.debounce";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{u(n.next(t))}catch(t){i(t)}}function s(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var o=function(){try{var t=Date.now().toString(),e=window.localStorage;e.setItem(t,t);var r=e.getItem(t)===t;return e.removeItem(t),r?e:null}catch(t){return null}}();var i=function(t){return function(t){var e=o?o.getItem("_one-stat_"+t):null;if(null===e)return null;try{return JSON.parse(e)}catch(t){return null}}(t)||null},a=function(t,e){!function(t,e){try{o&&o.setItem("_one-stat_"+t,JSON.stringify(e))}catch(t){}}(t,e)};var s;!function(t){t[t.PARAM_SESSION_EXPIRED=102]="PARAM_SESSION_EXPIRED",t[t.PARAM_SESSION_KEY=103]="PARAM_SESSION_KEY",t[t.PARAM_SIGNATURE=104]="PARAM_SIGNATURE",t[t.AUTH_LOGIN=401]="AUTH_LOGIN"}(s||(s={}));var u=function(){function t(t){this.apiTransport=t.apiTransport;var e=i("uuid");e?this.uuid=String(e):(this.uuid=function(){var t,e,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=new Array(36),o=0;for(e=0;e<36;e++)8===e||13===e||18===e||23===e?n[e]="-":14===e?n[e]="4":(o<=2&&(o=33554432+16777216*Math.random()|0),t=15&o,o>>=4,n[e]=r[19===e?3&t|8:t]);return n.join("")}(),a("uuid",this.uuid))}return t.prototype.authorize=function(t){return this.authToken=t,this._authorize()},t.prototype.logBeacon=function(t){var e="log.externalLog",r=this.createLogParams(t),n=this.sessionKey;void 0!==n&&this.apiTransport.sendBeacon(e,r,n)||this.apiTransport.sendRequest(e,r,n)},t.prototype.logRequest=function(t){var e,o;return r(this,void 0,void 0,(function(){var r,i,a,u,p,c;return n(this,(function(n){switch(n.label){case 0:return r="log.externalLog",i=this.createLogParams(t),null===(e=this.sessionKey)||void 0===e?[3,1]:(u=e,[3,3]);case 1:return[4,this._authorize()];case 2:u=n.sent(),n.label=3;case 3:a=u,n.label=4;case 4:return n.trys.push([4,6,,12]),[4,this.apiTransport.sendRequest(r,i,a)];case 5:return[2,n.sent()];case 6:switch(p=n.sent(),null===(o=p)||void 0===o?void 0:o.error_code){case s.PARAM_SESSION_EXPIRED:case s.PARAM_SESSION_KEY:case s.PARAM_SIGNATURE:return[3,7];case s.AUTH_LOGIN:return[3,9]}return[3,10];case 7:return[4,this._authorize()];case 8:return c=n.sent(),[2,this.apiTransport.sendRequest(r,i,c)];case 9:throw new Error("authToken");case 10:throw p;case 11:return[3,12];case 12:return[2]}}))}))},t.prototype.createLogParams=function(t){return{collector:"ok.mobile.apps.video",data:JSON.stringify({application:"@odnoklassniki/player-one-stat:0.0.3-dev.4590f59.0",platform:"WEB",items:t.map((function(t){return e(e({},t),{time:0,type:1})}))})}},t.prototype._authorize=function(){return r(this,void 0,void 0,(function(){var t,e=this;return n(this,(function(r){return this.authorizePromise||(this.sessionKey=void 0,"auth.anonymLogin",t={session_data:{version:2,device_id:this.uuid,client_type:"SDK_JS"}},void 0!==this.authToken&&(t.session_data.auth_token=this.authToken,t.session_data.version=3),this.authorizePromise=this.apiTransport.sendRequest("auth.anonymLogin",t).then((function(t){return t.session_key})).catch((function(t){console.error(t)})).then((function(t){return e.authorizePromise=void 0,e.sessionKey=t,t}))),[2,this.authorizePromise]}))}))},t}(),p=function(){function t(t){this.apiKey=t.apiKey,this.apiBaseUrl=t.apiBaseUrl,"/"!==this.apiBaseUrl[this.apiBaseUrl.length-1]&&(this.apiBaseUrl+="/")}return t.prototype.sendBeacon=function(t,e,r){if(!window.Blob||!window.navigator.sendBeacon)return!1;var n=this._prepareQueryParams({method:t,queryParams:e,sessionKey:r}),o=new window.Blob([n.toString()],{type:"application/x-www-form-urlencoded"});return window.navigator.sendBeacon(this.apiBaseUrl+"fb.do",o)},t.prototype.sendRequest=function(t,e,o){return r(this,void 0,void 0,(function(){return n(this,(function(r){return[2,fetch(this.apiBaseUrl+"fb.do",{method:"post",headers:{"Content-type":"application/x-www-form-urlencoded"},body:this._prepareQueryParams({method:t,queryParams:e,sessionKey:o})}).then((function(t){return Number(t.headers.get("content-length"))>0?t.json().then((function(t){return Object.prototype.hasOwnProperty.call(t,"error_msg")?Promise.reject(t):t})):void 0}))]}))}))},t.prototype._prepareQueryParams=function(t){var e=new URLSearchParams({format:"JSON",method:t.method,application_key:this.apiKey});return void 0!==t.sessionKey&&e.append("session_key",t.sessionKey),Object.entries(t.queryParams).forEach((function(t){var r=t[0],n=t[1];return e.append(r,"string"==typeof n?n:JSON.stringify(n))})),e},t}(),c=function(){function e(e){var r=this;this.requestQueue=[],this.debouncedFlush=t((function(){return r.flush()}),3e3,{maxWait:15e3}),this.api=e.api}return e.prototype.log=function(t){this.requestQueue.push(t),this.debouncedFlush()},e.prototype.flush=function(t){void 0===t&&(t=!1),t?this.api.logBeacon(this.requestQueue):this.api.logRequest(this.requestQueue),this.requestQueue=[],this.debouncedFlush.cancel()},e}(),h=function(){function t(t){var e=this;this.statContext=t;var r=new p({apiKey:"CIOPGQJGDIHBABABA",apiBaseUrl:"https://api.ok.ru"});this.api=new u({apiTransport:r}),this.logger=new c({api:this.api}),window.addEventListener("beforeunload",(function(){return e.logger.flush(!0)}))}return t.prototype.authorize=function(t){return this.api.authorize(t)},t.prototype.logStarted=function(){this.log({operation:"play"})},t.prototype.logPlay=function(){this.log({operation:"play_toggle"})},t.prototype.logPause=function(t){this.log({operation:"pause",param:String(t.position)})},t.prototype.logSeek=function(){this.log({operation:"seek"})},t.prototype.logFirstBytes=function(t){this.log({operation:"firstBytes",param:String(t.time)})},t.prototype.logFirstFrame=function(t){this.log({operation:"firstFrame",param:String(t.time)})},t.prototype.logError=function(t){this.log({operation:"error",param:t.errorType})},t.prototype.logWatchCoverageRecord=function(t){this.log({operation:"watch_coverage_record",param:t.start+"-"+t.end})},t.prototype.log=function(t){var e=this.crateLogItem(t);this.logger.log(e)},t.prototype.crateLogItem=function(t){var e=t.operation,r=t.param,n=Date.now(),o={vid:this.statContext.movieId};return void 0!==r&&(o.param=r),{operation:e,timestamp:n,custom:o}},t}();export{h as OneStat}; |
{ | ||
"name": "@odnoklassniki/player-one-stat", | ||
"version": "0.0.2", | ||
"version": "0.0.3-dev.4590f59.0", | ||
"description": "Statistics for one-video", | ||
@@ -5,0 +5,0 @@ "main": "index.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22833
11
262
3