# rwebsocket

> Simple auto-reconnect WebSocket decorator

Latest version **1.1.0** (published 2017-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install rwebsocket
pnpm add rwebsocket
yarn add rwebsocket
bun add rwebsocket
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-02-08 |
| First published | 2016-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maxime Tricoire |
| Maintainers | leiko |
| Keywords | websocket, ws, reconnect, auto, retry |

## Links

- npm: https://www.npmjs.com/package/rwebsocket
- Repository: https://github.com/maxleiko/rwebsocket
- Homepage: https://github.com/maxleiko/rwebsocket#readme
- Issues: https://github.com/maxleiko/rwebsocket/issues
- npm.io page: https://npm.io/package/rwebsocket

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^1.1.1
- [bufferutil](https://npm.io/package/bufferutil.md) ^1.3.0
- [utf-8-validate](https://npm.io/package/utf-8-validate.md) ^2.0.0

## 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

- 1.1.0 (latest) — 2017-02-08
- 1.0.2 — 2017-02-08
- 1.0.1 — 2016-12-20
- 1.0.0 — 2016-12-16
- 0.1.0 — 2016-12-16

## README

# rwebsocket [![Build Status](https://travis-ci.org/maxleiko/rwebsocket.svg?branch=master)](https://travis-ci.org/maxleiko/rwebsocket)
Simple auto-reconnect WebSocket adapter

### Install
```sh
npm i rwebsocket -S
```
or
```sh
yarn add rwebsocket
```

### Usage
```js
const RWebSocket = require('rwebsocket');

const client = new RWebSocket('ws://echo.websocket.org');

client.onopen = function () {
	// as soon as we are connected
	// just send an Hello World! to the server
	client.send('Hello World!');
};

client.onmessage = function (event) {
	// because the server is echo.websocket.org we should receive
	// "Hello World!" right after connection
	console.log('> ', event.data);
};

// connect
client.connect();
```

> If `ws://echo.websocket.org` is unreachable, RWebSocket will try to reconnect once every 3 seconds (default)

### API
The only modifications to the API are:
 - the ability to give a 3rd argument to the constructor to set the `retryInterval` in `ms`
 - the `#connect()` method to actually create a WebSocket and connect to the server

```js
const client = new RWebSocket('ws://echo.websocket.org', null, 25000);
```
> Reconnection attempts will be made once every 25 seconds  
> NB: the 'null' param is for the protocol because the constructor is the same as the [WebSocket RFC](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) + `retryInterval`

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