mqttClient renamed to mqttDispatcher
This commit is contained in:
42
src/main.ts
42
src/main.ts
@ -4,67 +4,39 @@ import * as callchain from './callchain'
|
||||
|
||||
|
||||
class Dispatcher {
|
||||
private _mqttClient: mqtt.MqttClient
|
||||
private _mqttDispatcher: mqtt.MqttDispatcher
|
||||
|
||||
constructor() {
|
||||
this._mqttClient = new mqtt.MqttClient()
|
||||
this._mqttDispatcher = new mqtt.MqttDispatcher()
|
||||
|
||||
this._mqttClient.register('IoT/test', 'print1', (message: any) : any => {
|
||||
this._mqttDispatcher.register('IoT/test', 'print1', (message: any) : any => {
|
||||
log.info("Callback for IoT/test")
|
||||
log.info(`message is ${message}`)
|
||||
return `<<${message}>>`
|
||||
})
|
||||
this._mqttClient.register('IoT/test', 'print2', (message: any) : any => {
|
||||
this._mqttDispatcher.register('IoT/test', 'print2', (message: any) : any => {
|
||||
log.info("Callback for IoT/test")
|
||||
log.info(`message is ${message}`)
|
||||
return `<<${message}>>`
|
||||
})
|
||||
this._mqttClient.register('IoT/test', 'null1', mqtt.passThrough)
|
||||
this._mqttClient.register('IoT/test', 'null2', mqtt.passThrough)
|
||||
this._mqttDispatcher.register('IoT/test', 'null1', mqtt.passThrough)
|
||||
this._mqttDispatcher.register('IoT/test', 'null2', mqtt.passThrough)
|
||||
}
|
||||
|
||||
exec() : void {
|
||||
log.info("Dispatcher starting")
|
||||
|
||||
this._mqttClient.exec()
|
||||
this._mqttDispatcher.exec()
|
||||
|
||||
log.info("Dispatcher running")
|
||||
}
|
||||
|
||||
test() : void {
|
||||
log.info("Sending test data")
|
||||
this._mqttClient.test()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// callchain.registerChainItemFunc('first', (message : any) : any => {
|
||||
// log.info(`first callback ${message}`)
|
||||
// return `<${message}>`
|
||||
// })
|
||||
|
||||
// callchain.registerChainItemFunc('second', (message : any) : any => {
|
||||
// log.info(`second callback ${message}`)
|
||||
// return `<${message}>`
|
||||
// })
|
||||
|
||||
// callchain.registerChainItemFunc('third', (message : any) : any => {
|
||||
// log.info(`third callback ${message}`)
|
||||
// return `<${message}>`
|
||||
// })
|
||||
|
||||
// callchain.begin()
|
||||
|
||||
// callchain.send('test1')
|
||||
// callchain.send('test2')
|
||||
// callchain.send('test3')
|
||||
// callchain.send('test4')
|
||||
|
||||
const dispatcher = new Dispatcher()
|
||||
dispatcher.exec()
|
||||
|
||||
dispatcher.test()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ interface TopicHandler {
|
||||
last: callchain.AChainItem | undefined
|
||||
}
|
||||
|
||||
export class MqttClient {
|
||||
export class MqttDispatcher {
|
||||
private _mqttClient: Mqtt.Client
|
||||
private _mqttBrokerUrl: string
|
||||
private _topicHandlers: TopicHandler[]
|
||||
@ -52,10 +52,6 @@ export class MqttClient {
|
||||
}
|
||||
}
|
||||
|
||||
test() : void {
|
||||
this._mqttClient.emit("message", 'IoT/test', 'payload')
|
||||
}
|
||||
|
||||
exec() : void {
|
||||
for (let topicHandler of this._topicHandlers) {
|
||||
(topicHandler.root as callchain.ChainItem).begin()
|
||||
|
Reference in New Issue
Block a user