Function reconnectingWebsocket

Maintains a web socket connection. Connects automatically.

The essential usage is:

import { reconnectingWebsocket } from 'https://unpkg.com/ixfx/dist/io.js'
const ws = reconnectingWebsocket(`wss://somehost.com/ws`, {
onMessage: (msg) => {
// Do something with received message...
}
}

// Send some data
ws.send(JSON.stringify(someData));

// Check state of connection
ws.isConnected();

More options can be provided to monitor state

import { reconnectingWebsocket } from 'https://unpkg.com/ixfx/dist/io.js'
const ws = reconnectingWebsocket(`wss://somehost.com/ws`, {
onError: (err) => {
console.error(err)
},
onMessage: (msg) => {
// Received data
console.log(msg);
},
onConnected: () => {
// Connected!
},
onDisconnected: () => {
// Disconnected :(
}
});