wsduck

3.2.1 • Public • Published

Ducky wsDuck is a module that lets you send websockets into "ponds," kinda like channels.

Examples

Attaching Ducky!

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);

Making a pond and connecting a websocket to it!

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);
var myPond = ducky.createPond();
wss.on('connection', function connection(ws) {
  myPond.connect(ws);
});

Listening for events on the pond!

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);
var myPond = ducky.createPond();
wss.on('connection', function connection(ws) {
  myPond.connect(ws);
});
pond.event.on("message", (message) => {
	console.log(message);
});
pond.event.on("disconnection", (ws) => {
	// awh.....
});

Properties of a duckling!

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);
var myPond = ducky.createPond();
wss.on('connection', function connection(ws) {
  var duckling = myPond.connect(ws);
  // duckling.ws (original websocket)
  duckling.disconnect();
});

Listing the ducklings!

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);
var myPond = ducky.createPond();
myPond.list(); // returns an object with values ws and disconnect (function)

Deleting the pond..

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080, clientTracking: true });
const ducky = require("wsducky")(wss);
var myPond = ducky.createPond();
myPond.destroy();

Readme

Keywords

Package Sidebar

Install

npm i wsduck

Weekly Downloads

1

Version

3.2.1

License

ISC

Unpacked Size

12.1 kB

Total Files

7

Last publish

Collaborators

  • drakexyz