0.1.41 Fix bug in consumerConnected Method

master
David Kebler 2020-01-21 18:38:11 -08:00
parent ddd7556c3f
commit 709b3e0fbc
2 changed files with 7 additions and 7 deletions

View File

@ -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": {

View File

@ -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