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

hypertimer

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypertimer - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

examples/synchronization/slave1.js

4

dist/hypertimer.min.js

@@ -10,3 +10,3 @@ /**

* @version 2.1.0
* @date 2015-02-27
* @date 2015-03-02
*

@@ -28,3 +28,3 @@ * @license

*/
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ws"),require("debug")):"function"==typeof define&&define.amd?define(["ws","debug"],t):"object"==typeof exports?exports.hypertimer=t(require("ws"),require("debug")):n.hypertimer=t(n.ws,n.debug)}(this,function(n,t){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){n.exports=e(1)},function(n,t,e){function r(n){function t(){return{paced:w,rate:y,deterministic:g,time:b,master:_}}function e(n){if(x||n.master)for(var t in n)if("master"!==t&&"slave"!==t)throw new Error('Cannot apply configuration option "'+t+'", timer is configured as slave.')}function r(n){function e(n){var e=t();r(n);var o=t();S.emit("config",o,e)}if("deterministic"in n&&(g=n.deterministic?!0:!1),"paced"in n&&(w=n.paced?!0:!1),"time"in n&&(j=h(n.time),O=f.systemNow(),s(j),b=new Date(j).toISOString()),"rate"in n){var o=Number(n.rate);if(isNaN(o)||0>=o)throw new TypeError("Invalid rate "+JSON.stringify(n.rate)+". Rate must be a positive number");j=S.now(),O=f.systemNow(),y=o}"master"in n&&(x&&(x.destroy(),x=null),n.master&&(x=c(n.master),x.on("change",function(n){e({time:n})}),x.on("config",function(n){e(n)}),x.on("error",function(n){S.emit("error",n)}))),"port"in n&&(_&&(_.destroy(),_=null),n.port&&(_=u(S.now,S.config,n.port),_.on("error",function(n){S.emit("error",n)}))),m(),_&&_.broadcastConfig()}function s(n){for(var t=0;t<E.length;t++){var e=E[t];e.type===a.INTERVAL&&l(e,n)}}function l(n,t){n.occurrence=Math.round((t-n.firstTime)/n.interval),n.time=n.firstTime+n.occurrence*n.interval}function d(n){if(E.length>0){for(var t=E.length-1;t>=0&&E[t].time>n.time;)t--;E.splice(t+1,0,n)}else E.push(n)}function p(n,t){function e(){n.type===a.INTERVAL&&I[n.id]&&(n.occurrence++,n.time=n.firstTime+n.occurrence*n.interval,d(n)),delete I[n.id],t&&t()}I[n.id]=n;try{0==n.callback.length?(n.callback(),e()):n.callback(e)}catch(r){i(S,"error")?S.emit("error",r):console.log("Error",r),e()}}function v(n){for(var t=0;t<E.length&&(E[t].time<=n||!isFinite(E[t].time));)t++;var e=E.splice(0,t);return 0==g&&f.shuffle(e),e}function m(){function n(){function n(){var e=t.shift();e?p(e,n):m()}w||(j=e>j&&isFinite(e)?e:j);var t=v(e);w?(t.forEach(p),m()):n()}if(w||!(Object.keys(I).length>0)){var t=E[0];if(k&&(clearTimeout(k),k=null),T&&t){var e=t.time,r=e-S.now(),o=w?r/y:0;k=setTimeout(n,Math.round(o))}}}function h(n){var t="number"==typeof n?n:n instanceof Date?n.valueOf():new Date(n).valueOf();if(isNaN(t))throw new TypeError("Invalid date "+JSON.stringify(n)+". Date, number, or ISOString expected");return t}var w=!0,y=1,g=!0,b=null,_=null,x=null,T=!1,O=null,j=f.systemNow(),E=[],I={},k=null,N=0,S=o({});return S.config=function(n){return n&&(e(n),r(n)),t()},S.now=function(){if(w){if(T){var n=f.systemNow()-O,t=n*y;return j+t}return j}return j},S["continue"]=function(){O=f.systemNow(),T=!0,m()},S.pause=function(){j=S.now(),O=null,T=!1,m()},S.getTime=function(){return new Date(S.now())},S.valueOf=S.getTime,S.toString=function(){return S.getTime().toString()},S.setTimeout=function(n,t){var e=N++,r=S.now()+t;if(isNaN(r))throw new TypeError("delay must be a number");return d({id:e,type:a.TIMEOUT,time:r,callback:n}),m(),e},S.setTrigger=function(n,t){var e=N++,r=h(t);return d({id:e,type:a.TRIGGER,time:r,callback:n}),m(),e},S.setInterval=function(n,t,e){var r=N++,o=Number(t);if(isNaN(o))throw new TypeError("interval must be a number");(0>o||!isFinite(o))&&(o=0);var i=void 0!=e?h(e):null,u=S.now(),c=null!=i?i:u+o,f={id:r,type:a.INTERVAL,interval:o,time:c,firstTime:null!=i?i:c,occurrence:0,callback:n};return u>c&&l(f,u),d(f),m(),r},S.clearTimeout=function(n){if(I[n])return void delete I[n];for(var t=0;t<E.length;t++)if(E[t].id===n){E.splice(t,1),m();break}},S.clearTrigger=S.clearTimeout,S.clearInterval=S.clearTimeout,S.list=function(){return E.map(function(n){return n.id})},S.clear=function(){I={},E=[],m()},S.destroy=function(){S.clear(),x&&x.destroy(),_&&_.destroy()},Object.defineProperty(S,"running",{get:function(){return T}}),S.config(n),S["continue"](),S}var o=e(5),i=e(6),u=e(2).createMaster,c=e(3).createSlave,f=e(4),a={TIMEOUT:0,INTERVAL:1,TRIGGER:2};n.exports=r},function(n,t,e){var r=e(7),o=e(8),i=e(9)("hypertimer:master");t.createMaster=function(n,t,e){function u(){var n=t();return delete n.time,delete n.master,n}var c=new r.Server({port:e});return c.on("connection",function(t){i("new connection");var e=o(t);e.on("time",function(t,e){var r=n();e(r),i("send time "+new Date(r).toISOString())});var r=u();i("send config",r),e.send("config",r),t.emitter=e}),c.broadcast=function(n,t){i("broadcast",n,t),c.clients.forEach(function(e){e.emitter.send(n,t)})},c.broadcastConfig=function(){c.broadcast("config",u())},c.destroy=function(){c.close(),i("destroyed")},i("listening at ws://localhost:"+e),c}},function(n,t,e){var r=e(7),o=e(10),i=e(9)("hypertimer:slave"),u=e(8),c=e(11),f=e(12),a=36e5,s=1e3,l=5;t.createSlave=function(n){function t(){function n(){var n=null;return m?o.resolve(n):e(p).then(function(t){n=t})["catch"](function(n){console.log(n)}).then(function(){return f.wait(s)}).then(function(){return n})}return f.repeat(n,l).then(function(n){var t=n.filter(function(n){return null!==n}),e=c.median(t)+c.std(t),r=t.filter(function(n){return e>n});return r.length>0?c.mean(r):null}).then(function(n){return m?o.resolve(null):p.request("time").then(function(t){var e=t+n;return p.emit("change",e),e})})["catch"](function(n){p.emit("error",n)})}function e(n){var t=Date.now();return n.request("time").then(function(e){var r=Date.now(),o=(r-t)/2,i=e+o;return v&&(v=!1,n.emit("change",i)),o})}var d=new r(n),p=u(d),v=!0,m=!1,h=null;return d.onopen=function(){i("connected"),t(),h=setInterval(t,a)},p.destroy=function(){m=!0,clearInterval(h),h=null,d.close(),i("destroyed")},p}},function(n,t){t.systemNow="function"==typeof Date.now?function(){return Date.now()}:function(){return(new Date).valueOf()},t.shuffle=function(n){for(var t,e,r=n.length;r;t=Math.floor(Math.random()*r),e=n[--r],n[r]=n[t],n[t]=e);return n}},function(n,t,e){"use strict";var r,o,i,u,c,f,a,s=e(15),l=e(19),d=Function.prototype.apply,p=Function.prototype.call,v=Object.create,m=Object.defineProperty,h=Object.defineProperties,w=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};r=function(n,t){var e;return l(t),w.call(this,"__ee__")?e=this.__ee__:(e=y.value=v(null),m(this,"__ee__",y),y.value=null),e[n]?"object"==typeof e[n]?e[n].push(t):e[n]=[e[n],t]:e[n]=t,this},o=function(n,t){var e,o;return l(t),o=this,r.call(this,n,e=function(){i.call(o,n,e),d.call(t,this,arguments)}),e.__eeOnceListener__=t,this},i=function(n,t){var e,r,o,i;if(l(t),!w.call(this,"__ee__"))return this;if(e=this.__ee__,!e[n])return this;if(r=e[n],"object"==typeof r)for(i=0;o=r[i];++i)(o===t||o.__eeOnceListener__===t)&&(2===r.length?e[n]=r[i?0:1]:r.splice(i,1));else(r===t||r.__eeOnceListener__===t)&&delete e[n];return this},u=function(n){var t,e,r,o,i;if(w.call(this,"__ee__")&&(o=this.__ee__[n]))if("object"==typeof o){for(e=arguments.length,i=new Array(e-1),t=1;e>t;++t)i[t-1]=arguments[t];for(o=o.slice(),t=0;r=o[t];++t)d.call(r,this,i)}else switch(arguments.length){case 1:p.call(o,this);break;case 2:p.call(o,this,arguments[1]);break;case 3:p.call(o,this,arguments[1],arguments[2]);break;default:for(e=arguments.length,i=new Array(e-1),t=1;e>t;++t)i[t-1]=arguments[t];d.call(o,this,i)}},c={on:r,once:o,off:i,emit:u},f={on:s(r),once:s(o),off:s(i),emit:s(u)},a=h({},f),n.exports=t=function(n){return null==n?v(a):h(Object(n),f)},t.methods=c},function(n,t,e){"use strict";var r=e(17),o=e(18),i=Object.prototype.hasOwnProperty;n.exports=function(n){var t;return o(n),t=arguments[1],arguments.length>1?i.call(n,"__ee__")&&Boolean(n.__ee__[t]):n.hasOwnProperty("__ee__")&&!r(n.__ee__)}},function(n,t,e){n.exports="undefined"==typeof window||"undefined"==typeof window.WebSocket?e(13):window.WebSocket},function(n,t,e){var r=e(5),o=e(10),i=e(9)("hypertimer:socket"),u=6e4;n.exports=function(n){function t(t,e){var r={event:t,data:e};i("send",r),n.send(JSON.stringify(r))}function e(t,e){return new o(function(r,o){var i=c(),f={event:t,id:i,data:e};a[i]={resolve:r,reject:o,timeout:setTimeout(function(){delete a[i],o(new Error("Timeout"))},u)},n.send(JSON.stringify(f))})}function c(){return s++}var f=r({socket:n,send:t,request:e});n.onmessage=function(t){var e=t.data,r=JSON.parse(e);i("receive",r);var o=a[r.id];o?(clearTimeout(o.timeout),delete a[r.id],o.resolve(r.data)):"id"in r?f.emit(r.event,r.data,function(t){var e={id:r.id,data:t};i("reply",e),n.open&&n.send(JSON.stringify(e))}):f.emit(r.event,r.data)};var a={},s=0;return f}},function(n,t,e){var r="undefined"!=typeof window?window.Debug:e(14);n.exports=r||function(){return function(){}}},function(n,t,e){n.exports="undefined"==typeof window||"undefined"==typeof window.Promise?e(16):window.Promise},function(n,t){t.compare=function(n,t){return n>t?1:t>n?-1:0},t.add=function(n,t){return n+t},t.sum=function(n){return n.reduce(t.add)},t.mean=function(n){return t.sum(n)/n.length},t.std=function(n){return Math.sqrt(t.variance(n))},t.variance=function(n){if(n.length<2)return 0;var e=t.mean(n);return n.map(function(n){return Math.pow(n-e,2)}).reduce(t.add)/(n.length-1)},t.median=function(n){if(n.length<2)return n[0];var e=n.slice().sort(t.compare);return e.length%2===0?(n[n.length/2-1]+n[n.length/2])/2:n[(n.length-1)/2]}},function(n,t,e){var r=e(10);t.wait=function(n){return new r(function(t){setTimeout(t,n)})},t.repeat=function(n,t){return new r(function(e){function r(){t>o?(o++,n().then(function(n){i.push(n),r()})):e(i)}var o=0,i=[];r()})},t.whilst=function(n,t){return new r(function(e){function r(){n()?t().then(function(){r()}):e()}r()})}},function(t){t.exports=n},function(n){n.exports=t},function(n,t,e){"use strict";var r,o=e(26),i=e(20),u=e(21),c=e(27);r=n.exports=function(n,t){var e,r,u,f,a;return arguments.length<2||"string"!=typeof n?(f=t,t=n,n=null):f=arguments[2],null==n?(e=u=!0,r=!1):(e=c.call(n,"c"),r=c.call(n,"e"),u=c.call(n,"w")),a={value:t,configurable:e,enumerable:r,writable:u},f?o(i(f),a):a},r.gs=function(n,t,e){var r,f,a,s;return"string"!=typeof n?(a=e,e=t,t=n,n=null):a=arguments[3],null==t?t=void 0:u(t)?null==e?e=void 0:u(e)||(a=e,e=void 0):(a=t,t=e=void 0),null==n?(r=!0,f=!1):(r=c.call(n,"c"),f=c.call(n,"e")),s={get:t,set:e,configurable:r,enumerable:f},a?o(i(a),s):s}},function(n,t,e){"use strict";n.exports=e(22),e(23),e(24),e(25)},function(n,t,e){"use strict";var r=e(18),o=Object.prototype.propertyIsEnumerable;n.exports=function(n){var t;r(n);for(t in n)if(o.call(n,t))return!1;return!0}},function(n){"use strict";n.exports=function(n){if(null==n)throw new TypeError("Cannot use null or undefined");return n}},function(n){"use strict";n.exports=function(n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}},function(n){"use strict";var t=Array.prototype.forEach,e=Object.create,r=function(n,t){var e;for(e in n)t[e]=n[e]};n.exports=function(){var n=e(null);return t.call(arguments,function(t){null!=t&&r(Object(t),n)}),n}},function(n){"use strict";n.exports=function(n){return"function"==typeof n}},function(n,t,e){"use strict";function r(n){function t(n){return null===f?void s.push(n):void u(function(){var t=f?n.onFulfilled:n.onRejected;if(null===t)return void(f?n.resolve:n.reject)(a);var e;try{e=t(a)}catch(r){return void n.reject(r)}n.resolve(e)})}function e(n){try{if(n===l)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var t=n.then;if("function"==typeof t)return void i(t.bind(n),e,r)}f=!0,a=n,c()}catch(o){r(o)}}function r(n){f=!1,a=n,c()}function c(){for(var n=0,e=s.length;e>n;n++)t(s[n]);s=null}if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof n)throw new TypeError("not a function");var f=null,a=null,s=[],l=this;this.then=function(n,e){return new l.constructor(function(r,i){t(new o(n,e,r,i))})},i(n,e,r)}function o(n,t,e,r){this.onFulfilled="function"==typeof n?n:null,this.onRejected="function"==typeof t?t:null,this.resolve=e,this.reject=r}function i(n,t,e){var r=!1;try{n(function(n){r||(r=!0,t(n))},function(n){r||(r=!0,e(n))})}catch(o){if(r)return;r=!0,e(o)}}var u=e(32);n.exports=r},function(n,t,e){"use strict";var r=e(22),o=e(32);n.exports=r,r.prototype.done=function(){var n=arguments.length?this.then.apply(this,arguments):this;n.then(null,function(n){o(function(){throw n})})}},function(n,t,e){"use strict";function r(n){this.then=function(t){return"function"!=typeof t?this:new o(function(e,r){i(function(){try{e(t(n))}catch(o){r(o)}})})}}var o=e(22),i=e(32);n.exports=o,r.prototype=o.prototype;var u=new r(!0),c=new r(!1),f=new r(null),a=new r(void 0),s=new r(0),l=new r("");o.resolve=function(n){if(n instanceof o)return n;if(null===n)return f;if(void 0===n)return a;if(n===!0)return u;if(n===!1)return c;if(0===n)return s;if(""===n)return l;if("object"==typeof n||"function"==typeof n)try{var t=n.then;if("function"==typeof t)return new o(t.bind(n))}catch(e){return new o(function(n,t){t(e)})}return new r(n)},o.all=function(n){var t=Array.prototype.slice.call(n);return new o(function(n,e){function r(i,u){try{if(u&&("object"==typeof u||"function"==typeof u)){var c=u.then;if("function"==typeof c)return void c.call(u,function(n){r(i,n)},e)}t[i]=u,0===--o&&n(t)}catch(f){e(f)}}if(0===t.length)return n([]);for(var o=t.length,i=0;i<t.length;i++)r(i,t[i])})},o.reject=function(n){return new o(function(t,e){e(n)})},o.race=function(n){return new o(function(t,e){n.forEach(function(n){o.resolve(n).then(t,e)})})},o.prototype["catch"]=function(n){return this.then(null,n)}},function(n,t,e){"use strict";var r=e(22),o=e(32);n.exports=r,r.denodeify=function(n,t){return t=t||1/0,function(){var e=this,o=Array.prototype.slice.call(arguments);return new r(function(r,i){for(;o.length&&o.length>t;)o.pop();o.push(function(n,t){n?i(n):r(t)});var u=n.apply(e,o);!u||"object"!=typeof u&&"function"!=typeof u||"function"!=typeof u.then||r(u)})}},r.nodeify=function(n){return function(){var t=Array.prototype.slice.call(arguments),e="function"==typeof t[t.length-1]?t.pop():null,i=this;try{return n.apply(this,arguments).nodeify(e,i)}catch(u){if(null===e||"undefined"==typeof e)return new r(function(n,t){t(u)});o(function(){e.call(i,u)})}}},r.prototype.nodeify=function(n,t){return"function"!=typeof n?this:void this.then(function(e){o(function(){n.call(t,null,e)})},function(e){o(function(){n.call(t,e)})})}},function(n,t,e){"use strict";n.exports=e(28)()?Object.assign:e(29)},function(n,t,e){"use strict";n.exports=e(30)()?String.prototype.contains:e(31)},function(n){"use strict";n.exports=function(){var n,t=Object.assign;return"function"!=typeof t?!1:(n={foo:"raz"},t(n,{bar:"dwa"},{trzy:"trzy"}),n.foo+n.bar+n.trzy==="razdwatrzy")}},function(n,t,e){"use strict";var r=e(33),o=e(18),i=Math.max;n.exports=function(n,t){var e,u,c,f=i(arguments.length,2);for(n=Object(o(n)),c=function(r){try{n[r]=t[r]}catch(o){e||(e=o)}},u=1;f>u;++u)t=arguments[u],r(t).forEach(c);if(void 0!==e)throw e;return n}},function(n){"use strict";var t="razdwatrzy";n.exports=function(){return"function"!=typeof t.contains?!1:t.contains("dwa")===!0&&t.contains("foo")===!1}},function(n){"use strict";var t=String.prototype.indexOf;n.exports=function(n){return t.call(this,n,arguments[1])>-1}},function(n,t,e){(function(t,e){function r(){for(;i.next;){i=i.next;var n=i.task;i.task=void 0;var t=i.domain;t&&(i.domain=void 0,t.enter());try{n()}catch(e){if(a)throw t&&t.exit(),setTimeout(r,0),t&&t.enter(),e;setTimeout(function(){throw e},0)}t&&t.exit()}c=!1}function o(n){u=u.next={task:n,domain:a&&t.domain,next:null},c||(c=!0,f())}var i={task:void 0,next:null},u=i,c=!1,f=void 0,a=!1;if("undefined"!=typeof t&&t.nextTick)a=!0,f=function(){t.nextTick(r)};else if("function"==typeof e)f="undefined"!=typeof window?e.bind(window,r):function(){e(r)};else if("undefined"!=typeof MessageChannel){var s=new MessageChannel;s.port1.onmessage=r,f=function(){s.port2.postMessage(0)}}else f=function(){setTimeout(r,0)};n.exports=o}).call(t,e(36),e(37).setImmediate)},function(n,t,e){"use strict";n.exports=e(34)()?Object.keys:e(35)},function(n){"use strict";n.exports=function(){try{return Object.keys("primitive"),!0}catch(n){return!1}}},function(n){"use strict";var t=Object.keys;n.exports=function(n){return t(null==n?n:Object(n))}},function(n){function t(){}var e=n.exports={};e.nextTick=function(){var n="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(n)return function(n){return window.setImmediate(n)};var r=[];if(t){var o=document.createElement("div"),i=new MutationObserver(function(){var n=r.slice();r.length=0,n.forEach(function(n){n()})});return i.observe(o,{attributes:!0}),function(n){r.length||o.setAttribute("yes","no"),r.push(n)}}return e?(window.addEventListener("message",function(n){var t=n.source;if((t===window||null===t)&&"process-tick"===n.data&&(n.stopPropagation(),r.length>0)){var e=r.shift();e()}},!0),function(n){r.push(n),window.postMessage("process-tick","*")}):function(n){setTimeout(n,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.on=t,e.addListener=t,e.once=t,e.off=t,e.removeListener=t,e.removeAllListeners=t,e.emit=t,e.binding=function(){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(){throw new Error("process.chdir is not supported")}},function(n,t,e){(function(n,r){var o=e(38).nextTick,i=Array.prototype.slice,u={},c=0;"undefined"!=typeof setTimeout&&(t.setTimeout=function(){return setTimeout.apply(window,arguments)}),"undefined"!=typeof clearTimeout&&(t.clearTimeout=function(){clearTimeout.apply(window,arguments)}),"undefined"!=typeof setInterval&&(t.setInterval=function(){return setInterval.apply(window,arguments)}),"undefined"!=typeof clearInterval&&(t.clearInterval=function(){clearInterval.apply(window,arguments)}),t.enroll=function(n,t){n._timeoutID=setTimeout(n._onTimeout,t)},t.unenroll=function(n){clearTimeout(n._timeoutID)},t.active=function(){},t.setImmediate="function"==typeof n?n:function(n){var e=c++,r=arguments.length<2?!1:i.call(arguments,1);return u[e]=!0,o(function(){u[e]&&(r?n.apply(null,r):n.call(null),t.clearImmediate(e))}),e},t.clearImmediate="function"==typeof r?r:function(n){delete u[n]}}).call(t,e(37).setImmediate,e(37).clearImmediate)},function(n){function t(){if(!i){i=!0;for(var n,t=o.length;t;){n=o,o=[];for(var e=-1;++e<t;)n[e]();t=o.length}i=!1}}function e(){}var r=n.exports={},o=[],i=!1;r.nextTick=function(n){o.push(n),i||setTimeout(t,0)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}}])});
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ws"),require("debug")):"function"==typeof define&&define.amd?define(["ws","debug"],t):"object"==typeof exports?exports.hypertimer=t(require("ws"),require("debug")):n.hypertimer=t(n.ws,n.debug)}(this,function(n,t){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){n.exports=e(1)},function(n,t,e){function r(n){function t(){return{paced:w,rate:y,deterministic:g,time:b,master:_,port:T}}function e(n){if(M||n.master)for(var t in n)if("master"!==t&&"slave"!==t)throw new Error('Cannot apply configuration option "'+t+'", timer is configured as slave.')}function r(n){function e(n){var e=t();r(n);var o=t();A.emit("config",o,e)}if("deterministic"in n&&(g=n.deterministic?!0:!1),"paced"in n&&(w=n.paced?!0:!1),"time"in n&&(E=h(n.time),O=f.systemNow(),s(E),b=new Date(E).toISOString()),"rate"in n){var o=Number(n.rate);if(isNaN(o)||0>=o)throw new TypeError("Invalid rate "+JSON.stringify(n.rate)+". Rate must be a positive number");E=A.now(),O=f.systemNow(),y=o}"master"in n&&(M&&(M.destroy(),M=null),_=n.master,null!=n.master&&(M=c(n.master),M.on("change",function(n){e({time:n})}),M.on("config",function(n){e(n)}),M.on("error",function(n){A.emit("error",n)}))),"port"in n&&(S&&(S.destroy(),S=null),T=n.port,n.port&&(S=u(A.now,A.config,n.port),S.on("error",function(n){A.emit("error",n)}))),m(),S&&S.broadcastConfig()}function s(n){for(var t=0;t<j.length;t++){var e=j[t];e.type===a.INTERVAL&&l(e,n)}}function l(n,t){n.occurrence=Math.round((t-n.firstTime)/n.interval),n.time=n.firstTime+n.occurrence*n.interval}function d(n){if(j.length>0){for(var t=j.length-1;t>=0&&j[t].time>n.time;)t--;j.splice(t+1,0,n)}else j.push(n)}function p(n,t){function e(){n.type===a.INTERVAL&&I[n.id]&&(n.occurrence++,n.time=n.firstTime+n.occurrence*n.interval,d(n)),delete I[n.id],t&&t()}I[n.id]=n;try{0==n.callback.length?(n.callback(),e()):n.callback(e)}catch(r){i(A,"error")?A.emit("error",r):console.log("Error",r),e()}}function v(n){for(var t=0;t<j.length&&(j[t].time<=n||!isFinite(j[t].time));)t++;var e=j.splice(0,t);return 0==g&&f.shuffle(e),e}function m(){function n(){function n(){var e=t.shift();e?p(e,n):m()}w||(E=e>E&&isFinite(e)?e:E);var t=v(e);w?(t.forEach(p),m()):n()}if(w||!(Object.keys(I).length>0)){var t=j[0];if(k&&(clearTimeout(k),k=null),x&&t){var e=t.time,r=e-A.now(),o=w?r/y:0;k=setTimeout(n,Math.round(o))}}}function h(n){var t="number"==typeof n?n:n instanceof Date?n.valueOf():new Date(n).valueOf();if(isNaN(t))throw new TypeError("Invalid date "+JSON.stringify(n)+". Date, number, or ISOString expected");return t}var w=!0,y=1,g=!0,b=null,_=null,T=null,x=!1,O=null,E=f.systemNow(),j=[],I={},k=null,N=0,S=null,M=null,A=o({});return A.config=function(n){return n&&(e(n),r(n)),t()},A.now=function(){if(w){if(x){var n=f.systemNow()-O,t=n*y;return E+t}return E}return E},A["continue"]=function(){O=f.systemNow(),x=!0,m()},A.pause=function(){E=A.now(),O=null,x=!1,m()},A.getTime=function(){return new Date(A.now())},A.valueOf=A.getTime,A.toString=function(){return A.getTime().toString()},A.setTimeout=function(n,t){var e=N++,r=A.now()+t;if(isNaN(r))throw new TypeError("delay must be a number");return d({id:e,type:a.TIMEOUT,time:r,callback:n}),m(),e},A.setTrigger=function(n,t){var e=N++,r=h(t);return d({id:e,type:a.TRIGGER,time:r,callback:n}),m(),e},A.setInterval=function(n,t,e){var r=N++,o=Number(t);if(isNaN(o))throw new TypeError("interval must be a number");(0>o||!isFinite(o))&&(o=0);var i=void 0!=e?h(e):null,u=A.now(),c=null!=i?i:u+o,f={id:r,type:a.INTERVAL,interval:o,time:c,firstTime:null!=i?i:c,occurrence:0,callback:n};return u>c&&l(f,u),d(f),m(),r},A.clearTimeout=function(n){if(I[n])return void delete I[n];for(var t=0;t<j.length;t++)if(j[t].id===n){j.splice(t,1),m();break}},A.clearTrigger=A.clearTimeout,A.clearInterval=A.clearTimeout,A.list=function(){return j.map(function(n){return n.id})},A.clear=function(){I={},j=[],m()},A.destroy=function(){A.clear(),M&&M.destroy(),S&&S.destroy()},Object.defineProperty(A,"running",{get:function(){return x}}),A.config(n),A["continue"](),A}var o=e(5),i=e(6),u=e(2).createMaster,c=e(3).createSlave,f=e(4),a={TIMEOUT:0,INTERVAL:1,TRIGGER:2};n.exports=r},function(n,t,e){var r=e(7),o=e(10),i=e(9)("hypertimer:master");t.createMaster=function(n,t,e){function u(){var n=t();return delete n.time,delete n.master,delete n.port,n}var c=new r.Server({port:e});return c.on("connection",function(t){i("new connection");var e=o(t);e.on("time",function(t,e){var r=n();e(r),i("send time "+new Date(r).toISOString())});var r=u();i("send config",r),e.send("config",r),t.emitter=e}),c.broadcast=function(n,t){i("broadcast",n,t),c.clients.forEach(function(e){e.emitter.send(n,t)})},c.broadcastConfig=function(){c.broadcast("config",u())},c.destroy=function(){c.close(),i("destroyed")},i("listening at ws://localhost:"+e),c}},function(n,t,e){var r=e(7),o=e(8),i=e(9)("hypertimer:slave"),u=e(10),c=e(11),f=e(12),a=36e5,s=1e3,l=5;t.createSlave=function(n){function t(){function n(){var n=null;return m?o.resolve(n):e(p).then(function(t){n=t})["catch"](function(n){console.log(n)}).then(function(){return f.wait(s)}).then(function(){return n})}return f.repeat(n,l).then(function(n){i("latencies",n);var t=n.filter(function(n){return null!==n}),e=c.median(t)+c.std(t),r=t.filter(function(n){return e>n});return r.length>0?c.mean(r):null}).then(function(n){return m?o.resolve(null):p.request("time").then(function(t){var e=t+n;return p.emit("change",e),e})})["catch"](function(n){p.emit("error",n)})}function e(n){var t=Date.now();return n.request("time").then(function(e){var r=Date.now(),o=(r-t)/2,i=e+o;return v&&(v=!1,n.emit("change",i)),o})}var d=new r(n),p=u(d),v=!0,m=!1,h=null;return d.onopen=function(){i("connected"),t(),h=setInterval(t,a)},p.destroy=function(){m=!0,clearInterval(h),h=null,d.close(),i("destroyed")},p}},function(n,t){t.systemNow="function"==typeof Date.now?function(){return Date.now()}:function(){return(new Date).valueOf()},t.shuffle=function(n){for(var t,e,r=n.length;r;t=Math.floor(Math.random()*r),e=n[--r],n[r]=n[t],n[t]=e);return n}},function(n,t,e){"use strict";var r,o,i,u,c,f,a,s=e(15),l=e(17),d=Function.prototype.apply,p=Function.prototype.call,v=Object.create,m=Object.defineProperty,h=Object.defineProperties,w=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};r=function(n,t){var e;return l(t),w.call(this,"__ee__")?e=this.__ee__:(e=y.value=v(null),m(this,"__ee__",y),y.value=null),e[n]?"object"==typeof e[n]?e[n].push(t):e[n]=[e[n],t]:e[n]=t,this},o=function(n,t){var e,o;return l(t),o=this,r.call(this,n,e=function(){i.call(o,n,e),d.call(t,this,arguments)}),e.__eeOnceListener__=t,this},i=function(n,t){var e,r,o,i;if(l(t),!w.call(this,"__ee__"))return this;if(e=this.__ee__,!e[n])return this;if(r=e[n],"object"==typeof r)for(i=0;o=r[i];++i)(o===t||o.__eeOnceListener__===t)&&(2===r.length?e[n]=r[i?0:1]:r.splice(i,1));else(r===t||r.__eeOnceListener__===t)&&delete e[n];return this},u=function(n){var t,e,r,o,i;if(w.call(this,"__ee__")&&(o=this.__ee__[n]))if("object"==typeof o){for(e=arguments.length,i=new Array(e-1),t=1;e>t;++t)i[t-1]=arguments[t];for(o=o.slice(),t=0;r=o[t];++t)d.call(r,this,i)}else switch(arguments.length){case 1:p.call(o,this);break;case 2:p.call(o,this,arguments[1]);break;case 3:p.call(o,this,arguments[1],arguments[2]);break;default:for(e=arguments.length,i=new Array(e-1),t=1;e>t;++t)i[t-1]=arguments[t];d.call(o,this,i)}},c={on:r,once:o,off:i,emit:u},f={on:s(r),once:s(o),off:s(i),emit:s(u)},a=h({},f),n.exports=t=function(n){return null==n?v(a):h(Object(n),f)},t.methods=c},function(n,t,e){"use strict";var r=e(18),o=e(19),i=Object.prototype.hasOwnProperty;n.exports=function(n){var t;return o(n),t=arguments[1],arguments.length>1?i.call(n,"__ee__")&&Boolean(n.__ee__[t]):n.hasOwnProperty("__ee__")&&!r(n.__ee__)}},function(n,t,e){n.exports="undefined"==typeof window||"undefined"==typeof window.WebSocket?e(13):window.WebSocket},function(n,t,e){n.exports="undefined"==typeof window||"undefined"==typeof window.Promise?e(16):window.Promise},function(n,t,e){var r="undefined"!=typeof window?window.Debug:e(14);n.exports=r||function(){return function(){}}},function(n,t,e){var r=e(5),o=e(8),i=e(9)("hypertimer:socket"),u=6e4;n.exports=function(n){function t(t,e){var r={event:t,data:e};i("send",r),n.send(JSON.stringify(r))}function e(t,e){return new o(function(r,o){var f=c(),s={event:t,id:f,data:e};a[f]={resolve:r,reject:o,timeout:setTimeout(function(){delete a[f],o(new Error("Timeout"))},u)},i("request",s),n.send(JSON.stringify(s))})["catch"](function(n){console.log("ERROR",n)})}function c(){return s++}var f=r({socket:n,send:t,request:e});n.onmessage=function(t){var e=t.data,r=JSON.parse(e);i("receive",r);var o=a[r.id];o?(clearTimeout(o.timeout),delete a[r.id],o.resolve(r.data)):"id"in r?f.emit(r.event,r.data,function(t){var e={id:r.id,data:t};n.readyState===n.OPEN||n.readyState===n.CONNECTING?(i("reply",e),n.send(JSON.stringify(e))):i("cancel reply",e,"(socket is closed)")}):f.emit(r.event,r.data)};var a={},s=0;return f}},function(n,t){t.compare=function(n,t){return n>t?1:t>n?-1:0},t.add=function(n,t){return n+t},t.sum=function(n){return n.reduce(t.add)},t.mean=function(n){return t.sum(n)/n.length},t.std=function(n){return Math.sqrt(t.variance(n))},t.variance=function(n){if(n.length<2)return 0;var e=t.mean(n);return n.map(function(n){return Math.pow(n-e,2)}).reduce(t.add)/(n.length-1)},t.median=function(n){if(n.length<2)return n[0];var e=n.slice().sort(t.compare);return e.length%2===0?(n[n.length/2-1]+n[n.length/2])/2:n[(n.length-1)/2]}},function(n,t,e){var r=e(8);t.wait=function(n){return new r(function(t){setTimeout(t,n)})},t.repeat=function(n,t){return new r(function(e){function r(){t>o?(o++,n().then(function(n){i.push(n),r()})):e(i)}var o=0,i=[];r()})},t.whilst=function(n,t){return new r(function(e){function r(){n()?t().then(function(){r()}):e()}r()})}},function(t){t.exports=n},function(n){n.exports=t},function(n,t,e){"use strict";var r,o=e(22),i=e(20),u=e(21),c=e(27);r=n.exports=function(n,t){var e,r,u,f,a;return arguments.length<2||"string"!=typeof n?(f=t,t=n,n=null):f=arguments[2],null==n?(e=u=!0,r=!1):(e=c.call(n,"c"),r=c.call(n,"e"),u=c.call(n,"w")),a={value:t,configurable:e,enumerable:r,writable:u},f?o(i(f),a):a},r.gs=function(n,t,e){var r,f,a,s;return"string"!=typeof n?(a=e,e=t,t=n,n=null):a=arguments[3],null==t?t=void 0:u(t)?null==e?e=void 0:u(e)||(a=e,e=void 0):(a=t,t=e=void 0),null==n?(r=!0,f=!1):(r=c.call(n,"c"),f=c.call(n,"e")),s={get:t,set:e,configurable:r,enumerable:f},a?o(i(a),s):s}},function(n,t,e){"use strict";n.exports=e(23),e(24),e(25),e(26)},function(n){"use strict";n.exports=function(n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}},function(n,t,e){"use strict";var r=e(19),o=Object.prototype.propertyIsEnumerable;n.exports=function(n){var t;r(n);for(t in n)if(o.call(n,t))return!1;return!0}},function(n){"use strict";n.exports=function(n){if(null==n)throw new TypeError("Cannot use null or undefined");return n}},function(n){"use strict";var t=Array.prototype.forEach,e=Object.create,r=function(n,t){var e;for(e in n)t[e]=n[e]};n.exports=function(){var n=e(null);return t.call(arguments,function(t){null!=t&&r(Object(t),n)}),n}},function(n){"use strict";n.exports=function(n){return"function"==typeof n}},function(n,t,e){"use strict";n.exports=e(28)()?Object.assign:e(29)},function(n,t,e){"use strict";function r(n){function t(n){return null===f?void s.push(n):void u(function(){var t=f?n.onFulfilled:n.onRejected;if(null===t)return void(f?n.resolve:n.reject)(a);var e;try{e=t(a)}catch(r){return void n.reject(r)}n.resolve(e)})}function e(n){try{if(n===l)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var t=n.then;if("function"==typeof t)return void i(t.bind(n),e,r)}f=!0,a=n,c()}catch(o){r(o)}}function r(n){f=!1,a=n,c()}function c(){for(var n=0,e=s.length;e>n;n++)t(s[n]);s=null}if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof n)throw new TypeError("not a function");var f=null,a=null,s=[],l=this;this.then=function(n,e){return new l.constructor(function(r,i){t(new o(n,e,r,i))})},i(n,e,r)}function o(n,t,e,r){this.onFulfilled="function"==typeof n?n:null,this.onRejected="function"==typeof t?t:null,this.resolve=e,this.reject=r}function i(n,t,e){var r=!1;try{n(function(n){r||(r=!0,t(n))},function(n){r||(r=!0,e(n))})}catch(o){if(r)return;r=!0,e(o)}}var u=e(32);n.exports=r},function(n,t,e){"use strict";var r=e(23),o=e(32);n.exports=r,r.prototype.done=function(){var n=arguments.length?this.then.apply(this,arguments):this;n.then(null,function(n){o(function(){throw n})})}},function(n,t,e){"use strict";function r(n){this.then=function(t){return"function"!=typeof t?this:new o(function(e,r){i(function(){try{e(t(n))}catch(o){r(o)}})})}}var o=e(23),i=e(32);n.exports=o,r.prototype=o.prototype;var u=new r(!0),c=new r(!1),f=new r(null),a=new r(void 0),s=new r(0),l=new r("");o.resolve=function(n){if(n instanceof o)return n;if(null===n)return f;if(void 0===n)return a;if(n===!0)return u;if(n===!1)return c;if(0===n)return s;if(""===n)return l;if("object"==typeof n||"function"==typeof n)try{var t=n.then;if("function"==typeof t)return new o(t.bind(n))}catch(e){return new o(function(n,t){t(e)})}return new r(n)},o.all=function(n){var t=Array.prototype.slice.call(n);return new o(function(n,e){function r(i,u){try{if(u&&("object"==typeof u||"function"==typeof u)){var c=u.then;if("function"==typeof c)return void c.call(u,function(n){r(i,n)},e)}t[i]=u,0===--o&&n(t)}catch(f){e(f)}}if(0===t.length)return n([]);for(var o=t.length,i=0;i<t.length;i++)r(i,t[i])})},o.reject=function(n){return new o(function(t,e){e(n)})},o.race=function(n){return new o(function(t,e){n.forEach(function(n){o.resolve(n).then(t,e)})})},o.prototype["catch"]=function(n){return this.then(null,n)}},function(n,t,e){"use strict";var r=e(23),o=e(32);n.exports=r,r.denodeify=function(n,t){return t=t||1/0,function(){var e=this,o=Array.prototype.slice.call(arguments);return new r(function(r,i){for(;o.length&&o.length>t;)o.pop();o.push(function(n,t){n?i(n):r(t)});var u=n.apply(e,o);!u||"object"!=typeof u&&"function"!=typeof u||"function"!=typeof u.then||r(u)})}},r.nodeify=function(n){return function(){var t=Array.prototype.slice.call(arguments),e="function"==typeof t[t.length-1]?t.pop():null,i=this;try{return n.apply(this,arguments).nodeify(e,i)}catch(u){if(null===e||"undefined"==typeof e)return new r(function(n,t){t(u)});o(function(){e.call(i,u)})}}},r.prototype.nodeify=function(n,t){return"function"!=typeof n?this:void this.then(function(e){o(function(){n.call(t,null,e)})},function(e){o(function(){n.call(t,e)})})}},function(n,t,e){"use strict";n.exports=e(30)()?String.prototype.contains:e(31)},function(n){"use strict";n.exports=function(){var n,t=Object.assign;return"function"!=typeof t?!1:(n={foo:"raz"},t(n,{bar:"dwa"},{trzy:"trzy"}),n.foo+n.bar+n.trzy==="razdwatrzy")}},function(n,t,e){"use strict";var r=e(33),o=e(19),i=Math.max;n.exports=function(n,t){var e,u,c,f=i(arguments.length,2);for(n=Object(o(n)),c=function(r){try{n[r]=t[r]}catch(o){e||(e=o)}},u=1;f>u;++u)t=arguments[u],r(t).forEach(c);if(void 0!==e)throw e;return n}},function(n){"use strict";var t="razdwatrzy";n.exports=function(){return"function"!=typeof t.contains?!1:t.contains("dwa")===!0&&t.contains("foo")===!1}},function(n){"use strict";var t=String.prototype.indexOf;n.exports=function(n){return t.call(this,n,arguments[1])>-1}},function(n,t,e){(function(t,e){function r(){for(;i.next;){i=i.next;var n=i.task;i.task=void 0;var t=i.domain;t&&(i.domain=void 0,t.enter());try{n()}catch(e){if(a)throw t&&t.exit(),setTimeout(r,0),t&&t.enter(),e;setTimeout(function(){throw e},0)}t&&t.exit()}c=!1}function o(n){u=u.next={task:n,domain:a&&t.domain,next:null},c||(c=!0,f())}var i={task:void 0,next:null},u=i,c=!1,f=void 0,a=!1;if("undefined"!=typeof t&&t.nextTick)a=!0,f=function(){t.nextTick(r)};else if("function"==typeof e)f="undefined"!=typeof window?e.bind(window,r):function(){e(r)};else if("undefined"!=typeof MessageChannel){var s=new MessageChannel;s.port1.onmessage=r,f=function(){s.port2.postMessage(0)}}else f=function(){setTimeout(r,0)};n.exports=o}).call(t,e(36),e(37).setImmediate)},function(n,t,e){"use strict";n.exports=e(34)()?Object.keys:e(35)},function(n){"use strict";n.exports=function(){try{return Object.keys("primitive"),!0}catch(n){return!1}}},function(n){"use strict";var t=Object.keys;n.exports=function(n){return t(null==n?n:Object(n))}},function(n){function t(){}var e=n.exports={};e.nextTick=function(){var n="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(n)return function(n){return window.setImmediate(n)};var r=[];if(t){var o=document.createElement("div"),i=new MutationObserver(function(){var n=r.slice();r.length=0,n.forEach(function(n){n()})});return i.observe(o,{attributes:!0}),function(n){r.length||o.setAttribute("yes","no"),r.push(n)}}return e?(window.addEventListener("message",function(n){var t=n.source;if((t===window||null===t)&&"process-tick"===n.data&&(n.stopPropagation(),r.length>0)){var e=r.shift();e()}},!0),function(n){r.push(n),window.postMessage("process-tick","*")}):function(n){setTimeout(n,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.on=t,e.addListener=t,e.once=t,e.off=t,e.removeListener=t,e.removeAllListeners=t,e.emit=t,e.binding=function(){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(){throw new Error("process.chdir is not supported")}},function(n,t,e){(function(n,r){var o=e(38).nextTick,i=Array.prototype.slice,u={},c=0;"undefined"!=typeof setTimeout&&(t.setTimeout=function(){return setTimeout.apply(window,arguments)}),"undefined"!=typeof clearTimeout&&(t.clearTimeout=function(){clearTimeout.apply(window,arguments)}),"undefined"!=typeof setInterval&&(t.setInterval=function(){return setInterval.apply(window,arguments)}),"undefined"!=typeof clearInterval&&(t.clearInterval=function(){clearInterval.apply(window,arguments)}),t.enroll=function(n,t){n._timeoutID=setTimeout(n._onTimeout,t)},t.unenroll=function(n){clearTimeout(n._timeoutID)},t.active=function(){},t.setImmediate="function"==typeof n?n:function(n){var e=c++,r=arguments.length<2?!1:i.call(arguments,1);return u[e]=!0,o(function(){u[e]&&(r?n.apply(null,r):n.call(null),t.clearImmediate(e))}),e},t.clearImmediate="function"==typeof r?r:function(n){delete u[n]}}).call(t,e(37).setImmediate,e(37).clearImmediate)},function(n){function t(){if(!i){i=!0;for(var n,t=o.length;t;){n=o,o=[];for(var e=-1;++e<t;)n[e]();t=o.length}i=!1}}function e(){}var r=n.exports={},o=[],i=!1;r.nextTick=function(n){o.push(n),i||setTimeout(t,0)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}}])});
//# sourceMappingURL=hypertimer.map
# History
## 2015-03-02, version 2.1.1
- Fixed replies not being send via socket.
## 2015-02-27, version 2.1.0

