Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

internet-time

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

internet-time - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

2

dist/client.js

@@ -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=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)}}};
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.rttBuf=new CircularQueue(512),this.running=!1,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 avg(this.rttBuf.ring.filter(Boolean))}async start(){if(!this.running)for(this.running=!0,await this.sendAutoRequest(!0);this.running;){const a=this.createRequest();await this.sendAutoRequest();const b=this.createRequest();this.rttBuf.enqueue(b-a)}}stop(){this.running=!1}async sendAutoRequest(a){if(!this.fHiddenTab||a){const a=this.createRequest();await this.sendRequest(a)}}};

@@ -1,1 +0,1 @@

const EventEmitter=require("events"),WebSocket=require("isomorphic-ws"),perf=require("./performance"),TimeClient=require("./client"),e=new EventEmitter;let s;const timeClient=new TimeClient({sendRequest:a=>{try{s.send(a)}catch(a){}},createRequest:()=>perf.now()+perf.timeOrigin}),socket=()=>(s||(s=new WebSocket("wss://time-server.fly.dev/"),s.onclose=()=>{s=void 0,socket()},s.onmessage=({data:a})=>{const b=a.split(" "),c=timeClient.processResponse({tTx:+b[0],tServer:+(b[1]/1e3)});e.emit("delta",c)},s.onerror=()=>{},s.onopen=()=>timeClient.start()),s);e.delta=()=>(socket(),timeClient.getDelta()||0),e.now=()=>perf.timeOrigin+perf.now()+e.delta(),e.nextDelta=()=>new Promise(a=>{e.now(),e.once("delta",a)}),module.exports=e;
const EventEmitter=require("events");require("isomorphic-fetch");const perf=require("./performance"),TimeClient=require("./client"),e=new EventEmitter,timeClient=new TimeClient({sendRequest:async a=>{try{const b=await fetch("https://cloudflare.com/cdn-cgi/trace"),c=await b.text(),d=c.split("\n"),f=+d.find(a=>a.startsWith("ts=")).slice(3),g=timeClient.processResponse({tTx:a,tServer:1e3*f});e.emit("delta",g)}catch(a){}},createRequest:()=>perf.now()+perf.timeOrigin});e.delta=()=>(timeClient.start(),timeClient.getDelta()||0),e.now=()=>perf.timeOrigin+perf.now()+e.delta(),e.nextDelta=()=>new Promise(a=>{e.now(),e.once("delta",a)}),e.latency=()=>timeClient.getRtt(),module.exports=e;
{
"name": "internet-time",
"version": "0.0.13",
"version": "0.0.14",
"main": "dist/index.js",

@@ -13,2 +13,3 @@ "license": "MIT",

"clocksy": "^1.1.0",
"isomorphic-fetch": "^2.2.1",
"isomorphic-ws": "^4.0.1",

@@ -15,0 +16,0 @@ "socket.io-client": "^2.2.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc