0.8.1 • Published 3 years ago

wsrecon v0.8.1

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

Reconnecting Websocket

Implementation of an isomorphic automatically reconnecting websocket client.

Message format is JSON. Works perfectly with Node.js servers, script or Server Side Rendering.

Install

npm i wsrecon

Usage

The client wraps the normal WebSocket browser client or uses the ws Node.js client if not in the browser.

const client = require('wsrecon')

// Awaits the connection ready
const socket = await client('ws://localhost:6000', {
  // Reconnect timeout in ms, set to false to not automatically reconnect
  timeout: 1
})

// Register events like this
socket.on('open', (event) => {
  console.log('Connection open')
})

socket.on('close', (event) => {
  console.log('Connection closed')
})

socket.on('error', (event) => {
  console.log('Connection error')
})

socket.on('message', (data, event) => {
  console.log('Received message', data)
})

// Send message, data arrives in message event
socket.send({ hello: 'socket' })

MIT licensed. Enjoy!

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

4 years ago

0.5.3

4 years ago

0.5.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago