0.1.41 Fix bug in consumerConnected Method
parent
ddd7556c3f
commit
709b3e0fbc
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@uci/base",
|
||||
"version": "0.1.40",
|
||||
"version": "0.1.41",
|
||||
"description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes",
|
||||
"main": "src/base",
|
||||
"scripts": {
|
||||
|
|
12
src/base.js
12
src/base.js
|
@ -516,14 +516,12 @@ class Base extends EventEmitter {
|
|||
|
||||
// a call to this method will (make or add) return and or subscribe a ready observer for incoming consumer connections
|
||||
consumerConnected (socket,opts={}) {
|
||||
let { subscribe, consumer, add} = opts
|
||||
let { subscribe, consumer, name, add} = opts
|
||||
|
||||
const conditionHandler = async ev => {
|
||||
if ((ev||{}).state ==='connected'){
|
||||
let data = (ev.data ||{})
|
||||
console.log('connected: data from consumer',data)
|
||||
if (consumer) {
|
||||
console.log('observing for a particular consumer',opts.consumer)
|
||||
if (data.name === consumer || [ev.name, ev.id, data.name, data.id].some(name => (name||'').includes(consumer)) ) return true
|
||||
} else return true
|
||||
}
|
||||
|
@ -531,10 +529,12 @@ class Base extends EventEmitter {
|
|||
}
|
||||
if (typeof socket ==='string') socket = this.getSocket(socket)
|
||||
|
||||
const create = add ? 'addObserver' : 'makeObserver'
|
||||
name = name || consumer
|
||||
add = add && consumer
|
||||
const options = {event:'connection:consumer',condition:conditionHandler}
|
||||
|
||||
const obs = this.ready[create](socket,{event:'connection:consumer',condition:conditionHandler})
|
||||
if (subscribe) return obs.subscribe(typeof subscribe==='function' ? subscribe : console.log)
|
||||
const obs = add ? this.ready.addObserver(`${name}:consumer:inbound`,socket,options) : this.ready.makeObserver(socket,options)
|
||||
if (typeof subscribe ==='function') return obs.subscribe(subscribe)
|
||||
return obs
|
||||
} // end consumerConnected
|
||||
|
||||
|
|
Loading…
Reference in New Issue