ws-events-and-middlewares
Advanced tools
Comparing version 1.0.13 to 1.0.14
24
index.js
@@ -78,3 +78,3 @@ const Emitter = require('component-emitter') | ||
function onclose (event) { | ||
if (clients[sock.id]) delete clients[sock.id] | ||
delete clients[sock.id] | ||
listeners.emit('close', event) | ||
@@ -117,3 +117,2 @@ } | ||
function join (room) { | ||
console.log(`[ws-events] join: ${room}`) | ||
if (!Array.isArray(rooms[room])) { | ||
@@ -126,3 +125,2 @@ rooms[room] = [] | ||
function leave (room) { | ||
console.log(`[ws-events] leave: ${room}`) | ||
if (!Array.isArray(rooms[room])) { | ||
@@ -139,3 +137,2 @@ return | ||
function leaveAll () { | ||
console.log(`[ws-events] leaveAll`) | ||
Object.keys(rooms).map(room => { | ||
@@ -154,6 +151,3 @@ const index = rooms[room].indexOf(sock.id) | ||
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) | ||
}) | ||
rooms[room].map(socketId => clients[socketId].emit.apply(clients[socketId], args)) | ||
} | ||
@@ -163,2 +157,11 @@ } | ||
function toAll () { | ||
return { | ||
emit: function () { | ||
const args = Array.from(arguments) | ||
Object.keys(clients).map(socketId => clients[socketId].emit.apply(clients[socketId], args) ) | ||
} | ||
} | ||
} | ||
var events = Object.create(sock) | ||
@@ -174,9 +177,8 @@ events.emit = emit | ||
events.to = to | ||
events.toAll = toAll | ||
// Guardamos el nuevo cliente | ||
// Guardamos el nuevo cliente | ||
clients[sock.id] = events | ||
console.log('Nuevo cliente conectado:') | ||
console.log(JSON.stringify(clients)) | ||
return events | ||
} |
{ | ||
"name": "ws-events-and-middlewares", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"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
152
9160