diff --git a/dist/stomp.js b/dist/stomp.js index 2e3afb3..1b0d04c 100644 --- a/dist/stomp.js +++ b/dist/stomp.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.4.0 +// Generated by CoffeeScript 1.6.3 (function() { var Byte, Client, Frame, Stomp, __hasProp = {}.hasOwnProperty; @@ -9,7 +9,6 @@ }; Frame = (function() { - function Frame(command, headers, body) { this.command = command; this.headers = headers != null ? headers : {}; @@ -92,7 +91,6 @@ })(); Client = (function() { - function Client(ws) { this.ws = ws; this.ws.binaryType = "arraybuffer"; @@ -102,6 +100,7 @@ outgoing: 10000, incoming: 10000 }; + this.heartbeatWindow = 0.10; this.subscriptions = {}; } @@ -132,6 +131,7 @@ })(), serverOutgoing = _ref1[0], serverIncoming = _ref1[1]; if (!(this.heartbeat.outgoing === 0 || serverIncoming === 0)) { ttl = Math.max(this.heartbeat.outgoing, serverIncoming); + ttl = ttl - (ttl * this.heartbeatWindow); if (typeof this.debug === "function") { this.debug("send PING every " + ttl + "ms"); } @@ -142,6 +142,7 @@ } if (!(this.heartbeat.incoming === 0 || serverOutgoing === 0)) { ttl = Math.max(this.heartbeat.incoming, serverOutgoing); + ttl = ttl + (ttl * this.heartbeatWindow); if (typeof this.debug === "function") { this.debug("check PONG every " + ttl + "ms"); } diff --git a/src/stomp.coffee b/src/stomp.coffee index 7408f23..59c7e7d 100644 --- a/src/stomp.coffee +++ b/src/stomp.coffee @@ -111,6 +111,9 @@ class Client # (value in ms) incoming: 10000 } + # Send pings 10% faster and allow pongs 10% slower to account for + # inaccurate timing in the web browser + @heartbeatWindow = 0.10 #10% # subscription callbacks indexed by subscriber's ID @subscriptions = {} @@ -129,6 +132,7 @@ class Client unless @heartbeat.outgoing == 0 or serverIncoming == 0 ttl = Math.max(@heartbeat.outgoing, serverIncoming) + ttl = ttl - (ttl * @heartbeatWindow); @debug? "send PING every #{ttl}ms" @pinger = window?.setInterval(=> @ws.send Byte.LF @@ -137,6 +141,7 @@ class Client unless @heartbeat.incoming == 0 or serverOutgoing == 0 ttl = Math.max(@heartbeat.incoming, serverOutgoing) + ttl = ttl + (ttl * @heartbeatWindow) @debug? "check PONG every #{ttl}ms" @ponger = window?.setInterval(=> delta = Date.now() - @serverActivity @@ -355,4 +360,4 @@ else if exports? Stomp.WebSocketClass = require('./test/server.mock.js').StompServerMock # or in the current object (e.g. a WebWorker) else - self.Stomp = Stomp \ No newline at end of file + self.Stomp = Stomp