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
git clone git@github.com:markmarijnissen/clockskew.git
node server
npm install clockskew
node node_modules/clockskew/server
modulus deploy
Client
npm install clockskew
var ClockSkew = require('clockskew/client');
var clockSkew = new ClockSkew({
getServerTime: ClockSkew.getSocketTime('ws://...'),
getServerTime: ClockSkew.getHttpTime.bind(null,'http://'),
getServerTime: ClockSkew.getFirebaseTime.bind(null,'https://xxx.firebaseio.com/timestamp')
getTime: function(){...},
timeout: 10000,
interval: 1000,
history: 10,
tolerance: 2,
waitInteval: 30000,
minSkewValues: 5,
minRttValues: 5
setTimeout: ...
clearTimeout: ...
onSkew: function(skew) {
});
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