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

1
dist/main.js vendored
View File

@ -11,6 +11,7 @@ class Dispatcher {
return `<<${message}>>`; return `<<${message}>>`;
}); });
this._mqttClient.register('IoT/Device/#', mqtt.passThrough); this._mqttClient.register('IoT/Device/#', mqtt.passThrough);
this._mqttClient.register('IoT/Device/#', mqtt.passThrough);
} }
exec() { exec() {
log.info("Dispatcher starting"); log.info("Dispatcher starting");

5
dist/mqttclient.js vendored
View File

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

View File

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

View File

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