Commit aa9f8e03 by Chavee Issariyapat

update

parent 0df933eb
......@@ -20,6 +20,15 @@ const Coordinator = function(param={}) {
that.remoteclient.subscribe(`->tap/device/${deviceid}:${client.token}`);
});
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}`);
});
this.remoteclient.on('message', function(topic, payload){
let jsonpayload = {};
try {
......@@ -27,6 +36,7 @@ const Coordinator = function(param={}) {
}
catch(e) {}
//console.log('incoming message ', topic, jsonpayload)
if (topic == '@shadow/data/updated') {
that.localserver.publish(`${jsonpayload.deviceid}/shadow`, payload.toString());
}
......
......@@ -37,7 +37,6 @@ MQTTClient.prototype.publish = function(topic, payload) {
this.client.publish(topic, payload);
}
else {
}
}
......@@ -51,6 +50,7 @@ MQTTClient.prototype.subscribe = function(topic) {
}
function create(param) {
return new MQTTClient(param);
}
......
......@@ -30,6 +30,10 @@ MQTTServer.prototype.start = function() {
that.emit('clientConnected',client);
});
this.mqttserver.on('clientDisconnected', function(client, reason) {
that.emit('clientDisconnected',client, reason);
});
this.mqttserver.on('subscribed', function(topic, client) {
that.emit('clientSubscribed',{
deviceid: client.id,
......@@ -42,7 +46,7 @@ MQTTServer.prototype.start = function() {
deviceid: client.id,
topic: topic
});
});
});
}
MQTTServer.prototype.publish = function(topic, payload) {
......
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