reconnecting-websocket
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
70067
15
717
0
0
91
0
6