Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ws-events-and-middlewares

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws-events-and-middlewares - npm Package Compare versions

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

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc