Giter Club home page Giter Club logo

clockskew's Introduction

clockskew

A smart algorithm to calculate clock skew from a timeserver.

Use it to synchronize your apps with millisecond accuracy.

See demo of synchronized note playing (open multiple tabs, modern browser required).

Time Server

# Clone from GIT
git clone [email protected]:markmarijnissen/clockskew.git
node server

# or get from NPM
npm install clockskew
node node_modules/clockskew/server

# Deploy online (for example using modulus.io)
modulus deploy

Client

npm install clockskew
var ClockSkew = require('clockskew/client');
// or just include the file 

var clockSkew = new ClockSkew({
	// REQUIRED :
	getServerTime: ClockSkew.getSocketTime('ws://...'),
	// or use HTTP protocol
	getServerTime: ClockSkew.getHttpTime.bind(null,'http://'),
	// or use Firebase
	getServerTime: ClockSkew.getFirebaseTime.bind(null,'https://xxx.firebaseio.com/timestamp')

	// OPTIONAL:
	getTime: function(){...}, // get local time in ms.
	timeout: 10000, // ping timeout
	interval: 1000, // ping interval
	history: 10, 
	tolerance: 2, // is standard deviation of last `history` average skew is less then tolerance, wait longer before pinging.
	waitInteval: 30000, // wait interval
	minSkewValues: 5, // minimum values before averaging
	minRttValues: 5 // minimum Round-Trip-Time values before rejecting RTTs that are more than 1 standard deviation slower
	setTimeout: ... // custom setTimeout Implementation
	clearTimeout: ... // custom clearTimeout implementation
	onSkew: function(skew) { // do stuff },
});

clockSkew.start();
clockSkew.stop();
clockSkew.skew;

Changelog

0.2.1 - Removed accidental console.log on stable clockskew value 0.2.0 - Changed ClockSkew.js into client.js

Contribute

Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.

Contact

© 2015 - Mark Marijnissen

clockskew's People

Contributors

markmarijnissen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.