Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a window for heartbeat pings and pongs #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dist/stomp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/stomp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
self.Stomp = Stomp