js files
This commit is contained in:
34
dist/main.js
vendored
34
dist/main.js
vendored
@ -4,48 +4,26 @@ const log = require("./log");
|
|||||||
const mqtt = require("./mqttclient");
|
const mqtt = require("./mqttclient");
|
||||||
class Dispatcher {
|
class Dispatcher {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._mqttClient = new mqtt.MqttClient();
|
this._mqttDispatcher = new mqtt.MqttDispatcher();
|
||||||
this._mqttClient.register('IoT/test', 'print1', (message) => {
|
this._mqttDispatcher.register('IoT/test', 'print1', (message) => {
|
||||||
log.info("Callback for IoT/test");
|
log.info("Callback for IoT/test");
|
||||||
log.info(`message is ${message}`);
|
log.info(`message is ${message}`);
|
||||||
return `<<${message}>>`;
|
return `<<${message}>>`;
|
||||||
});
|
});
|
||||||
this._mqttClient.register('IoT/test', 'print2', (message) => {
|
this._mqttDispatcher.register('IoT/test', 'print2', (message) => {
|
||||||
log.info("Callback for IoT/test");
|
log.info("Callback for IoT/test");
|
||||||
log.info(`message is ${message}`);
|
log.info(`message is ${message}`);
|
||||||
return `<<${message}>>`;
|
return `<<${message}>>`;
|
||||||
});
|
});
|
||||||
this._mqttClient.register('IoT/test', 'null1', mqtt.passThrough);
|
this._mqttDispatcher.register('IoT/test', 'null1', mqtt.passThrough);
|
||||||
this._mqttClient.register('IoT/test', 'null2', mqtt.passThrough);
|
this._mqttDispatcher.register('IoT/test', 'null2', mqtt.passThrough);
|
||||||
}
|
}
|
||||||
exec() {
|
exec() {
|
||||||
log.info("Dispatcher starting");
|
log.info("Dispatcher starting");
|
||||||
this._mqttClient.exec();
|
this._mqttDispatcher.exec();
|
||||||
log.info("Dispatcher running");
|
log.info("Dispatcher running");
|
||||||
}
|
}
|
||||||
test() {
|
|
||||||
log.info("Sending test data");
|
|
||||||
this._mqttClient.test();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// callchain.registerChainItemFunc('first', (message : any) : any => {
|
|
||||||
// log.info(`first callback ${message}`)
|
|
||||||
// return `<${message}>`
|
|
||||||
// })
|
|
||||||
// callchain.registerChainItemFunc('second', (message : any) : any => {
|
|
||||||
// log.info(`second callback ${message}`)
|
|
||||||
// return `<${message}>`
|
|
||||||
// })
|
|
||||||
// callchain.registerChainItemFunc('third', (message : any) : any => {
|
|
||||||
// log.info(`third callback ${message}`)
|
|
||||||
// return `<${message}>`
|
|
||||||
// })
|
|
||||||
// callchain.begin()
|
|
||||||
// callchain.send('test1')
|
|
||||||
// callchain.send('test2')
|
|
||||||
// callchain.send('test3')
|
|
||||||
// callchain.send('test4')
|
|
||||||
const dispatcher = new Dispatcher();
|
const dispatcher = new Dispatcher();
|
||||||
dispatcher.exec();
|
dispatcher.exec();
|
||||||
dispatcher.test();
|
|
||||||
//# sourceMappingURL=main.js.map
|
//# sourceMappingURL=main.js.map
|
7
dist/mqttclient.js
vendored
7
dist/mqttclient.js
vendored
@ -8,7 +8,7 @@ function passThrough(message) {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
exports.passThrough = passThrough;
|
exports.passThrough = passThrough;
|
||||||
class MqttClient {
|
class MqttDispatcher {
|
||||||
constructor(mqttBrokerUrl) {
|
constructor(mqttBrokerUrl) {
|
||||||
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||||
this._topicHandlers = [];
|
this._topicHandlers = [];
|
||||||
@ -37,9 +37,6 @@ class MqttClient {
|
|||||||
log.info(`first callback ${newChainItem.toString()} added for topic ${topic}`);
|
log.info(`first callback ${newChainItem.toString()} added for topic ${topic}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test() {
|
|
||||||
this._mqttClient.emit("message", 'IoT/test', 'payload');
|
|
||||||
}
|
|
||||||
exec() {
|
exec() {
|
||||||
for (let topicHandler of this._topicHandlers) {
|
for (let topicHandler of this._topicHandlers) {
|
||||||
topicHandler.root.begin();
|
topicHandler.root.begin();
|
||||||
@ -88,5 +85,5 @@ class MqttClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.MqttClient = MqttClient;
|
exports.MqttDispatcher = MqttDispatcher;
|
||||||
//# sourceMappingURL=mqttclient.js.map
|
//# sourceMappingURL=mqttclient.js.map
|
Reference in New Issue
Block a user