wrapper to WS client that try reconnect to server when disconnect by any reasone
npm install reconnecting-ws
npm install --save reconnecting-ws
`
Using
`typescript
import { WebSocketClient } from 'reconnecting-ws';
class SocketClient {
private webSocketClient: WebSocketClient;
constructor() {
/**
* Init WebSocketClient
* Set trying reconnect when connection lost each 5 seconds, and show console message
*/
this.webSocketClient = new WebSocketClient(5000, true);
/* Subscribe to emitters. /
this.webSocketClient.on('open', this.onOpen);
this.webSocketClient.on('error', this.onError);
this.webSocketClient.on('message', this.onMessage);
this.webSocketClient.on('close', this.onClose);
this.webSocketClient.on('reconnect', this.onReconnect);
/* Connect to server. /
this.webSocketClient.connect('ws://127.0.0.1:3001');
/**
* Its possible to access WebSocket instance directly.
For real example see example` folder.