lot of changes for first actual use
This commit is contained in:
15
dist/mqttdispatcher.js
vendored
15
dist/mqttdispatcher.js
vendored
@ -3,14 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Mqtt = require("mqtt");
|
||||
const log = require("./log");
|
||||
const callchain = require("./callchain");
|
||||
const fs = require("fs");
|
||||
const MQTT_BROKER_DEFAULT_URL = "mqtt://localhost";
|
||||
function passThrough(message) {
|
||||
return message;
|
||||
}
|
||||
exports.passThrough = passThrough;
|
||||
class MqttDispatcher {
|
||||
constructor(mqttBrokerUrl) {
|
||||
constructor(mqttBrokerUrl, mqttUser, mqttPass, mqttCAFile) {
|
||||
this._mqttOptions = {};
|
||||
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||
if (mqttUser && mqttPass) {
|
||||
this._mqttOptions.username = mqttUser;
|
||||
this._mqttOptions.password = mqttPass;
|
||||
}
|
||||
if (mqttCAFile) {
|
||||
this._mqttOptions.ca = fs.readFileSync(mqttCAFile, 'ascii');
|
||||
this._mqttOptions.rejectUnauthorized = true;
|
||||
}
|
||||
this._topicHandlers = [];
|
||||
}
|
||||
register(topic, label, newChainItemOrCallbackFunc) {
|
||||
@ -41,7 +51,8 @@ class MqttDispatcher {
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
topicHandler.root.begin();
|
||||
}
|
||||
this._mqttClient = Mqtt.connect(this._mqttBrokerUrl);
|
||||
log.info(`connecting to ${this._mqttBrokerUrl}`);
|
||||
this._mqttClient = Mqtt.connect(this._mqttBrokerUrl, this._mqttOptions);
|
||||
this._mqttClient.on('error', log.error);
|
||||
this._mqttClient.on('connect', () => {
|
||||
log.info("connected to mqtt broker");
|
||||
|
Reference in New Issue
Block a user