Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/shared/mqtt-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,25 @@ export class UniversalMqttAdapter implements MqttAdapter {
const options = this.buildMqttOptions()
this.client = mqtt.connect(this.options.host, options)

let connected = false
this.client.on('connect', (connack) => {
// Store CONNACK properties for later access
this.connackProperties = connack?.properties
connected = true
resolve()
})

this.client.on('error', (error) => {
reject(error)
})

this.client.on('close', () => {
// closed but not connected
if (!connected) {
reject(new Error('Connection closed'))
}
})

// Set a connection timeout
const timeout = setTimeout(() => {
reject(new Error('Connection timeout'))
Expand Down