Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Feb 28, 2022
1 parent 5628014 commit d347980
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class MQTTCLIENT extends EventEmitter {
}
const url = `mqtt://${this.mqttHost}:${this.mqttPort}`;
this.mqttClient = await MQTT.connectAsync(url, options);

this.isConnected = true;
this.emit('connected', 'MQTT Connected.');
} catch (error) {
this.isConnected = false;
this.emit('error', error);
this.emit('error', `MQTT Connect error: ${error}`);
};
};

Expand All @@ -46,13 +44,8 @@ class MQTTCLIENT extends EventEmitter {
await this.mqttClient.publish(fullTopic, message);
const emitDebug = this.mqttDebug ? this.emit('debug', `MQTT publish: ${fullTopic}: ${message}`) : false;
} catch (error) {
await this.mqttClient.end();
this.isConnected = false;
this.emit('disconnected', 'MQTT Disconnected, trying to reconnect.');

setTimeout(() => {
this.connect();
}, 5000);
this.emit('error', `MQTT Publish error: ${error}`);
};
};
};
Expand Down

0 comments on commit d347980

Please sign in to comment.