wsDuck is a module that lets you send websockets into "ponds," kinda like channels.
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();