Skip to content

vovchisko/wse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

272 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WSE - WebSocket Everywhere!

npm version License: MIT Made in Ukraine

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 wse

Example

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! 🖕

About

WebSocket wrapper with authorization and customizable protocol

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors