diff --git a/package.json b/package.json index 13d8ee2..d4352ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/base", - "version": "0.1.29", + "version": "0.1.30", "description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes", "main": "src/base", "scripts": { diff --git a/src/base.js b/src/base.js index c3e4484..4236e61 100644 --- a/src/base.js +++ b/src/base.js @@ -23,7 +23,7 @@ import EventEmitter from 'events' // Internal dependencies import { processor, defaultCmds, namespaces } from './processing' -// Useful Constants +// Constants const SOCKET_INFO_KEYS = ['name', 'type', 'transport'] const TRANSLATE = { n: 'Named Pipe', @@ -167,6 +167,7 @@ class Base extends EventEmitter { break case 'm': if (type === 'p') type = 'c' + options.client = type==='c' ? true : false options.connect = options.connect || {} if (options.host) options.connect.host = options.host if (options.port) options.connect.port = options.port @@ -183,10 +184,18 @@ class Base extends EventEmitter { this._socket[name].transport = transport this._socket[name]._packetProcess = this._packetProcess.bind(this, name) - // bubble up events from sockets - this._socket[name].on('status', ev => { - ev.socketName=name - this.emit('status', ev) + // bubble up events from sockets to instance + const EVENTS=['status','consumer-connection'] // that should emit up from socket to instance + EVENTS.forEach(event => { + this._socket[name].on(event, obj => { + if (Object.prototype.toString.call(obj) !== '[object Object]') { + let data=obj + obj = {} + obj.data = data + } + obj.socketName = name + this.emit(event,obj) + }) }) if (type==='c') {