|
1 | 1 | ReconnectingWebSocket
|
2 | 2 | =====================
|
3 | 3 |
|
4 |
| -A small JavaScript library that decorates the WebSocket API to provide |
5 |
| -a WebSocket connection that will automatically reconnect if the |
6 |
| -connection is dropped. |
| 4 | +A small JavaScript library that decorates the WebSocket API to provide a WebSocket connection that will automatically reconnect if the connection is dropped. |
7 | 5 |
|
8 | 6 | It is API compatible, so when you have:
|
9 | 7 |
|
@@ -48,12 +46,57 @@ With a `ReconnectingWebSocket`, after an `onclose` event is called it will autom
|
48 | 46 |
|
49 | 47 | This is all handled automatically for you by the library.
|
50 | 48 |
|
51 |
| -More |
52 |
| ----- |
| 49 | +## Parameters |
| 50 | + |
| 51 | +`var socket = new ReconnectingWebSocket(url, protocols, options);` |
| 52 | + |
| 53 | +#### `url` |
| 54 | +- The URL you are connecting to. |
| 55 | +- http://dev.w3.org/html5/websockets/#the-websocket-interface |
| 56 | + |
| 57 | +#### `protocols` |
| 58 | +- Optional string or array of protocols per the WebSocket spec. |
| 59 | +- [http://dev.w3.org/html5/websockets/#refsWSP |
| 60 | + |
| 61 | +#### `options` |
| 62 | +- Options (see below) |
| 63 | + |
| 64 | +## Options |
| 65 | + |
| 66 | +Options can either be passed as the 3rd parameter upon instantiation or set directly on the object after instantiation: |
| 67 | + |
| 68 | +`var socket = new ReconnectingWebSocket(url, null, {debug: true, reconnectInterval: 3000});` |
| 69 | + |
| 70 | +or |
| 71 | + |
| 72 | + var socket = new ReconnectingWebSocket(url); |
| 73 | + socket.debug = true; |
| 74 | + socket.timeoutInterval = 5400; |
| 75 | + |
| 76 | +#### `debug` |
| 77 | +- Whether this instance should log debug messages or not. Debug messages are printed to `console.debug()`. |
| 78 | +- Accepts `true` or `false` |
| 79 | +- Default value: `false` |
| 80 | + |
| 81 | +#### `reconnectInterval` |
| 82 | +- The number of milliseconds to delay before attempting to reconnect. |
| 83 | +- Accepts `integer` |
| 84 | +- Default: `1000` |
| 85 | + |
| 86 | +####`reconnectDecay` |
| 87 | +- The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. |
| 88 | +- Accepts `integer` or `float` |
| 89 | +- Default: `1.5` |
| 90 | + |
| 91 | +#### `timeoutInterval` - `[integer]` |
| 92 | +- The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. |
| 93 | +- Accepts `integer` |
| 94 | +- Default: `2000` |
| 95 | + |
| 96 | +--- |
53 | 97 |
|
54 | 98 | Like this? Check out [websocketd](https://github.com/joewalnes/websocketd) for the simplest way to create WebSocket backends from any programming language.
|
55 | 99 |
|
56 | 100 | [Follow @joewalnes](https://twitter.com/joewalnes)
|
57 | 101 |
|
58 | 102 | [](https://bitdeli.com/free "Bitdeli Badge")
|
59 |
| - |
|
0 commit comments