2.1.3 • Published 11 months ago

chef-socket v2.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

chef-socket

web-sockets micro-service manager and static files server at the same port,

designed for node written in typescript, with tests

  • express for routing (and socket.io for websockets)

Command-Line Running

$ npx chef-socket folder [--debug] [--ssl] [--port 443] [--plugin path/to/plugin.js]

Installation

$ yarn add chef-socket

Minimal Chat Demo

https://chef-js-socket.herokuapp.com/

$ yarn add chef-socket
$ yarn chef-socket node_modules/chef-socket/demo --plugin node_modules/chef-core/chat.js

Minimal configuration is specifying folder, then it serves it from http://localhost:4200

const startServer = require("chef-socket");
const config = { folder: "docs" };

startServer(config).then((server: Express.Application) => {
  // server api is get, post, any
  server.any("/*", (req: Express.Request, res: Express.Response) => {
    res.end("200 OK");
  });
});

Configuration

For more information about config parameters read:

Plugins

The plugins are a mighty thing, think of them like chat rooms,

after a client handshakes the chat room, his messages start being forwarded to that room,

and it is being handled there by the room's own plugin.

This means you can have for example: a chat server and other unrelated websocket services

at the same port as the files server too. One client may be in many rooms.

STEP 1: Before Connection

  • client -> socket.io-client connects to location.origin.replace(/^http/, 'ws')
  • server -> waits for any incoming config.join events

STEP 2: Connection

  • client -> sends join event with room name (topic/plugin name)
  • server -> if such plugin is configured joins client to that plugin

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 plugins from room that client left (config.leave)

API

  • 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 server 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

1.5.1

11 months ago

1.5.0

11 months ago

2.1.2

11 months ago

2.1.1

11 months ago

2.1.3

11 months ago

2.1.0

11 months ago

2.0.0

11 months ago

1.4.0

1 year ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago