overloaded register func in mqttclilent
This commit is contained in:
@ -9,18 +9,18 @@ class Dispatcher {
|
||||
constructor() {
|
||||
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(`message is ${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(`message is ${message}`)
|
||||
return `<<${message}>>`
|
||||
})
|
||||
this._mqttClient.registerCallbackFunc('IoT/test', 'null1', mqtt.passThrough)
|
||||
this._mqttClient.registerCallbackFunc('IoT/test', 'null2', mqtt.passThrough)
|
||||
this._mqttClient.register('IoT/test', 'null1', mqtt.passThrough)
|
||||
this._mqttClient.register('IoT/test', 'null2', mqtt.passThrough)
|
||||
}
|
||||
|
||||
exec() : void {
|
||||
|
@ -27,13 +27,16 @@ export class MqttClient {
|
||||
this._topicHandlers = []
|
||||
}
|
||||
|
||||
registerCallbackFunc(topic: string, label: string, callbackFunc: callchain.ChainItemFunc) : void {
|
||||
let newChainItem = new callchain.ChainItem(label)
|
||||
newChainItem.registerFunc(callbackFunc)
|
||||
this.registerCallbackClass(topic, label, newChainItem)
|
||||
}
|
||||
|
||||
registerCallbackClass(topic: string, label: string, newChainItem: callchain.AChainItem) : void {
|
||||
register(topic: string, label: string,
|
||||
newChainItemOrCallbackFunc: callchain.AChainItem | callchain.ChainItemFunc) : void {
|
||||
let newChainItem : callchain.AChainItem
|
||||
if (newChainItemOrCallbackFunc instanceof callchain.AChainItem) {
|
||||
newChainItem = newChainItemOrCallbackFunc
|
||||
} else {
|
||||
let myNewChainItem = new callchain.ChainItem(label)
|
||||
myNewChainItem.registerFunc(newChainItemOrCallbackFunc)
|
||||
newChainItem = myNewChainItem
|
||||
}
|
||||
let done: boolean = false
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
if (topicHandler.topic === topic) {
|
||||
|
Reference in New Issue
Block a user