0.1.30 add consumer connection bubble up listener for each socket
add mqtt s vs c optionmaster
parent
23ea81c9d9
commit
ec311b51df
|
@ -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": {
|
||||
|
|
19
src/base.js
19
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') {
|
||||
|
|
Loading…
Reference in New Issue