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.2 to 1.0.3

29

index.js

@@ -1,2 +0,3 @@

var Emitter = require('component-emitter')
const Emitter = require('component-emitter')
const uuidv4 = require('uuid/v4')

@@ -10,2 +11,3 @@ callbackCounter = 0

let callbacks = {}
let clients = {}

@@ -58,12 +60,27 @@ module.exports = function wsEvents (sock, middlewares = []) {

function onopen () {
// Generamos un id aleatorio
let found = false
while(!found) {
const id = uuidv4()
// Si no existe ningun cliente con este id lo guardamos
if (!clients[id]) {
found = true
sock.id = id
clients[id] = sock // Guardamos el cliente en 'la base de datos'
}
}
// Procesamos todos los eventos pendientes emitidos antes de estar realemnte conectados
onopenHandlers.forEach(function (fn) {
fn()
})
onopenHandlers = []
onopenHandlers = [] // Limpiamos los eventos pendientes
}
function whenOpen (fn) {
// Comprobamos si estamos realmente conectados y ejecutamos la funcion dada
if (sock.readyState === sock.constructor.OPEN) {
fn()
} else {
// Si no estamos realmente conectados guardamos la funcion a ejecutar para lanzarla cuadno nos volvamos a conectar
onopenHandlers.push(fn)

@@ -73,6 +90,6 @@ }

function onclose (e) {
console.log('Onclose Arguments:')
console.log(arguments)
listeners.emit('close', e)
function onclose (event) {
// Eliminamos el cliente de 'la base de datos'
delete clients[sock.id]
listeners.emit('close', event)
}

@@ -79,0 +96,0 @@

{
"name": "ws-events-and-middlewares",
"version": "1.0.2",
"version": "1.0.3",
"description": "ws module wrapper to provide events",

@@ -27,4 +27,5 @@ "main": "index.js",

"dependencies": {
"component-emitter": "^1.2.1"
"component-emitter": "^1.2.1",
"uuid": "^3.3.2"
}
}

@@ -69,7 +69,21 @@ # ws-events-and-middlewares

## Construyendo el servidor
## Instalando ws-events-and-middlewares
```js
npm install ws-events-and-middlewares --save
```
o
```js
yarn install ws-events-and-middlewares --save
```
## Construyendo el servidor con eventos
## Construyendo el cliente
## Construyendo el servidor con eventos y middlewares
### TODO list

@@ -76,0 +90,0 @@

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