Skip to content

Commit bc8d6cc

Browse files
committedDec 23, 2014
Merge pull request #36 from JamesThorpe/doc-ts
Updated ts with new option
2 parents ee8f794 + 46399e6 commit bc8d6cc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
 

‎README.md

+5
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

+8-1
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
*
@@ -104,6 +107,8 @@
104107
debug: false,
105108
/** The number of milliseconds to delay before attempting to reconnect. */
106109
reconnectInterval: 1000,
110+
/** The maximum number of milliseconds to delay a reconnection attempt. */
111+
maxReconnectInterval: 30000,
107112
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
108113
reconnectDecay: 1.5,
109114
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
@@ -232,10 +237,12 @@
232237
}
233238
eventTarget.dispatchEvent(generateEvent('close'));
234239
}
240+
241+
var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts);
235242
setTimeout(function() {
236243
self.reconnectAttempts++;
237244
connect(true);
238-
}, self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts));
245+
}, timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout);
239246
}
240247
};
241248
ws.onmessage = function(event) {

‎reconnecting-websockets.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ declare class ReconnectingWebSocket
2323
/** The number of milliseconds to delay before attempting to reconnect. */
2424
public reconnectInterval: number;
2525

26+
/** The maximum number of milliseconds to delay a reconnection attempt. */
27+
public maxReconnectInterval: number;
28+
2629
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
2730
public reconnectDecay: number;
2831

0 commit comments

Comments
 (0)
Please sign in to comment.