some changes
This commit is contained in:
12
dist/main.js
vendored
12
dist/main.js
vendored
@ -1,12 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const log = require("./log");
|
||||
const MqttClient = require("./mqttclient");
|
||||
const mqtt = require("./mqttclient");
|
||||
class Dispatcher {
|
||||
constructor() {
|
||||
this._mqttClient = new MqttClient.MqttClient();
|
||||
this._mqttClient.register('IoT/test', null);
|
||||
this._mqttClient.register('IoT/Device/#', null);
|
||||
this._mqttClient = new mqtt.MqttClient();
|
||||
this._mqttClient.register('IoT/test', (message) => {
|
||||
log.info("Callback for IoT/test");
|
||||
log.info(`message is ${message}`);
|
||||
return `<<${message}>>`;
|
||||
});
|
||||
this._mqttClient.register('IoT/Device/#', mqtt.passThrough);
|
||||
}
|
||||
exec() {
|
||||
log.info("Dispatcher starting");
|
||||
|
8
dist/mqttclient.js
vendored
8
dist/mqttclient.js
vendored
@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Mqtt = require("mqtt");
|
||||
const log = require("./log");
|
||||
const MQTT_BROKER_DEFAULT_URL = "mqtt://localhost";
|
||||
function passThrough(message) {
|
||||
return message;
|
||||
}
|
||||
exports.passThrough = passThrough;
|
||||
class MqttClient {
|
||||
constructor(mqttBrokerUrl) {
|
||||
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||
@ -26,9 +30,7 @@ class MqttClient {
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
if (this.topicMatch(topicHandler.topic, topic)) {
|
||||
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`);
|
||||
if (topicHandler.callback != null) {
|
||||
topicHandler.callback(payload);
|
||||
}
|
||||
topicHandler.callback(payload);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user