wse
v4.10.1
Published
Suspicious wrapper for websocket with auth and custom protocol support.
Maintainers
Readme
WSE - WebSocket Everywhere!
WSE (WebSocket Everywhere!) is a lightweight WebSocket wrapper that provides authentication, RPC support, and multi-device messaging.
Goes with client for NodeJS/Browser, and NodeJS server.
Fastify/Express/HTTP-server friendsly - can be easily mixed with regular web-api without dedicated ws port.
Why?
Just wanted RPC-like api without brokers and routers.
Installation
npm install wseExample
import { WseServer, WseClient } from 'wse'
// Server
const server = new WseServer({
port: 4200,
identify: ({ accept }) => accept('user-' + Date.now())
})
server.channel.on('chat', (conn, message) => {
server.broadcast('chat', { user: conn.cid, message })
})
server.register('ping', () => 'pong')
// Client
const client = new WseClient({ url: 'ws://localhost:4200' })
await client.connect()
client.send('chat', 'Hello world!')
const result = await client.call('ping')
console.log(result) // 'pong'Documentation
Yes, it's all here, Docs and API Reference.
Have fun! ❤️
License
MIT License - Do whatever you like.
Russian warship - go fuck yourself! 🖕
