Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/farwayer/wscl
Simple WebSocket wrapper with some extra features
https://github.com/farwayer/wscl
reconnect socket websocket websocket-client ws wss
Last synced: 4 days ago
JSON representation
Simple WebSocket wrapper with some extra features
- Host: GitHub
- URL: https://github.com/farwayer/wscl
- Owner: farwayer
- Created: 2019-05-22T14:06:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T15:14:21.000Z (8 months ago)
- Last Synced: 2024-04-24T18:24:57.952Z (8 months ago)
- Topics: reconnect, socket, websocket, websocket-client, ws, wss
- Language: JavaScript
- Homepage:
- Size: 4.02 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## wscl
[![NPM version](https://img.shields.io/npm/v/wscl.svg)](https://www.npmjs.com/package/wscl)
Simple WebSocket wrapper with some extra features:
- auto reconnect with exponential backoff strategy
- wait connection before sending messagesLib is small. Its size [limited](https://github.com/ai/size-limit)
to **621 bytes** (with all deps, minified and brotlied).## How to use
```shell
yarn add wscl
``````js
import {Client, events} from 'wscl'const wsc = new Client({
url: 'wss://echo.websocket.org',
})wsc.on(events.Open, console.log)
wsc.on(events.Close, console.log)
wsc.on(events.Message, console.log) // will be called with data not event
wsc.on(events.Error, console.log) // will be called with error not event// you can send message before connect
wsc.send("message")await wsc.connect()
console.log(wsc.connected)wsc.close("reason")
```