Skip to content

Commit db8c147

Browse files
committed
fix(connection): Delay flagging as connected by 7 sec; Related to #84
1 parent 823ebfb commit db8c147

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

connection.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ module.exports = function (RED) {
6767
}
6868

6969
this.registerChildNode = function (nodeId, callbacks) {
70-
// console.log(
71-
// `registerChildNode() for ${nodeId} | allowed: ${this.allowedDeviceCount}`
72-
// )
73-
7470
if (Object.keys(this.childNodes).length >= this.allowedDeviceCount) {
7571
callbacks.setStatus({
7672
shape: 'dot',
@@ -84,8 +80,6 @@ module.exports = function (RED) {
8480

8581
if (Object.keys(this.childNodes).length == 1) {
8682
//first child node is registering!
87-
//console.log('first child node registering!!!')
88-
8983
this.connectAndSubscribe()
9084
}
9185

@@ -108,7 +102,6 @@ module.exports = function (RED) {
108102
}
109103

110104
this.unregisterChildNode = async function (nodeId) {
111-
//console.log(`unregisterChildNode() for ${nodeId}`)
112105
delete this.childNodes[nodeId]
113106

114107
if (Object.keys(this.childNodes).length == 0) {
@@ -149,6 +142,22 @@ module.exports = function (RED) {
149142
})
150143
}
151144

145+
this.requestConfigDebounced = debounce(this.requestConfig, 1000)
146+
147+
this.markAsConnected = function () {
148+
this.publish(`$aws/things/${this.credentials.thingId}/shadow/update`, {
149+
state: {
150+
reported: {
151+
connected: true,
152+
vsh_version: VSH_VERSION,
153+
nr_version: RED.version(),
154+
},
155+
},
156+
})
157+
}
158+
159+
this.markAsConnectedDebounced = debounce(this.markAsConnected, 7000)
160+
152161
this.publish = async function (topic, message) {
153162
if (!this.mqttClient) {
154163
return
@@ -161,8 +170,6 @@ module.exports = function (RED) {
161170
return await this.mqttClient.publish(topic, message)
162171
}
163172

164-
this.requestConfigDebounced = debounce(this.requestConfig, 1000)
165-
166173
this.triggerChangeReport = function ({
167174
endpointId,
168175
properties,
@@ -569,18 +576,7 @@ module.exports = function (RED) {
569576
text: 'online',
570577
})
571578

572-
this.publish(
573-
`$aws/things/${this.credentials.thingId}/shadow/update`,
574-
{
575-
state: {
576-
reported: {
577-
connected: true,
578-
vsh_version: VSH_VERSION,
579-
nr_version: RED.version(),
580-
},
581-
},
582-
}
583-
)
579+
this.markAsConnectedDebounced()
584580
},
585581

586582
onDisconnect: () => {

0 commit comments

Comments
 (0)