# resilient-ws

> A resilient websocket client for Node.js and the browser. Provides automatic reconnection, message retries, ping/pong & message queueing.

Latest version **0.0.16** (published 2024-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install resilient-ws
pnpm add resilient-ws
yarn add resilient-ws
bun add resilient-ws
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.16 |
| Published | 2024-02-18 |
| First published | 2023-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Bilal Afzal |
| Maintainers | bilalafzal01 |
| Keywords | websocket, client, reconnecting, reconnection, reconnect, forever, persistent, forever, automatic |

## Links

- npm: https://www.npmjs.com/package/resilient-ws
- Repository: https://github.com/bilalafzal01/resilient-ws
- Homepage: https://github.com/bilalafzal01/resilient-ws/tree/main#readme
- Issues: https://github.com/bilalafzal01/resilient-ws/issues
- npm.io page: https://npm.io/package/resilient-ws

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.16 (latest) — 2024-02-18
- 0.0.15 — 2023-10-31
- 0.0.14 — 2023-10-31
- 0.0.13 — 2023-10-31
- 0.0.12 — 2023-10-31
- 0.0.11 — 2023-10-31
- 0.0.10 — 2023-10-31
- 0.0.9 — 2023-10-31
- 0.0.8 — 2023-10-27
- 0.0.7 — 2023-10-27
- 0.0.6 — 2023-10-27
- 0.0.5 — 2023-10-27
- 0.0.4 — 2023-10-27
- 0.0.3 — 2023-10-27
- 0.0.2 — 2023-10-27
- … 1 more at https://npm.io/package/resilient-ws/versions

## README

[![npm version](https://badge.fury.io/js/resilient-ws.svg)](https://badge.fury.io/js/resilient-ws)

# 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

```bash
npm install resilient-ws
```

OR

```bash
yarn add resilient-ws
```

OR

```bash
pnpm add resilient-ws
```

## Usage

```js
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.

```js
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.

```js
import { ResilientWS } from 'resilient-ws'

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

---
_Source: https://npm.io/package/resilient-ws · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
