overloaded register func in mqttclilent
This commit is contained in:
8
dist/main.js
vendored
8
dist/main.js
vendored
@ -5,18 +5,18 @@ const mqtt = require("./mqttclient");
|
|||||||
class Dispatcher {
|
class Dispatcher {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._mqttClient = new mqtt.MqttClient();
|
this._mqttClient = new mqtt.MqttClient();
|
||||||
this._mqttClient.registerCallbackFunc('IoT/test', 'print1', (message) => {
|
this._mqttClient.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.registerCallbackFunc('IoT/test', 'print2', (message) => {
|
this._mqttClient.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.registerCallbackFunc('IoT/test', 'null1', mqtt.passThrough);
|
this._mqttClient.register('IoT/test', 'null1', mqtt.passThrough);
|
||||||
this._mqttClient.registerCallbackFunc('IoT/test', 'null2', mqtt.passThrough);
|
this._mqttClient.register('IoT/test', 'null2', mqtt.passThrough);
|
||||||
}
|
}
|
||||||
exec() {
|
exec() {
|
||||||
log.info("Dispatcher starting");
|
log.info("Dispatcher starting");
|
||||||
|
16
dist/mqttclient.js
vendored
16
dist/mqttclient.js
vendored
@ -13,12 +13,16 @@ class MqttClient {
|
|||||||
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
this._mqttBrokerUrl = (mqttBrokerUrl) ? mqttBrokerUrl : MQTT_BROKER_DEFAULT_URL;
|
||||||
this._topicHandlers = [];
|
this._topicHandlers = [];
|
||||||
}
|
}
|
||||||
registerCallbackFunc(topic, label, callbackFunc) {
|
register(topic, label, newChainItemOrCallbackFunc) {
|
||||||
let newChainItem = new callchain.ChainItem(label);
|
let newChainItem;
|
||||||
newChainItem.registerFunc(callbackFunc);
|
if (newChainItemOrCallbackFunc instanceof callchain.AChainItem) {
|
||||||
this.registerCallbackClass(topic, label, newChainItem);
|
newChainItem = newChainItemOrCallbackFunc;
|
||||||
}
|
}
|
||||||
registerCallbackClass(topic, label, newChainItem) {
|
else {
|
||||||
|
let myNewChainItem = new callchain.ChainItem(label);
|
||||||
|
myNewChainItem.registerFunc(newChainItemOrCallbackFunc);
|
||||||
|
newChainItem = myNewChainItem;
|
||||||
|
}
|
||||||
let done = false;
|
let done = false;
|
||||||
for (let topicHandler of this._topicHandlers) {
|
for (let topicHandler of this._topicHandlers) {
|
||||||
if (topicHandler.topic === topic) {
|
if (topicHandler.topic === topic) {
|
||||||
|
@ -9,18 +9,18 @@ class Dispatcher {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this._mqttClient = new mqtt.MqttClient()
|
this._mqttClient = new mqtt.MqttClient()
|
||||||
|
|
||||||
this._mqttClient.registerCallbackFunc('IoT/test', 'print1', (message: any) : any => {
|
this._mqttClient.register('IoT/test', 'print1', (message: any) : any => {
|
||||||
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.registerCallbackFunc('IoT/test', 'print2', (message: any) : any => {
|
this._mqttClient.register('IoT/test', 'print2', (message: any) : any => {
|
||||||
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.registerCallbackFunc('IoT/test', 'null1', mqtt.passThrough)
|
this._mqttClient.register('IoT/test', 'null1', mqtt.passThrough)
|
||||||
this._mqttClient.registerCallbackFunc('IoT/test', 'null2', mqtt.passThrough)
|
this._mqttClient.register('IoT/test', 'null2', mqtt.passThrough)
|
||||||
}
|
}
|
||||||
|
|
||||||
exec() : void {
|
exec() : void {
|
||||||
|
@ -27,13 +27,16 @@ export class MqttClient {
|
|||||||
this._topicHandlers = []
|
this._topicHandlers = []
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCallbackFunc(topic: string, label: string, callbackFunc: callchain.ChainItemFunc) : void {
|
register(topic: string, label: string,
|
||||||
let newChainItem = new callchain.ChainItem(label)
|
newChainItemOrCallbackFunc: callchain.AChainItem | callchain.ChainItemFunc) : void {
|
||||||
newChainItem.registerFunc(callbackFunc)
|
let newChainItem : callchain.AChainItem
|
||||||
this.registerCallbackClass(topic, label, newChainItem)
|
if (newChainItemOrCallbackFunc instanceof callchain.AChainItem) {
|
||||||
}
|
newChainItem = newChainItemOrCallbackFunc
|
||||||
|
} else {
|
||||||
registerCallbackClass(topic: string, label: string, newChainItem: callchain.AChainItem) : void {
|
let myNewChainItem = new callchain.ChainItem(label)
|
||||||
|
myNewChainItem.registerFunc(newChainItemOrCallbackFunc)
|
||||||
|
newChainItem = myNewChainItem
|
||||||
|
}
|
||||||
let done: boolean = false
|
let done: boolean = false
|
||||||
for (let topicHandler of this._topicHandlers) {
|
for (let topicHandler of this._topicHandlers) {
|
||||||
if (topicHandler.topic === topic) {
|
if (topicHandler.topic === topic) {
|
||||||
|
Reference in New Issue
Block a user