Skip to content

Commit

Permalink
Merge pull request #36 from JamesThorpe/doc-ts
Browse files Browse the repository at this point in the history
Updated ts with new option
  • Loading branch information
joewalnes committed Dec 23, 2014
2 parents ee8f794 + 46399e6 commit bc8d6cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -83,6 +83,11 @@ or
- Accepts `integer`
- Default: `1000`

#### `maxReconnectInterval`
- The maximum number of milliseconds to delay a reconnection attempt.
- Accepts `integer`
- Default: `30000`

####`reconnectDecay`
- The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist.
- Accepts `integer` or `float`
Expand Down
9 changes: 8 additions & 1 deletion reconnecting-websocket.js
Expand Up @@ -79,6 +79,9 @@
* reconnectInterval
* - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
*
* maxReconnectInterval
* - The maximum number of milliseconds to delay a reconnection attempt. Accepts integer. Default: 30000.
*
* reconnectDecay
* - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5.
*
Expand All @@ -104,6 +107,8 @@
debug: false,
/** The number of milliseconds to delay before attempting to reconnect. */
reconnectInterval: 1000,
/** The maximum number of milliseconds to delay a reconnection attempt. */
maxReconnectInterval: 30000,
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
reconnectDecay: 1.5,
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
Expand Down Expand Up @@ -232,10 +237,12 @@
}
eventTarget.dispatchEvent(generateEvent('close'));
}

var timeout = self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts);
setTimeout(function() {
self.reconnectAttempts++;
connect(true);
}, self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts));
}, timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout);
}
};
ws.onmessage = function(event) {
Expand Down
3 changes: 3 additions & 0 deletions reconnecting-websockets.d.ts
Expand Up @@ -23,6 +23,9 @@ declare class ReconnectingWebSocket
/** The number of milliseconds to delay before attempting to reconnect. */
public reconnectInterval: number;

/** The maximum number of milliseconds to delay a reconnection attempt. */
public maxReconnectInterval: number;

/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
public reconnectDecay: number;

Expand Down

0 comments on commit bc8d6cc

Please sign in to comment.