mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
58774c366d
commit
f7a72a48ea
@ -54,16 +54,20 @@ MQTTClient.prototype.connect = function(options) {
|
|||||||
|
|
||||||
self.client = mqtt.createConnection(this.port,this.host,function(err,client) {
|
self.client = mqtt.createConnection(this.port,this.host,function(err,client) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
self.connected = false;
|
||||||
|
self.connectionError = true;
|
||||||
self.emit('connectionlost',err);
|
self.emit('connectionlost',err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client.on('close',function(e) {
|
client.on('close',function(e) {
|
||||||
clearInterval(self.watchdog);
|
clearInterval(self.watchdog);
|
||||||
if (self.connected) {
|
if (!self.connectionError) {
|
||||||
self.connected = false;
|
if (self.connected) {
|
||||||
self.emit('connectionlost',e);
|
self.connected = false;
|
||||||
} else {
|
self.emit('connectionlost',e);
|
||||||
self.emit('disconnect');
|
} else {
|
||||||
|
self.emit('disconnect');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
client.on('error',function(e) {
|
client.on('error',function(e) {
|
||||||
@ -96,6 +100,7 @@ MQTTClient.prototype.connect = function(options) {
|
|||||||
self.lastInbound = (new Date()).getTime()
|
self.lastInbound = (new Date()).getTime()
|
||||||
self.lastOutbound = (new Date()).getTime()
|
self.lastOutbound = (new Date()).getTime()
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
|
self.connectionError = false;
|
||||||
self.emit('connect');
|
self.emit('connect');
|
||||||
} else {
|
} else {
|
||||||
self.connected = false;
|
self.connected = false;
|
||||||
@ -161,6 +166,7 @@ MQTTClient.prototype.connect = function(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.lastOutbound = (new Date()).getTime()
|
this.lastOutbound = (new Date()).getTime()
|
||||||
|
this.connectionError = false;
|
||||||
client.connect(self.options);
|
client.connect(self.options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user