Skip to content

Commit abfb1fa

Browse files
committed
Improved the documentation, adding the automaticOpen option as well as describing the publicly available methods.
1 parent be51b4b commit abfb1fa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ or
7878
- Accepts `true` or `false`
7979
- Default value: `false`
8080

81+
#### `automaticOpen`
82+
- Whether or not the websocket should attempt to connect immediately upon instantiation. The socket can be manually opened or closed at any time using ws.open() and ws.close().
83+
- Accepts `true` or `false`
84+
- Default value: `true`
85+
8186
#### `reconnectInterval`
8287
- The number of milliseconds to delay before attempting to reconnect.
8388
- Accepts `integer`
@@ -95,6 +100,23 @@ or
95100

96101
---
97102

103+
## Methods
104+
105+
#### `ws.open()`
106+
- Open the Reconnecting Websocket
107+
108+
#### `ws.close(code, reason)`
109+
- Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing.
110+
- `code` is optional the closing code (default value 1000). [https://tools.ietf.org/html/rfc6455#section-7.4.1](https://tools.ietf.org/html/rfc6455#section-7.4.1)
111+
- `reason` is the optional reason that the socket is being closed. [https://tools.ietf.org/html/rfc6455#section-7.1.6](https://tools.ietf.org/html/rfc6455#section-7.1.6)
112+
113+
#### `ws.refresh()`
114+
- Refresh the connection if still open (close and then re-open it).
115+
116+
#### `ws.send(data)`
117+
- Transmits data to the server over the WebSocket connection.
118+
- Accepts @param data a text string, ArrayBuffer or Blob
119+
98120
Like this? Check out [websocketd](https://github.com/joewalnes/websocketd) for the simplest way to create WebSocket backends from any programming language.
99121

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

reconnecting-websocket.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
* debug
7777
* - Whether this instance should log debug messages. Accepts true or false. Default: false.
7878
*
79+
* automaticOpen
80+
* - Whether or not the websocket should attempt to connect immediately upon instantiation. The socket can be manually opened or closed at any time using ws.open() and ws.close().
81+
*
7982
* reconnectInterval
8083
* - The number of milliseconds to delay before attempting to reconnect. Accepts integer. Default: 1000.
8184
*

0 commit comments

Comments
 (0)