@hanseltime/jsp-ws-connection
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

jsp-ws-connection

This library is for specfic implementaions of the janus-simple-command package's Connection interface that uses the ws websocket library.

Currently supported

  • Node

Node usage example

yarn add @hanseltime/janus-simple-command @hanseltime/jsp-ws-connection
import { NodeWebSocketConnection } from '@hanseltime/jsp-ws-connection'
import { HandlerReturn, Server } from '@hanseltime/janus-simple-command'

const app = express()

const server = app.listen(PORT)
const wss = new WebSocketServer({
  server: server,
  path: process.env.ROOT_PATH ?? '/',
})

let serv: Server<Commands, CommandMap, StatusMap> | undefined = undefined
wss.on('connection', async (ws) => {
  debug('INFO', 'ws connected')
  const connection = new NodeWebSocketConnection(ws, 'server', console.log)

  serv = new Server<Commands, CommandMap, StatusMap>({
    maxSenderInactivity: 10000,
    maxAckRetries: 3,
    ackRetryDelay: 10000,
    connection,
    debug: (msg: string) => console.log(msg),
  })

  serv.setMessageHandlerWithIntermediate('cmd', {
    handler: async (msg, inter): Promise<HandlerReturn<StatusMap['cmd']>> => {
      runbot(msg)
    },
  })

  await serv.open()
})

See JSP Readme for more

https://github.com/hanseltime/hanseltime-janus-simple-command/tree/master/packages/janus-simple-command#usage

Readme

Keywords

none

Package Sidebar

Install

npm i @hanseltime/jsp-ws-connection

Weekly Downloads

2,088

Version

1.0.1

License

none

Unpacked Size

37.4 kB

Total Files

12

Last publish

Collaborators

  • hanseltime