ws-events-and-middlewares
Advanced tools
Comparing version 1.0.19 to 1.0.20
34
index.js
@@ -17,3 +17,2 @@ const Emitter = require('component-emitter') | ||
var onopenHandlers = [] | ||
let mySocketId = null | ||
@@ -58,5 +57,5 @@ async function onmessage (event) { | ||
function onerror (err) { | ||
delete clients[mySocketId] | ||
delete clients[sock.id] | ||
Object.keys(rooms).map(room => { | ||
const index = rooms[room].indexOf(mySocketId) | ||
const index = rooms[room].indexOf(sock.id) | ||
if (index > -1) { | ||
@@ -75,2 +74,3 @@ rooms[room].splice(index, 1) | ||
onopenHandlers = [] // Limpiamos los eventos pendientes | ||
clients[sock.id] = sock | ||
listeners.emit('open') | ||
@@ -90,5 +90,5 @@ } | ||
function onclose (event) { | ||
delete clients[mySocketId] | ||
delete clients[sock.id] | ||
Object.keys(rooms).map(room => { | ||
const index = rooms[room].indexOf(mySocketId) | ||
const index = rooms[room].indexOf(sock.id) | ||
if (index > -1) { | ||
@@ -137,3 +137,3 @@ rooms[room].splice(index, 1) | ||
} | ||
rooms[room].push(mySocketId) | ||
rooms[room].push(sock.id) | ||
} | ||
@@ -146,3 +146,3 @@ | ||
const index = rooms[room].indexOf(mySocketId) | ||
const index = rooms[room].indexOf(sock.id) | ||
if (index > -1) { | ||
@@ -155,3 +155,3 @@ rooms[room].splice(index, 1) | ||
Object.keys(rooms).map(room => { | ||
const index = rooms[room].indexOf(mySocketId) | ||
const index = rooms[room].indexOf(sock.id) | ||
if (index > -1) { | ||
@@ -199,21 +199,3 @@ rooms[room].splice(index, 1) | ||
// Generamos un id para el socket solo si estamos en el servidor y guardamos el socket como cliente, en el cliente no es necesario | ||
if (typeof module !== 'undefined' && module.exports) { | ||
console.log('[ws-events] Se ha conectado un nuevo usuario') | ||
let found = false | ||
while (!found) { | ||
const id = uuidv4() | ||
if (!clients[id]) { | ||
found = true | ||
events.id = id | ||
clients[id] = events | ||
mySocketId = id | ||
} | ||
} | ||
} | ||
return events | ||
} |
{ | ||
"name": "ws-events-and-middlewares", | ||
"version": "1.0.19", | ||
"version": "1.0.20", | ||
"description": "ws module wrapper to provide events", | ||
@@ -27,5 +27,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"component-emitter": "^1.2.1", | ||
"uuid": "^3.3.2" | ||
"component-emitter": "^1.2.1" | ||
} | ||
} |
1
9553
168
- Removeduuid@^3.3.2
- Removeduuid@3.4.0(transitive)