Skip to content

Commit d97587b

Browse files
committed
Updated default, added documentation
Now defaults to 30,000. Removed the -1 magic number. Added documentation on use.
1 parent 39e1438 commit d97587b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ or
8383
- Accepts `integer`
8484
- Default: `1000`
8585

86+
#### `maxReconnectInterval`
87+
- The maximum number of milliseconds to delay a reconnection attempt.
88+
- Accepts `integer`
89+
- Default: `30000`
90+
8691
####`reconnectDecay`
8792
- The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist.
8893
- Accepts `integer` or `float`

reconnecting-websocket.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
* reconnectInterval
8080
* - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
8181
*
82+
* maxReconnectInterval
83+
* - The maximum number of milliseconds to delay a reconnection attempt. Accepts integer. Default: 30000.
84+
*
8285
* reconnectDecay
8386
* - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5.
8487
*
@@ -105,7 +108,7 @@
105108
/** The number of milliseconds to delay before attempting to reconnect. */
106109
reconnectInterval: 1000,
107110
/** The maximum number of milliseconds to delay a reconnection attempt. */
108-
maxReconnectInterval: -1,
111+
maxReconnectInterval: 30000,
109112
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
110113
reconnectDecay: 1.5,
111114
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
@@ -234,14 +237,12 @@
234237
}
235238
eventTarget.dispatchEvent(generateEvent('close'));
236239
}
237-
var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts);
238-
if (self.maxReconnectInterval != -1 && timeout > self.maxReconnectInterval)
239-
timeout = self.maxReconnectInterval;
240240

241+
var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts);
241242
setTimeout(function() {
242243
self.reconnectAttempts++;
243244
connect(true);
244-
}, timeout);
245+
}, timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout);
245246
}
246247
};
247248
ws.onmessage = function(event) {

0 commit comments

Comments
 (0)