import ReopeningWebSocket from 'reopening-websocket/src/ReopeningWebSocket.js'
ReopeningWebSocket
Extends:
Implements:
Automatically reopening WebSocket
Test:
Constructor Summary
Public Constructor | ||
public |
constructor(url: String, protocols: String | String[]) Creates a new ReopeningWebSocket |
Member Summary
Public Members | ||
public |
An event listener to be called on reopen. |
|
public |
An event listener to be called on each reopen attempt. |
|
public |
How many times a reopen happened without success. |
Method Summary
Public Methods | ||
public |
addEventListener(type: String, listener: EventListener, options: Boolean | Object) Register an event handler of a specific type. |
|
public |
Closes the WebSocket connection or connection attempt, if any. |
|
public |
dispatchEvent(event: Event) Dispatches an Event. |
|
public |
removeEventListener(type: String, listener: EventListener) Removes an event listener registed with ReopeningWebSocket#addEventListener. |
|
public |
reopen() Reopens the WebSocket connection. |
|
public |
send(data: String | ArrayBuffer | Blob) Transmits data to the server |
Public Constructors
Public Members
Public Methods
public addEventListener(type: String, listener: EventListener, options: Boolean | Object) source
Register an event handler of a specific type.
Params:
Name | Type | Attribute | Description |
type | String | The event to listen for. |
|
listener | EventListener | The function to call when the event occures. |
|
options | Boolean | Object |
|
Specifies characteristics of the listener. |
options.once | Boolean |
|
Only call the listener once. |
public close(code: Number, reason: String) source
Closes the WebSocket connection or connection attempt, if any.
Note that after calling this method the connection will not reopen automatically any more. Call ReopeningWebSocket#reopen to reopen it.
Example:
const ws = new ReopeningWebSocket('ws://example.com');
...
ws.close();
// At this point the connection will not no longer automatically reopen
ws.reopen();
// At this point automatic reopening is re-enabled.
public dispatchEvent(event: Event) source
Dispatches an Event.
Params:
Name | Type | Attribute | Description |
event | Event | The event to dispatch. |
public removeEventListener(type: String, listener: EventListener) source
Removes an event listener registed with ReopeningWebSocket#addEventListener.
Params:
Name | Type | Attribute | Description |
type | String | The event to listen for. |
|
listener | EventListener | The function to call when the event occures. |
public send(data: String | ArrayBuffer | Blob) source
Transmits data to the server
Params:
Name | Type | Attribute | Description |
data | String | ArrayBuffer | Blob | The data to transmit. |