promisifiedwebsocket

1.1.0 • Public • Published

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')
})

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i promisifiedwebsocket

    Weekly Downloads

    2

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    4.99 kB

    Total Files

    4

    Last publish

    Collaborators

    • jeffreydavidsz