Skip to content

Configure gracePeriodMutliplier #7

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

Open
wants to merge 4 commits 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
11 changes: 7 additions & 4 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,15 @@ <h3 id=heartbeat>Heart-beating</h3>

<p>If the STOMP broker accepts STOMP 1.1 frames, <a href=>heart-beating</a> is enabled by default.

<p>The <code>client</code> object has a <code>heartbeat</code> field which can be used to configure heart-beating by changing its <code>incoming</code> and <code>outgoing</code> integer fields (default value for both is <code>10000</code>ms):
<p>The <code>client</code> object has a <code>heartbeat</code> field which can be used to configure heart-beating by changing its <code>incoming</code>, <code>outgoing</code> and <code>gracePeriodMultiplier</code> integer fields (default value are: incoming = outgoing = <code>10000</code>ms, gracePeriodMtuliplier = <code>2</code>).:

<pre><code>
client.<mark>heartbeat.outgoing</mark> = 20000; // client will send heartbeats every 20000ms
client.<mark>heartbeat.incoming</mark> = 0; // client does not want to receive heartbeats
// from the server
client.<mark>heartbeat.outgoing</mark> = 20000; // client will send heartbeats every 20000ms
client.<mark>heartbeat.incoming</mark> = 0; // client does not want to receive heartbeats
// from the server
cliean.<mark>heartbeat.gracePeriodMultiplier</mark> = 2; // client will tolerate late heartbeats from the server.
// The effeltive heartbeat will be
// heartbeat.incoming * heartbeat.gracePeriodMultiplier
</code></pre>

<p>The heart-beating is using <code>window.setInterval()</code> to regularly send heart-beats and/or check server heart-beats.
Expand Down
5 changes: 3 additions & 2 deletions lib/stomp.js

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

2 changes: 1 addition & 1 deletion lib/stomp.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stompjs",
"version": "2.3.4-next",
"version": "3.0.1",
"author": "Jeff Mesnil <[email protected]>",
"description": "STOMP for JavaScript apps (Web browser & node.js)",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/stomp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class Client
# expect to receive server heartbeat at least every 10s by default
# (value in ms)
incoming: 10000
# multiplier to be tolerant for late heartbeats. The effective
# heartbeat interval will be incoming * gracePeriodMultiplier
# The default is 2 to be flexible on window's setInterval calls
gracePeriodMultiplier: 2

}
# maximum *WebSocket* frame size sent by the client. If the STOMP frame
# is bigger than this value, the STOMP frame will be sent using multiple
Expand Down Expand Up @@ -205,8 +210,7 @@ class Client
@debug? "check PONG every #{ttl}ms"
@ponger = Stomp.setInterval ttl, =>
delta = now() - @serverActivity
# We wait twice the TTL to be flexible on window's setInterval calls
if delta > ttl * 2
if delta > ttl * @heartbeat.gracePeriodMultiplier
@debug? "did not receive server activity for the last #{delta}ms"
@ws.close()

Expand Down