internet-time
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -1,1 +0,1 @@ | ||
const{CircularQueue}=require("@ganorberg/data-structures-javascript");function avg(b){return b.reduce((a,b)=>a+b)/b.length}module.exports=class{constructor({sendRequest:a,createRequest:b}={}){this.tDelta=null,this.rtt=null,this.timer=null,this.alpha=.01,this.updatePeriod=50,this.sendRequest=a,this.createRequest=b,this.deltaBuf=new CircularQueue(512),this.fHiddenTab=!1;try{this.fHiddenTab=document.hidden,document.addEventListener("visibilitychange",()=>{this.fHiddenTab=document.hidden})}catch(a){}}processResponse(a){const b=this.createRequest(),{tTx:c,tServer:d}=a,e=b-c;return this.tDelta=this.calcNewDelta(d-e/2-c),this.rtt=e,this.tDelta}calcNewDelta(a){return this.deltaBuf.enqueue(a),avg(this.deltaBuf.ring.filter(Boolean))}getDelta(){return this.tDelta}getRtt(){return this.rtt}start(){null!=this.timer&&this.stop(),this.sendAutoRequest(!0),this.timer=setInterval(this.sendAutoRequest.bind(this),this.updatePeriod)}stop(){null==this.timer||(clearInterval(this.timer),this.timer=null)}sendAutoRequest(a){if(!this.fHiddenTab||a){const a=this.createRequest();this.sendRequest(a)}}}; | ||
const{CircularQueue}=require("@ganorberg/data-structures-javascript");function avg(b){return b.reduce((a,b)=>a+b)/b.length}module.exports=class{constructor({sendRequest:a,createRequest:b}={}){this.tDelta=null,this.rtt=null,this.timer=null,this.alpha=.01,this.updatePeriod=125,this.sendRequest=a,this.createRequest=b,this.deltaBuf=new CircularQueue(512),this.fHiddenTab=!1;try{this.fHiddenTab=document.hidden,document.addEventListener("visibilitychange",()=>{this.fHiddenTab=document.hidden})}catch(a){}}processResponse(a){const b=this.createRequest(),{tTx:c,tServer:d}=a,e=b-c;return this.tDelta=this.calcNewDelta(d-e/2-c),this.rtt=e,this.tDelta}calcNewDelta(a){return this.deltaBuf.enqueue(a),avg(this.deltaBuf.ring.filter(Boolean))}getDelta(){return this.tDelta}getRtt(){return this.rtt}start(){null!=this.timer&&this.stop(),this.sendAutoRequest(!0),this.timer=setInterval(this.sendAutoRequest.bind(this),this.updatePeriod)}stop(){null==this.timer||(clearInterval(this.timer),this.timer=null)}sendAutoRequest(a){if(!this.fHiddenTab||a){const a=this.createRequest();this.sendRequest(a)}}}; |
{ | ||
"name": "internet-time", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
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
2743