0.1.32 change buble up events to 'connection:socket' and 'connection:consumer'

master
David Kebler 2019-12-05 15:32:14 -08:00
parent 2d552bc6c1
commit 741823cce4
2 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci/base",
"version": "0.1.31",
"version": "0.1.32",
"description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes",
"main": "src/base",
"scripts": {
@ -34,13 +34,13 @@
"chai": "^4.2.0",
"esm": "^3.2.25",
"mocha": "^6.2.2",
"nodemon": "^2.0.0"
"nodemon": "^2.0.1"
},
"dependencies": {
"@uci-utils/bind-funcs": "^0.2.4",
"@uci-utils/logger": "^0.0.16",
"@uci/mqtt": "^0.1.13",
"@uci/socket": "^0.2.22",
"@uci/socket": "^0.2.26",
"@uci/websocket": "^0.3.10",
"await-to-js": "^2.1.1",
"p-reflect": "^2.1.0",

View File

@ -129,7 +129,7 @@ class Base extends EventEmitter {
async init(sockets) {
// Object.getPrototypeOf(Object.getPrototypeOf(this).init.call(this,sockets))
this.socketsInit(sockets)
return this.socketsInit(sockets)
// can do other init stuff here
}
@ -168,7 +168,9 @@ class Base extends EventEmitter {
if (typeof sockets ==='string') sockets = [sockets]
// console.log('sockets to initialize',sockets)
sockets.forEach(name => {
inits.push({name:name, init:this.getSocketInit(name)})
if (this._socket[name]) {
inits.push({name:name, init:this.getSocketInit(name)})
} else log.warn({msg:`no socket registered by name of ${name} to initialize`})
})
// console.log('starting promise',results,errors)
let [err] = await to(Promise.all(inits.map(initialize)))
@ -182,7 +184,7 @@ class Base extends EventEmitter {
// support old name for now
async addSocket(name,type,transport,options) {
this.registerSocket(name,type,transport,options)
return this.registerSocket(name,type,transport,options)
}
@ -230,7 +232,7 @@ class Base extends EventEmitter {
this._socket[name]._packetProcess = this._packetProcess.bind(this, name)
// bubble up events from sockets to instance
const EVENTS=['status','consumer-connection'] // that should emit up from socket to instance
const EVENTS=['log','connection','connection:consumer', 'connection:socket'] // that should emit up from each socket to instance
EVENTS.forEach(event => {
this._socket[name].on(event, obj => {
if (Object.prototype.toString.call(obj) !== '[object Object]') {
@ -300,6 +302,10 @@ class Base extends EventEmitter {
getSocketInit(name) {
let socket = this._socket[name]
if(!socket) {
log.warn({msg:`can't fetch create/connect function, no socket registered by name of ${name}`})
return null
}
if (this._socket[name].type === 's' && this._socket[name].transport !== 'm') {
return socket.create
} else {