@@ -5,0 +10,0 @@

@@ -46,4 +46,4 @@ var emitter = require('event-emitter');

var configuredTime = null;// only used for returning the configured time on .config()
var master = null;
var slave = null;
var master = null; // url of master, will run as slave
var port = null; // port to serve as master

@@ -58,2 +58,4 @@ // properties

var idSeq = 0; // counter for unique timeout id's
var server = null;
var client = null;

@@ -348,4 +350,4 @@ // exported timer object with public functions and variables

timer.clear();
if (slave) slave.destroy();
if (master) master.destroy();
if (client) client.destroy();
if (server) server.destroy();
};

@@ -365,3 +367,4 @@

time: configuredTime,
master: master
master: master,
port: port
}

@@ -377,3 +380,3 @@ }

// validate writable options
if (slave || options.master) {
if (client || options.master) {
// when we are a slave, we can't adjust the config, except for

@@ -428,9 +431,10 @@ // changing the master url or becoming a master itself (port configured)

// create a timesync slave, connect to master via a websocket
if (slave) {
slave.destroy();
slave = null;
if (client) {
client.destroy();
client = null;
}
if (options.master) {
slave = createSlave(options.master);
master = options.master;
if (options.master != null) {
client = createSlave(options.master);

@@ -444,5 +448,5 @@ function applyConfig(config) {

slave.on('change', function (time) { applyConfig({time: time}) });
slave.on('config', function (config) { applyConfig(config) });
slave.on('error', function (err) { timer.emit('error', err) });
client.on('change', function (time) { applyConfig({time: time}) });
client.on('config', function (config) { applyConfig(config) });
client.on('error', function (err) { timer.emit('error', err) });
}

@@ -453,10 +457,11 @@ }

if ('port' in options) {
if (master) {
master.destroy();
master = null;
if (server) {
server.destroy();
server = null;
}
port = options.port;
if (options.port) {
master = createMaster(timer.now, timer.config, options.port);
master.on('error', function (err) { timer.emit('error', err) });
server = createMaster(timer.now, timer.config, options.port);
server.on('error', function (err) { timer.emit('error', err) });
}

@@ -468,5 +473,5 @@ }

if (master) {
if (server) {
// broadcast changed config
master.broadcastConfig();
server.broadcastConfig();
}

@@ -473,0 +478,0 @@ }

@@ -48,2 +48,3 @@ var WebSocket = require('./WebSocket');

delete curr.master;
delete curr.port;
return curr;

@@ -50,0 +51,0 @@ }

@@ -52,3 +52,3 @@ var WebSocket = require('./WebSocket');

.then(function (latency) { result = latency }) // store the retrieved latency
.catch(function (err) { console.log(err) }) // just ignore failed requests
.catch(function (err) { console.log(err) }) // just log failed requests
.then(function () { return util.wait(DELAY) }) // wait 1 sec

@@ -61,2 +61,4 @@ .then(function () { return result}); // return the retrieved latency

.then(function (all) {
debug('latencies', all);
// filter away failed requests

@@ -63,0 +65,0 @@ var latencies = all.filter(function (latency) {

@@ -56,4 +56,5 @@ // Turn a WebSocket in an event emitter.

debug('request', envelope);
socket.send(JSON.stringify(envelope));
});
}).catch(function (err) {console.log('ERROR', err)});
}

@@ -85,4 +86,10 @@

};
debug('reply', response);
socket.open && socket.send(JSON.stringify(response));
if (socket.readyState === socket.OPEN || socket.readyState === socket.CONNECTING) {
debug('reply', response);
socket.send(JSON.stringify(response));
}
else {
debug('cancel reply', response, '(socket is closed)');
}
});

