interface instead of type

This commit is contained in:
Wolfgang Hottgenroth
2017-07-23 22:55:05 +02:00
parent dad740e620
commit 8685bdde87
4 changed files with 12 additions and 2 deletions

View File

@ -15,6 +15,8 @@ class Dispatcher {
log.info("Dispatcher starting")
this._mqttClient.exec()
log.info("Dispatcher running")
}
}

View File

@ -3,12 +3,13 @@ import * as log from './log'
const MQTT_BROKER_DEFAULT_URL : string = "mqtt://localhost"
type TopicHandlerCallback = (message: Buffer) => void
type TopicHandlerCallback = (message: any) => any
type TopicHandler = {
interface TopicHandler {
topic: string,
callback: TopicHandlerCallback|null
}
export class MqttClient {
private _mqttClient: Mqtt.Client
private _mqttBrokerUrl: string
@ -38,6 +39,9 @@ export class MqttClient {
for (let topicHandler of this._topicHandlers) {
if (this.topicMatch(topicHandler.topic, topic)) {
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`)
if (topicHandler.callback != null) {
topicHandler.callback(payload)
}
}
}
})