Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reconnecting-websocket

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reconnecting-websocket - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.npmignore

34

package.json
{
"name": "reconnecting-websocket",
"version": "1.0.0",
"version": "1.1.0",
"description": "Reconnecting WebSocket",
"main": "index.js",
"main": "build/index.js",
"scripts": {
"test": "ava"
"build": "tsc",
"test": "nyc ava --verbose --serial test/test.js",
"pretest": "npm run build",
"report": "nyc report --reporter=html && opn coverage/index.html"
},
"keywords": [
"websocket",
"client",
"reconnecting",
"reconnection",
"reconnect",
"forever",
"persistent",
"forever",
"automatic"
],
"author": "Pedro Ladaria <pedro.ladaria@gmail.com>",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"ava": "^0.15.2",
"html5-websocket": "^0.6.0",
"nyc": "^6.6.1",
"opn-cli": "^3.1.0",
"sinon": "^1.17.4",
"ws": "^1.1.1"
},
"dependencies": {},
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pladaria/reconnecting-websocket.git"
},
"bugs": {
"url": "https://github.com/pladaria/reconnecting-websocket/issues"
},
"homepage": "https://github.com/pladaria/reconnecting-websocket#readme"
}
# Reconnecting WebSocket
Work in progress
WebSocket that will automatically reconnect if the connection is closed.
# WORK IN PROGRESS
Please do not use for production :(
## Features
- Small (~150 LOC)
- WebSocket API compatible (same interface DOM1, DOM2 event model) - **WIP**
- Fully configurable
- Multiplatform (Web, ServiceWorkers, Node.js, React Native)
- Dependency free (does not depends on Window, DOM or any EventEmitter library)
- Reassign event listeners when a new WebSocket instance is created
- Automatic reconnection using rfc6455 guidelines
- Handle connection timeouts
- Full test coverage - **WIP**
- Debug mode
## Install
```bash
npm install --save reconnecting-websocket
```
## Usage
### Compatible with WebSocket Browser API
So this documentation should be valid: [MDN WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
Ping me if you find any problems. Or, even better, write a test for your case and make a pull request :)
### Simple usage
```javascript
const WebSocket = require('reconnecting-websocket');
const ws = new WebSocket('ws://my.site.com');
ws.addEventListener('open', () => {
ws.send('hello!');
});
```
### Configure
#### Default options
Options should be self explainatory
```javascript
const DEFAULT_OPTIONS = {
constructor: (typeof WebSocket === 'function') ? WebSocket : null,
maxReconnectionDelay: 10000,
minReconnectionDelay: 1500,
reconnectionDelayGrowFactor: 1.3,
connectionTimeout: 4000,
maxRetries: Infinity,
debug: false,
};
```
#### Sample with custom options
```javascript
const WebSocket = require('reconnecting-websocket');
const options = {connectionTimeout: 1000};
const ws = new WebSocket('ws://my.site.com', null, options);
```
#### Using alternative constructor
This way you can use this module in cli/testing/node.js or use a decorated/alternative WebSocket. The only requisite is that the given constructor must be compatible with the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
The example uses the [html5-websocket](https://github.com/pladaria/html5-websocket) module.
```javascript
const Html5WebSocket = require('html5-websocket');
const WebSocket = require('reconnecting-websocket');
const options = {constructor: Html5WebSocket};
const ws = new WebSocket('ws://my.site.com', null, options);
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc