1.0.51 • Published 3 years ago

wsbasic v1.0.51

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

wsBasic

wsBasic is a simple hook-on utility for ws.

Examples:

Server:

const WebSocket = require("ws"); /// require ws
const wss = new WebSocket.Server({ port: 8080, clientTracking: true }); /// define ws server
require("wsbasic")(wss); /// enable wsbasic

On connection:

/// gives a uuid for each client
wss.on('connection', function connection(ws) {
  console.log(ws.uuid); /// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
});

To specific UUID:

wss.on('connection', function connection(ws) {
  wss.sendToUUID('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'hello');
});

To client with specific attribute:

wss.on('connection', function connection(ws) {
  wss.sendToAttribute({"channel": "/"}, 'hello');
});

Channels:

wss.on('connection', function connection(ws) {
  ws.channel = "hello";
  wss.broadcast("hello", "hi"); // as you probably guessed, this will send a message to all clients in "hello"
});
1.0.51

3 years ago

1.0.5

3 years ago

1.0.401

3 years ago

1.0.40

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago