ws-events-and-middlewares
Advanced tools
Comparing version 1.0.8 to 1.0.9
13
index.js
@@ -11,2 +11,3 @@ const Emitter = require('component-emitter') | ||
let rooms = {} | ||
let clients = {} | ||
@@ -17,2 +18,5 @@ module.exports = function wsEvents (sock, middlewares = []) { | ||
// Guardamos el nuevo cliente | ||
clients[sock.id] = sock | ||
async function onmessage (event) { | ||
@@ -79,3 +83,3 @@ var json, args | ||
function onclose (event) { | ||
// TODO: sacamos el cliente | ||
if (clients[sock.id]) delete clients[sock.id] | ||
listeners.emit('close', event) | ||
@@ -156,3 +160,8 @@ } | ||
emit: function () { | ||
const args = Array.from(arguments) | ||
if (!Array.isArray(rooms[room])) { return } | ||
rooms[room].map(socketId => { | ||
console.log('Emitiendo mensaje el socket ' + socketId + 'por estar en la sala ' + room) | ||
clients[socketId].emit.apply(clients[socketId], args) | ||
}) | ||
} | ||
@@ -159,0 +168,0 @@ } |
{ | ||
"name": "ws-events-and-middlewares", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "ws module wrapper to provide events", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9371
154