(window.webpackJsonp=window.webpackJsonp||[]).push([[60],{464:function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(object,t){var e=Object.keys(object);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(object);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(object,t).enumerable}))),e.push.apply(e,n)}return e}function c(t){for(var i=1;i1&&void 0!==arguments[1]?arguments[1]:{};l(this,t),this.log=e,this.opts=c({detectionInterval:15e3,detectionThreshold:1500},n),this.timer=0,this.frame=void 0,this.visible=!0}return d(t,[{key:"start",value:function(){var t=this.opts.detectionInterval;this.timer=setInterval(this.runJob.bind(this),t)}},{key:"stop",value:function(){clearInterval(this.timer)}},{key:"toggleVisible",value:function(t){this.visible=t,t?this.start():this.stop()}},{key:"runJob",value:function(){var t=this;cancelAnimationFrame(this.frame);var e=performance.now(),n=this.opts.detectionThreshold;this.frame=requestAnimationFrame((function(){var span=performance.now()-e;span>n&&t.log({t:"perf",c:10490,d:span})}))}}]),t}(),y=[function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new m(t,e)}],k="by-logger",w="by-pv",O="by-events",S="by-signup",j=null;try{j="AbortController"in window}catch(t){j=null}var T={},E=function(t){var e=String(t).toLowerCase();return{json:!0,text:!0,formData:!0,blob:!0,arrayBuffer:!0}[e]?e:"json"},P=function(t){return t>=200&&t<300},D=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(this,t),this.defaultOpts=c(c({},T),e),this.timeout=n.timeout||3e4,this.validateStatus=n.validateStatus||P,this.defaultRespType=n.defaultRespType||"json",this.interceptors={response:[],request:[],errorHandler:[],finally:[]}}return d(t,[{key:"get",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=t;if(e.body){var o=e.body,l=Object.keys(o);l.forEach((function(t){var param="".concat(t,"=").concat(o[t]);r=r.indexOf("?")>-1?"".concat(r,"&").concat(param):"".concat(r,"?").concat(param)})),delete e.body}return this.fetch(r,c(c({},e),{},{method:"get"}),n)}},{key:"post",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.fetch(t,c(c({},e),{},{method:"post"}),n)}},{key:"delete",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.fetch(t,c(c({},e),{},{method:"delete"}),n)}},{key:"put",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.fetch(t,c(c({},e),{},{method:"put"}),n)}},{key:"fetch",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){var e,n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0,l=o||this.defaultRespType,h=c(c(c({},this.defaultOpts),r),{},{headers:c(c({},this.defaultOpts.headers),r.headers)}),d=this.interceptors.request.reduce((function(e,n){return n(e,t)}),h),f=j?new AbortController:{};d.signal=f.signal;var v=new Promise((function(t,r){e=setTimeout((function(){r({ret_code:9000001,ret_msg:"Request timeout, please re-try!"}),j&&f.abort()}),n.timeout)})),m=fetch(t,d);return Promise.race([m,v]).then((function(t){return clearTimeout(e),t})).then((function(t){return n.validateStatus(t.status)?t.ok&&t[E(l)]():Promise.reject({status:t.status,statusText:t.statusText})})).then((function(data){return n.interceptors.response.reduce((function(t,e){return t.then(e)}),Promise.resolve({data:data,config:d,url:t}))})).catch((function(r){return clearTimeout(e),n.interceptors.errorHandler.forEach((function(e){return e(r,d,t)})),Promise.reject(r)})).finally((function(){n.interceptors.finally.forEach((function(e){return e(d,t)}))}))}))}]),t}(),I=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!("fetch"in window))return console.error("fetch function doesn't detected in you environment"),null;var n=new D(t,e),r=n.fetch.bind(n);return r.get=n.get.bind(n),r.post=n.post.bind(n),r.put=n.put.bind(n),r.delete=n.delete.bind(n),r.interceptors=n.interceptors,r}({headers:{"Content-Type":"application/json"}}),A=function(t){t.objectStoreNames.contains(k)||t.createObjectStore(k,{autoIncrement:!0}),t.objectStoreNames.contains(w)||t.createObjectStore(w,{autoIncrement:!0}),t.objectStoreNames.contains(O)||t.createObjectStore(O,{autoIncrement:!0}),t.objectStoreNames.contains(S)||t.createObjectStore(S,{autoIncrement:!0})},z=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(this,t),this.isRealtimeReport=-1===e.reportInterval,this.opts=c({extendFields:!1,reportInterval:45e3,reportUrl:"",noBackgroundTasks:!1,keepAliveInBackground:!1,maxSendBufferSize:80,logTable:k},e),this.eventOpts=c({v:0,p:0},n),this.tasks=[],this.timer=0,this.tabActive=!0,this.tmpSenderSize=this.opts.maxSendBufferSize,this.initialized=!1,this.idb=new f.a("by-skynet-db",2,A)}return d(t,[{key:"init",value:function(){var t=this;"undefined"!=typeof window&&(this.opts.keepAliveInBackground||document.addEventListener("visibilitychange",this.visibilityChange.bind(this)),this.opts.noBackgroundTasks||(this.tasks=y.map((function(e){return e(t.log.bind(t),t.opts)})),this.tasks.forEach((function(t){return t.start()}))),this.isRealtimeReport||(this.timer=setInterval(this.consume.bind(this),this.opts.reportInterval)),this.initialized=!0)}},{key:"visibilityChange",value:function(){var t=this;this.tabActive=!document.hidden,this.tasks.forEach((function(e){return e.toggleVisible(t.tabActive)}))}},{key:"consume",value:function(){var t=this;if(!this.tabActive||!this.initialized)return Promise.resolve();var e=this.tmpSenderSize,n=this.isRealtimeReport,r=this.opts,o=r.maxSendBufferSize,c=r.logTable,l=r.reportUrl;return this.idb.head(c,e).then((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=Object.keys(e).map(v.e);if(0===r.length)return Promise.resolve();var h=n?t.combineDelayValues(Object.values(e)):Object.values(e),d={method:"post",body:JSON.stringify(h)};return I(l,d,"text").then((function(){return t.tmpSenderSize=o,t.idb.delete(c,r)})).catch((function(e){console.error(e);var n=t.tmpSenderSize-5;n=n<1?1:n,t.tmpSenderSize=n}))}))}},{key:"sendDirect",value:function(t){var e={method:"post",body:JSON.stringify([this.combineEvent(t)])},n=this.opts.reportUrl;return console.log("[Skynet] Debug: ",t),I(n,e,"text").catch(console.error)}},{key:"combineDelayValues",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=this.opts.getUid;return Object(v.c)(t,(function(t){return c(c({},t),{},{u:e()||window.GA_UID})}))}},{key:"combineEvent",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=navigator.connection,o=this.opts,l=o.getGuid,h=o.getUid,d=Object.keys(this.eventOpts).reduce((function(e,n){var o=t.eventOpts[n],l=Object(v.a)(o)?o():o;return c(c({},e),{},r({},n,l))}),{});return c(c({g:l(),u:h()||window.GA_UID,net:n?n.rtt:-1,w:n?n.downlink>10?99:n.downlink:-1,dt:(new Date).toISOString()},d),e)}},{key:"log",value:function(t){return this.tabActive&&this.initialized?window&&window._BY_SKYNET_DEBUG_?this.sendDirect(t):this.isRealtimeReport?this.addDelayEvent(t):this.addEvent(t):Promise.resolve()}},{key:"addEvent",value:function(t){return this.idb.insert(this.opts.logTable,this.combineEvent(t)).catch()}},{key:"addDelayEvent",value:function(t){var e=this,n=this.opts.reportDelay;return clearTimeout(e.delayTimer),e.delayTimer=setTimeout((function(){e.consume.apply(e)}),n),this.addEvent(t)}}]),t}()}}]);