https://github.com/rxnew/socket8-js
It is a wrapper for using WebSocket client of JavaScript more conveniently.
https://github.com/rxnew/socket8-js
javascript websocket
Last synced: 12 months ago
JSON representation
It is a wrapper for using WebSocket client of JavaScript more conveniently.
- Host: GitHub
- URL: https://github.com/rxnew/socket8-js
- Owner: rxnew
- License: mit
- Created: 2019-03-05T20:17:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-05T21:10:27.000Z (over 7 years ago)
- Last Synced: 2025-06-22T15:44:40.378Z (about 1 year ago)
- Topics: javascript, websocket
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket8-js
It is a wrapper for using WebSocket client of JavaScript more conveniently.
socket8-js has the following functions.
- When the connection is disconnected, it will automatically reconnect
- When sending before connection or after disconnection, data is queued and waits for connection completion
## How to use
```javascript
sock = new Socket8('ws://localhost:8081', ['echo-protocol']);
sock.onopen(() => console.info('Connected.'));
sock.onclose(() => console.info('Closed.'));
sock.onerror(() => console.info('Error.'));
sock.onmessage(e => console.info(e.data);
sock.send('hello');
```
## How to run sample
```sh
$ npm install --save-dev
$ npm start
```
Open http://localhost:8080 in your web browser.