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