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 dataws.send(JSON.stringify(someData));// Check state of connectionws.isConnected(); Copy
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 dataws.send(JSON.stringify(someData));// Check state of connectionws.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 :( }}); Copy
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 :( }});
Maintains a web socket connection. Connects automatically.
The essential usage is:
More options can be provided to monitor state