@@ -89,0 +96,0 @@ }

{
"name": "hypertimer",
"version": "2.1.0",
"version": "2.1.1",
"description": "Time control for simulations",

@@ -5,0 +5,0 @@ "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",

@@ -41,6 +41,20 @@ // NOTE: all timeouts should have time differences of at least 50ms to be

var timer = hypertimer();
assert.deepEqual(timer.config(), {paced: true, rate: 1, deterministic: true, time: null, master: null});
assert.deepEqual(timer.config(), {
paced: true,
rate: 1,
deterministic: true,
time: null,
master: null,
port: null
});
var timer2 = hypertimer({paced: false, rate: 2, deterministic: false, time: 2524651200000});
assert.deepEqual(timer2.config(), {paced: false, rate: 2, deterministic: false, time: '2050-01-01T12:00:00.000Z', master: null});
assert.deepEqual(timer2.config(), {
paced: false,
rate: 2,
deterministic: false,
time: '2050-01-01T12:00:00.000Z',
master: null,
port: null
});
});

@@ -47,0 +61,0 @@

@@ -13,4 +13,10 @@ var assert = require('assert');

slave.on('config', function (config) {
assert.equal(config.port, null); // should not be sent from the master
assert.equal(config.rate, 2);
assert.deepEqual(config, {
paced: true,
rate: 2,
deterministic: true,
time: null,
port: null, // should not be sent from the master
master: 'ws://localhost:' + port
});
slave.destroy();

@@ -17,0 +23,0 @@ master.destroy();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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