Skip to content
/ wscl Public

Simple WebSocket wrapper with some extra features

Notifications You must be signed in to change notification settings

farwayer/wscl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wscl

NPM version

Simple WebSocket wrapper with some extra features:

  • auto reconnect with exponential backoff strategy
  • wait connection before sending messages

Lib is small. Its size limited to 592 bytes (with all deps, minified and brotlied).

How to use

yarn add wscl
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")