Skip to content

Commit f74109b

Browse files
committed
feat(connection): Display and log reason when connection got killed
1 parent 9421d01 commit f74109b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

connection.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function (RED) {
1313
this.isSubscribed = false
1414
this.isError = false
1515
this.isKilled = false
16+
this.killedStatusText = 'KILLED'
1617

1718
this.jobQueue = []
1819

@@ -141,12 +142,6 @@ module.exports = function (RED) {
141142
this.discover(nodeId)
142143
}
143144

144-
// this.handleUpdateDelta = function (nodeId, message) {
145-
// this.execCallbackForOne(nodeId, 'setLocalState', message.state)
146-
// this.execCallbackForOne(nodeId, 'emitLocalState')
147-
// this.updateShadow({ nodeId, type: 'reported' })
148-
// }
149-
150145
this.handleUpdateAccepted = function (nodeId, message) {
151146
if (message.state.desired && !message.state.reported) {
152147
//update must have been initiated from Alexa!
@@ -209,7 +204,7 @@ module.exports = function (RED) {
209204
this.execCallbackForAll('setStatus', {
210205
shape: 'dot',
211206
fill: 'red',
212-
text: this.isKilled ? 'KILLED' : 'offline'
207+
text: this.isKilled ? this.killedStatusText : 'offline'
213208
})
214209
}
215210
},
@@ -241,13 +236,16 @@ module.exports = function (RED) {
241236
this.handleGetRejected(nodeId, message)
242237
} else if (topic.includes('/delete/accepted')) {
243238
this.handleDeleteAccepted(nodeId)
244-
// } else if (topic.includes('/update/delta')) {
245-
// this.handleUpdateDelta(nodeId, message)
246239
} else if (topic.includes('/update/accepted')) {
247240
this.handleUpdateAccepted(nodeId, message)
248241
}
249242
} else if (topic == `vsh/${this.credentials.thingId}/kill`) {
243+
console.warn(
244+
'CONNECTION KILLED! Reason:',
245+
message.reason || 'undefined'
246+
)
250247
this.isKilled = true
248+
this.killedStatusText = message.reason ? message.reason : 'KILLED'
251249
this.mqttClient.disconnect()
252250
}
253251
}
@@ -259,7 +257,6 @@ module.exports = function (RED) {
259257
`$aws/things/${this.credentials.thingId}/shadow/name/+/delete/accepted`,
260258
`$aws/things/${this.credentials.thingId}/shadow/name/+/get/accepted`,
261259
`$aws/things/${this.credentials.thingId}/shadow/name/+/get/rejected`,
262-
//`$aws/things/${this.credentials.thingId}/shadow/name/+/update/delta`,
263260
`$aws/things/${this.credentials.thingId}/shadow/name/+/update/accepted`,
264261
`vsh/${this.credentials.thingId}/kill`
265262
]

0 commit comments

Comments
 (0)