ws-events-and-middlewares
Advanced tools
Comparing version 1.0.5 to 1.0.6
52
index.js
@@ -10,2 +10,3 @@ const Emitter = require('component-emitter') | ||
let callbacks = {} | ||
let rooms = {} | ||
@@ -77,2 +78,3 @@ module.exports = function wsEvents (sock, middlewares = []) { | ||
function onclose (event) { | ||
// TODO: sacamos el cliente | ||
listeners.emit('close', event) | ||
@@ -113,2 +115,48 @@ } | ||
function join (room) { | ||
console.log(`[ws-events] join: ${room}`) | ||
if (!Array.isArray(rooms[room]) { | ||
rooms[room] = [] | ||
} | ||
rooms[room].push(socket.id) | ||
console.log('rooms:') | ||
console.log(JSON.stringify(rooms, null, 2)) | ||
} | ||
function leave (room) { | ||
console.log(`[ws-events] leave: ${room}`) | ||
if (!Array.isArray(rooms[room]) { | ||
return | ||
} | ||
const index = rooms[room].indexOf(socket.id) | ||
if (index > -1) { | ||
rooms[room].splice(index, 1) | ||
} | ||
console.log('rooms:') | ||
console.log(JSON.stringify(rooms, null, 2)) | ||
} | ||
function leaveAll () { | ||
console.log(`[ws-events] leaveAll`) | ||
Object.keys(rooms).map(room => { | ||
const index = rooms[room].indexOf(socket.id) | ||
if (index > -1) { | ||
rooms[room].splice(index, 1) | ||
} | ||
}) | ||
console.log('rooms:') | ||
console.log(JSON.stringify(rooms, null, 2)) | ||
} | ||
function to (room) { | ||
return { | ||
emit: function () { | ||
} | ||
} | ||
} | ||
var events = Object.create(sock) | ||
@@ -121,2 +169,6 @@ events.socket = sock | ||
events.hasListeners = listeners.hasListeners.bind(listeners) | ||
events.join = join | ||
events.leave = leave | ||
events.leaveAll = leaveAll | ||
events.to = to | ||
@@ -123,0 +175,0 @@ return events |
{ | ||
"name": "ws-events-and-middlewares", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"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
9007
146