websocket-reconnector
A wrapper to W3C WebSocket objects to seamlesly add reconnection feature.
Installation
$ npm install --save websocket-reconnector
Usage
const WebSocketReconnector = require('websocket-reconnector')
const ReconnectingWebSocket = WebSocketReconnector(WebSocket)
const client = ReconnectingWebsocket('ws://localhost')
client.onopen(() => client.send('Hello server'))
client.onmessage(event => console.log(`Message received: ${event.data}`))
API
The API is fully compatible with the W3C WebSocket API.
In addition, the following additional method is available:
client.reconnect()
Closes the underlying websocket instance and initiates a new connection.
License
MIT