Commit 63b2f13d by Chavee Issariyapat

share device subscription between shadow of the same devieid

parent 00553dd9
......@@ -16,20 +16,32 @@ const Coordinator = function(param={}) {
client.forward(topic, payload, options, topic, 0);
});
that.remoteclient.subscribe(`->tap/shadow/${deviceid}:${client.token}`);
that.remoteclient.subscribe(`->tap/device/${deviceid}:${client.token}`);
if (!that.localserver.sublist[deviceid]) {
that.remoteclient.subscribe(`->tap/shadow/${deviceid}:${client.token}`);
that.remoteclient.subscribe(`->tap/device/${deviceid}:${client.token}`);
that.localserver.sublist[deviceid] = 1;
}
else{
that.localserver.sublist[deviceid]++;
}
});
this.localserver.on('clientDisconnected', function(client){
console.log('client disconnected', client.id);
let deviceid = client.id.split(':')[0];
that.remoteclient.unsubscribe(`->tap/shadow/${deviceid}:${client.token}`);
that.remoteclient.unsubscribe(`->tap/device/${deviceid}:${client.token}`);
if (that.localserver.sublist[deviceid] == 1) {
that.remoteclient.unsubscribe(`->tap/shadow/${deviceid}:${client.token}`);
that.remoteclient.unsubscribe(`->tap/device/${deviceid}:${client.token}`);
that.localserver.sublist[deviceid] = 0;
}
else {
that.localserver.sublist[deviceid]--;
}
});
this.remoteclient.on('message', function(topic, payload){
//console.log(that.localserver.sublist);
let jsonpayload = {};
try {
jsonpayload = JSON.parse(payload.toString());
......
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