Skip to content

Commit

Permalink
Added mqtt disconnect metric
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Jun 6, 2024
1 parent a2eaf31 commit 4c88238
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "7.8.0",
"version": "7.8.1",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
17 changes: 17 additions & 0 deletions src/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ReconnectingMQTTClient extends MQTTClient {
this.reconnectLimit = reconnectLimit || 3
this.tokenProvider = tokenProvider
this.tokenProviderPromise = undefined
this.trackEvent = undefined

this.handleCloseEvent = this.handleCloseEvent.bind(this)
this.handleConnectEvent = this.handleConnectEvent.bind(this)
Expand Down Expand Up @@ -191,6 +192,14 @@ class ReconnectingMQTTClient extends MQTTClient {
`[mqtt] Command '${cmd}', reasonCode ${reasonCode} (${mqttReasonCodeNameEnum[reasonCode]})`,
)

if (this.trackEvent) {
// eslint-disable-next-line unicorn/no-null
this.trackEvent('Debug', 'MQTT.Disconnect', 'v1', null, {
reason: mqttReasonCodeNameEnum[reasonCode],
reasonCode,
})
}

// ignore 131 (MQTT broker limits)
if (reasonCode === 131) {
return
Expand Down Expand Up @@ -262,6 +271,14 @@ class ReconnectingMQTTClient extends MQTTClient {
this.disconnect()
})
}

/**
* Set event tracker
* @param {function} trackEvent
*/
setEventTracker(trackEvent) {
this.trackEvent = trackEvent
}
}

export { MQTTClient, ReconnectingMQTTClient, defaultOptions }

0 comments on commit 4c88238

Please sign in to comment.