1.1.0 • Published 6 months ago

promisifiedwebsocket v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

PromisifiedWebSocket

This class is a wrapper for ws: a Node.js WebSocket library. It adds the following functionality:

Promise-based send method Event emitter for websocketOpen and websocketError Status event emitter

Install

// Using NPM
npm install promisifiedwebsocket
// Using YARN
yarn add promisifiedwebsocket

Then you can use the module

const PromisifiedWebSocket = require('promisifiedwebsocket')

const url = '127.0.0.1:1234/testPath' // Change this to your likes
const ws = new PromisifiedWebSocket(url)

You can use the send(data) & close();

const result = await ws.send('getFaderList')
console.log(`The result: ${result}`)
ws.close()

The following listeners are added:

ws.on('websocketError', (error) => {
    console.log(`WebSocket error: ${error}`)
})
ws.on('status', (status) => {
    // Statuses that will be emitted are: open & connaction closed
    console.log(`Status change: ${status}`)
})
ws.on('websocketOpen', () => {
    console.log('Connection open')
})
ws.on('websocketClose', () => {
    console.log('Connection closed')
})
1.1.0

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago