Commit ae98af36 by Chavee Issariyapat

edit

parent cd4bc42f
......@@ -104,11 +104,45 @@ const Coordinator = function(param={}) {
});
*/
this.flowemitter.on('flowpub', function(topic, payload, client){
console.log('client published', client.id);
let outtopic, outmsg;
let deviceid = client.id;
switch (topic) {
case '@shadow/data/update' :
outtopic = `@tap/shadow/update/${deviceid}:${client.token}`;
outmsg = payload.toString();
that.remoteclient.publish(outtopic, outmsg);
break;
case '@local/shadow/get' :
outtopic = `@tap/shadow/get/${deviceid}:${client.token}`;
outmsg = payload.toString();
that.remoteclient.publish(outtopic, outmsg);
break;
case '@local/device/get' :
outtopic = `@tap/device/get/${deviceid}:${client.token}`;
outmsg = payload.toString();
that.remoteclient.publish(outtopic, outmsg);
break;
default:
if (topic.startsWith('@local/msgout/')) {
let part = topic.substr(14);
outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${part}`;
outmsg = payload.toString();
that.remoteclient.publish(outtopic, outmsg);
}
}
});
this.flowemitter.on('flowsub', function(topic, client) {
let deviceid = client.id.split(':')[0];
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if (topic.startsWith('@local/msgin/')) {
let msgpart = packet.topic.split('/').splice(4).join('/');
let msgpart = topic.split('/').splice(4).join('/');
outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${msgpart}`;
that.remoteclient.subscribe(outtopic);
}
......
......@@ -23,8 +23,15 @@ FlowEmitter.prototype.start = function() {
this.red.events.on('flowsub', function(topic, client) {
that.emit('flowsub', topic, {
id : client.clientId,
token : client.username
id : client.deviceid,
token : client.devicetoken
});
});
this.red.events.on('flowpub', function(topic, payload, client) {
that.emit('flowpub', topic, payload, {
id : client.deviceid,
token : client.devicetoken
});
});
......
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