3.2.1 • Published 3 years ago

wsduck v3.2.1

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

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();