0.0.2 • Published 3 years ago

@bhoos/websocket v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

websocket

Reliable Websocket Client Library

This library provides a reliable websocket connection. It sends heartbeats (pings), reconnects if connection is broken and also keeps a buffer for messages that were send while the connection is down and those messages are later sent when connection is up.

Use

import {ReliableWS} from '@bhoos/websocket'

const config = {
  PING_INTERVAL: 1000, // ms
  RECONNECT_INTERVAL: 5000, // ms
  MSG_BUFFER_SIZE: 20,
  PING_MESSAGE : 'ping'
}

const agent = new ReliableWS('ws://localhost:3030/subscribe/', config);

agent.send('Hi');

agent.onerror = (event) => {
  console.log("Error: ", event.message);
}

agent.onopen = (event) => {
  console.log("Opened!!");
}

agent.onmessage = (event) => {
  console.log(event.data);
};