Skip to content

Commit f7ac75b

Browse files
committed
Updated the documentation and the JS file header comment block. Added Parameters section with explanations. Added Options section with explanations, accepted and default values.
1 parent 12b94b3 commit f7ac75b

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
ReconnectingWebSocket
22
=====================
33

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.
75

86
It is API compatible, so when you have:
97

@@ -48,12 +46,57 @@ With a `ReconnectingWebSocket`, after an `onclose` event is called it will autom
4846

4947
This is all handled automatically for you by the library.
5048

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

5498
Like this? Check out [websocketd](https://github.com/joewalnes/websocketd) for the simplest way to create WebSocket backends from any programming language.
5599

56100
[Follow @joewalnes](https://twitter.com/joewalnes)
57101

58102
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/joewalnes/reconnecting-websocket/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
59-

reconnecting-websocket.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,41 @@
5050
*
5151
* Latest version: https://github.com/joewalnes/reconnecting-websocket/
5252
* - Joe Walnes
53+
*
54+
* Syntax
55+
* ======
56+
* var socket = new ReconnectingWebSocket(url, protocols, options);
57+
*
58+
* Parameters
59+
* ==========
60+
* url - The url you are connecting to.
61+
* protocols - Optional string or array of protocols.
62+
* options - See below
63+
*
64+
* Options
65+
* =======
66+
* Options can either be passed upon instantiation or set after instantiation:
67+
*
68+
* var socket = new ReconnectingWebSocket(url, null, { debug: true, reconnectInterval: 4000 });
69+
*
70+
* or
71+
*
72+
* var socket = new ReconnectingWebSocket(url);
73+
* socket.debug = true;
74+
* socket.reconnectInterval = 4000;
75+
*
76+
* debug
77+
* - Whether this instance should log debug messages. Accepts true or false. Default: false.
78+
*
79+
* reconnectInterval
80+
* - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
81+
*
82+
* reconnectDecay
83+
* - The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. Accepts integer or float. Default: 1.5.
84+
*
85+
* timeoutInterval
86+
* - The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. Accepts integer. Default: 2000.
87+
*
5388
*/
5489
(function (global, factory) {
5590
if (typeof define === 'function' && define.amd) {

0 commit comments

Comments
 (0)