https://github.com/gamestdio/websocket
WebSocket client with reconnect back-off feature. Works in the browser, Node.js and React Native.
https://github.com/gamestdio/websocket
react-native websockets
Last synced: 11 months ago
JSON representation
WebSocket client with reconnect back-off feature. Works in the browser, Node.js and React Native.
- Host: GitHub
- URL: https://github.com/gamestdio/websocket
- Owner: gamestdio
- License: mit
- Created: 2015-11-18T01:26:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T17:49:36.000Z (almost 7 years ago)
- Last Synced: 2025-06-21T19:40:54.690Z (12 months ago)
- Topics: react-native, websockets
- Language: JavaScript
- Homepage:
- Size: 88.9 KB
- Stars: 64
- Watchers: 5
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @gamestdio/websocket
WebSocket with reconnect back-off feature.
For Node.js support, you should install the `ws` module in your project.
## Installation
`npm i @gamestdio/websocket`
## Usage
`WebSocketClient` behaves exactly in the same way as `WebSocket`.
It accepts an optional third parameter, which is used to configure
[backoff](https://github.com/MathieuTurcotte/node-backoff) feature.
```javascript
// fibonacci backoff strategy
var conn = new WebSocketClient('ws://' + host + ':8080', [], {
backoff: "fibonacci"
});
```
```javascript
// exponential backoff strategy
var conn = new WebSocketClient('ws://' + host + ':8080', [], {
backoff: "exponential"
});
```
## Event Listeners
- onclose
- onerror
- onmessage
- onopen
- onreconnect
## License
MIT