0.0.16 • Published 3 months ago

resilient-ws v0.0.16

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

npm version

Resilient Websockets

  • automatic retries when the message cannot be sent (e.g. when the connection is lost)
  • ping/pong to keep the connection alive

Installation

npm install resilient-ws

OR

yarn add resilient-ws

OR

pnpm add resilient-ws

Usage

import { ResilientWS } from 'resilient-ws'

ResilientWS.create({
  url: '',
  onConnectCallback: () => {
    console.log(`Wow this is a websocket connection!`)
  },
  onDisconnectCallback: () => {
    console.log(`Wow this is a websocket disconnection!`)
  },
  onMessageCallback: (message) => {
    console.log(`Wow this is a websocket message!`, message)
  },
  onErrorCallback: (error) => {
    console.log(`Wow this is a websocket error!`, error)
  },
})

ResilientWS maintains a single instance. So you can import it anywhere and use it.

import { ResilientWS } from 'resilient-ws'

const ws = ResilientWS.getInstance()

ws.send({
    message: 'Hello World!'
    attempt: 0,
    forceReconnect: false,
})

Ping/Pong

By default, ping/pong is disabled. You can enable it by passing the config for ping/pong when creating your ResilientWS instance.

import { ResilientWS } from 'resilient-ws'

ResilientWS.create({
  ...config,
  pingPongSettings: {
    enabled: true
    pingInterval: 10000,
    pingMessage: 'ping',
  },
})
0.0.16

3 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago