@jacekpietal/bouncer.js v3.0.3
@jacekpietal/bouncer.js
(ノಠ益ಠ)ノ
"you shall not pass"
web-sockets micro-service manager and static files server at the same port
- using
express
+socket.io
- or
uWebSockets.js
Install
Express + socket.io variant
$ yarn add @jacekpietal/bouncer.js express socket.io
MicroWebSockets variant
$ yarn add @jacekpietal/bouncer.js uWebSockets.js@github:uNetworking/uWebSockets.js#v20.6.0
Running
$ [PORT=4200] yarn bouncer.js folder [--express] [--uws] [--debug] [--plugin path/to/file.js]
PORT=4200
- choose server portfolder
- folder you want to server static files from--express
- optional parameter to start express + socket.io variant--uws
- optional parameter to start microwebsockets variant--debug
- show logs--plugin path/to/file.js
- path toWSPlugin
, can use multiple times
Demos
https://github.com/Prozi/bouncer.js/tree/master/demo
$ git clone https://github.com/Prozi/bouncer.js
$ cd bouncer.js
$ yarn
Express + socket.io variant
$ yarn add express socket.io
$ yarn express
MicroWebSockets variant
$ yarn add uWebSockets.js@github:uNetworking/uWebSockets.js#v20.6.0
$ yarn uws
then visit http://localhost:4200
Flow
STEP 1: Before Connection
- client -> connects websocket to
bouncer
server onwebsocket
protocol - server -> waits for
join
event (which is defined inconfig.join
)
STEP 2: Connection
- client -> sends
join
event with room name (topic/plugin name) - server -> if such plugin is configured joins client to that plugin
- server -> broadcasts to all of that room that client has joined
STEP 3: After Connection
- client -> does some actions (emits, receives)
- server -> plugin responds to websocket actions
STEP 4: Finish Connection
- client -> disconnects after some time
- server -> broadcasts to all people from room that client left (
config.leave
)
Plugins
- plugin example used in chat demo: https://github.com/Prozi/bouncer.js/blob/master/src/echo.ts
- To handshake a plugin in bouncer you need to send from your connected client something with similar payload:
{ "event": "/join", "data": "pluginName" }
- a plugin is a function
(ws, { id, event, data })
that is called each time the frontend websocket emits to server - context (
this
) of each plugin is thebouncer
instance. - plugins receive (and send) the data in the format of:
{
id, // WebSocket id - this is automatically added
event, // event name as string
data, // any data accompanying the event
}
License
MIT
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago