remove leading underscore, fix next call in mongosave
This commit is contained in:
36
dist/mqttdispatcher.js
vendored
36
dist/mqttdispatcher.js
vendored
@ -11,17 +11,17 @@ function passThrough(message) {
|
||||
exports.passThrough = passThrough;
|
||||
class MqttDispatcher {
|
||||
constructor(mqttBrokerUrl, mqttUser, mqttPass, mqttCAFile) {
|
||||
this._mqttOptions = {};
|
||||
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||
this.mqttOptions = {};
|
||||
this.mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||
if (mqttUser && mqttPass) {
|
||||
this._mqttOptions.username = mqttUser;
|
||||
this._mqttOptions.password = mqttPass;
|
||||
this.mqttOptions.username = mqttUser;
|
||||
this.mqttOptions.password = mqttPass;
|
||||
}
|
||||
if (mqttCAFile) {
|
||||
this._mqttOptions.ca = fs.readFileSync(mqttCAFile, 'ascii');
|
||||
this._mqttOptions.rejectUnauthorized = true;
|
||||
this.mqttOptions.ca = fs.readFileSync(mqttCAFile, 'ascii');
|
||||
this.mqttOptions.rejectUnauthorized = true;
|
||||
}
|
||||
this._topicHandlers = [];
|
||||
this.topicHandlers = [];
|
||||
}
|
||||
register(topic, label, newChainItemOrCallbackFunc) {
|
||||
let newChainItem;
|
||||
@ -34,7 +34,7 @@ class MqttDispatcher {
|
||||
newChainItem = myNewChainItem;
|
||||
}
|
||||
let done = false;
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
for (let topicHandler of this.topicHandlers) {
|
||||
if (topicHandler.topic === topic) {
|
||||
topicHandler.last.registerNext(newChainItem);
|
||||
topicHandler.last = newChainItem;
|
||||
@ -43,26 +43,26 @@ class MqttDispatcher {
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
this._topicHandlers.push({ topic: topic, root: newChainItem, last: newChainItem });
|
||||
this.topicHandlers.push({ topic: topic, root: newChainItem, last: newChainItem });
|
||||
log.info(`first callback ${newChainItem.toString()} added for topic ${topic}`);
|
||||
}
|
||||
}
|
||||
exec() {
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
for (let topicHandler of this.topicHandlers) {
|
||||
topicHandler.root.begin();
|
||||
}
|
||||
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(`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");
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
this._mqttClient.subscribe(topicHandler.topic);
|
||||
for (let topicHandler of this.topicHandlers) {
|
||||
this.mqttClient.subscribe(topicHandler.topic);
|
||||
}
|
||||
});
|
||||
this._mqttClient.on('message', (topic, payload) => {
|
||||
this.mqttClient.on('message', (topic, payload) => {
|
||||
log.info(`message received, topic ${topic}, payload ${payload}`);
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
for (let topicHandler of this.topicHandlers) {
|
||||
if (this.topicMatch(topicHandler.topic, topic)) {
|
||||
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`);
|
||||
topicHandler.root.send(payload);
|
||||
|
Reference in New Issue
Block a user