Commit 13c23373 by Chavee Issariyapat

use channelID to separate pub/sub group

parent 74489dc2
......@@ -18,7 +18,7 @@ let FlowAgent = function(option = {}) {
flowagentid : option.flowagentid,
flowagentsecret : option.flowagentsecret,
red : option.red || null,
namespace : option.namespace
channelID : option.channelID
}
if (this.option.red) {
......@@ -36,10 +36,11 @@ let FlowAgent = function(option = {}) {
host: that.option.broker_uri,
options: opt
});
console.log('flowagent.js --');
console.log(this.option)
let flowemitter = FlowEmitter.create({
red: this.option.red,
namespace: this.option.namespace
channelID: this.option.channelID
});
this.coordinator = Coordinatior.create({
......
......@@ -6,43 +6,46 @@ const FlowEmitter = function(param = {}) {
this.red = param.red; // node-red object
this.globalcontext = param.globalcontext;
this.events = new events.EventEmitter;
this.namespace = param.namespace; // namespace is for communicating with RED.events
this.channelID = param.channelID; // channelID is a namespace for communicating with RED.events
}
FlowEmitter.prototype.start = function() {
let that = this;
this.red.events.on(`${that.namespace}-registershadowlistener`, function(client) {
console.log('FlowEmitter--')
console.log('this.channelID == '+that.channelID)
this.red.events.on(`${that.channelID}-registershadowlistener`, function(client) {
that.emit('registershadowlistener', client);
});
this.red.events.on(`${that.namespace}-deregistershadowlistener`, function(client) {
this.red.events.on(`${that.channelID}-deregistershadowlistener`, function(client) {
that.emit('deregistershadowlistener', client);
//that.emit('startcountdownreset');
});
this.red.events.on(`${that.namespace}-flowsub`, function(topic, client) {
this.red.events.on(`${that.channelID}-flowsub`, function(topic, client) {
//that.devicelist[client.nodeid].msgtopic.push(topic);
that.emit('flowsub', topic, client);
});
this.red.events.on(`${that.namespace}-flowunsub`, function(topic, client) {
this.red.events.on(`${that.channelID}-flowunsub`, function(topic, client) {
that.emit('flowunsub', topic, client);
});
this.red.events.on(`${that.namespace}-flowpub`, function(topic, payload, client) {
this.red.events.on(`${that.channelID}-flowpub`, function(topic, payload, client) {
that.emit('flowpub', topic, payload, client);
});
}
FlowEmitter.prototype.pub = function(topic, payload) {
let that = this;
this.red.events.emit(`${that.namespace}-${topic}`, payload);
this.red.events.emit(`${that.channelID}-${topic}`, payload);
}
FlowEmitter.prototype.redemit = function(eventname, data1, data2, data3) {
let that = this;
this.red.events.emit(`${that.namespace}-${eventname}`, data1, data2, data3);
this.red.events.emit(`${that.channelID}-${eventname}`, data1, data2, data3);
}
FlowEmitter.prototype.on = function(eventname, handler) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment