interface instead of type
This commit is contained in:
1
dist/main.js
vendored
1
dist/main.js
vendored
@ -11,6 +11,7 @@ class Dispatcher {
|
|||||||
exec() {
|
exec() {
|
||||||
log.info("Dispatcher starting");
|
log.info("Dispatcher starting");
|
||||||
this._mqttClient.exec();
|
this._mqttClient.exec();
|
||||||
|
log.info("Dispatcher running");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const dispatcher = new Dispatcher();
|
const dispatcher = new Dispatcher();
|
||||||
|
3
dist/mqttclient.js
vendored
3
dist/mqttclient.js
vendored
@ -26,6 +26,9 @@ class MqttClient {
|
|||||||
for (let topicHandler of this._topicHandlers) {
|
for (let topicHandler of this._topicHandlers) {
|
||||||
if (this.topicMatch(topicHandler.topic, topic)) {
|
if (this.topicMatch(topicHandler.topic, topic)) {
|
||||||
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`);
|
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`);
|
||||||
|
if (topicHandler.callback != null) {
|
||||||
|
topicHandler.callback(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,8 @@ class Dispatcher {
|
|||||||
log.info("Dispatcher starting")
|
log.info("Dispatcher starting")
|
||||||
|
|
||||||
this._mqttClient.exec()
|
this._mqttClient.exec()
|
||||||
|
|
||||||
|
log.info("Dispatcher running")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,13 @@ import * as log from './log'
|
|||||||
|
|
||||||
const MQTT_BROKER_DEFAULT_URL : string = "mqtt://localhost"
|
const MQTT_BROKER_DEFAULT_URL : string = "mqtt://localhost"
|
||||||
|
|
||||||
type TopicHandlerCallback = (message: Buffer) => void
|
type TopicHandlerCallback = (message: any) => any
|
||||||
|
|
||||||
type TopicHandler = {
|
interface TopicHandler {
|
||||||
topic: string,
|
topic: string,
|
||||||
callback: TopicHandlerCallback|null
|
callback: TopicHandlerCallback|null
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MqttClient {
|
export class MqttClient {
|
||||||
private _mqttClient: Mqtt.Client
|
private _mqttClient: Mqtt.Client
|
||||||
private _mqttBrokerUrl: string
|
private _mqttBrokerUrl: string
|
||||||
@ -38,6 +39,9 @@ export class MqttClient {
|
|||||||
for (let topicHandler of this._topicHandlers) {
|
for (let topicHandler of this._topicHandlers) {
|
||||||
if (this.topicMatch(topicHandler.topic, topic)) {
|
if (this.topicMatch(topicHandler.topic, topic)) {
|
||||||
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`)
|
log.info(`received topic ${topic} matches registered topic ${topicHandler.topic}`)
|
||||||
|
if (topicHandler.callback != null) {
|
||||||
|
topicHandler.callback(payload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user