3.0.3 • Published 2 years ago

@jacekpietal/bouncer.js v3.0.3

Weekly downloads
77
License
MIT
Repository
github
Last release
2 years ago

@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 port
  • folder - 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 to WSPlugin, 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 on websocket protocol
  • server -> waits for join event (which is defined in config.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

{ "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 the bouncer 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

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.27.1

3 years ago

2.27.0

3 years ago

2.26.2

3 years ago

2.26.1

3 years ago

2.26.0

3 years ago

2.25.0

3 years ago

2.25.2

3 years ago

2.25.1

3 years ago

2.24.1

3 years ago

2.24.0

3 years ago

2.23.0

3 years ago

2.22.5

3 years ago

2.22.4

3 years ago

2.22.3

3 years ago

2.22.2

3 years ago

2.21.4

3 years ago

2.21.3

3 years ago

2.21.5

3 years ago

2.20.3

3 years ago

2.22.1

3 years ago

2.22.0

3 years ago

2.21.0

3 years ago

2.21.2

3 years ago

2.21.1

3 years ago

2.19.0

3 years ago

2.19.1

3 years ago

2.20.2

3 years ago

2.20.0

3 years ago

2.20.1

3 years ago

2.18.1

4 years ago

2.18.0

4 years ago

2.17.8

4 years ago

2.17.7

4 years ago

2.17.6

4 years ago

2.17.4

4 years ago

2.17.5

4 years ago

2.17.3

4 years ago

2.17.2

4 years ago

2.17.1

4 years ago

2.17.0

4 years ago

2.16.0

4 years ago

2.15.0

4 years ago

2.14.1

4 years ago

2.14.0

4 years ago

2.13.0

4 years ago

2.12.0

4 years ago

2.11.0

4 years ago

2.10.1

4 years ago

2.10.2

4 years ago

2.10.0

4 years ago

2.9.0

4 years ago

2.8.6

4 years ago

2.10.3

4 years ago

2.10.4

4 years ago

2.8.5

4 years ago

2.8.4

4 years ago

2.8.3

4 years ago

2.8.2

4 years ago

2.8.1

4 years ago

2.8.0

4 years ago

2.7.0

4 years ago

2.7.1

4 years ago

2.6.7

4 years ago

2.6.6

4 years ago

2.6.5

4 years ago

2.6.3

4 years ago

2.6.4

4 years ago

2.6.1

4 years ago

2.6.2

4 years ago

2.6.0

4 years ago

2.5.5

4 years ago

2.5.4

4 years ago

2.5.3

4 years ago

2.5.2

4 years ago

2.5.1

4 years ago

2.5.0

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.4.2

4 years ago

2.3.0

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.9

4 years ago

2.3.12

4 years ago

2.3.14

4 years ago

2.3.11

4 years ago

2.3.10

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago