callback name

This commit is contained in:
Wolfgang Hottgenroth
2017-07-27 23:58:14 +02:00
parent 04873adad2
commit ac5566a402
4 changed files with 8 additions and 4 deletions

View File

@ -13,6 +13,7 @@ class Dispatcher {
return `<<${message}>>`
})
this._mqttClient.register('IoT/Device/#', mqtt.passThrough)
this._mqttClient.register('IoT/Device/#', mqtt.passThrough)
}
exec() : void {

View File

@ -26,17 +26,18 @@ export class MqttClient {
register(topic: string, callback: TopicHandlerCallback) : void {
let done: boolean = false
let callbackName : string = (callback.name === "") ? "lambda" : callback.name
for (let topicHandler of this._topicHandlers) {
if (topicHandler.topic === topic) {
topicHandler.callbacks.push(callback)
done = true
log.info(`additional callback added for topic ${topic}`)
log.info(`additional callback <${callbackName}> added for topic ${topic}`)
}
}
if (! done) {
let cbs : TopicHandlerCallback[] = [ callback ]
this._topicHandlers.push({topic:topic, callbacks:cbs})
log.info(`first callback added for topic ${topic}`)
log.info(`first callback <${callbackName}> added for topic ${topic}`)
}
}