@node-red/nodes 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/network/10-mqtt.js +32 -33
- package/package.json +1 -1
package/core/network/10-mqtt.js
CHANGED
|
@@ -637,24 +637,8 @@ module.exports = function(RED) {
|
|
|
637
637
|
|
|
638
638
|
node.deregister = function(mqttNode,done) {
|
|
639
639
|
delete node.users[mqttNode.id];
|
|
640
|
-
if (node.closing) {
|
|
641
|
-
|
|
642
|
-
}
|
|
643
|
-
if (Object.keys(node.users).length === 0) {
|
|
644
|
-
if (node.client && node.client.connected) {
|
|
645
|
-
// Send close message
|
|
646
|
-
if (node.closeMessage) {
|
|
647
|
-
node.publish(node.closeMessage,function(err) {
|
|
648
|
-
node.client.end(done);
|
|
649
|
-
});
|
|
650
|
-
} else {
|
|
651
|
-
node.client.end(done);
|
|
652
|
-
}
|
|
653
|
-
return;
|
|
654
|
-
} else {
|
|
655
|
-
if (node.client) { node.client.end(); }
|
|
656
|
-
return done();
|
|
657
|
-
}
|
|
640
|
+
if (!node.closing && node.connected && Object.keys(node.users).length === 0) {
|
|
641
|
+
node.disconnect();
|
|
658
642
|
}
|
|
659
643
|
done();
|
|
660
644
|
};
|
|
@@ -663,6 +647,7 @@ module.exports = function(RED) {
|
|
|
663
647
|
}
|
|
664
648
|
node.connect = function (callback) {
|
|
665
649
|
if (node.canConnect()) {
|
|
650
|
+
node.closing = false;
|
|
666
651
|
node.connecting = true;
|
|
667
652
|
setStatusConnecting(node, true);
|
|
668
653
|
try {
|
|
@@ -672,6 +657,7 @@ module.exports = function(RED) {
|
|
|
672
657
|
let callbackDone = false; //prevent re-connects causing node.client.on('connect' firing callback multiple times
|
|
673
658
|
// Register successful connect or reconnect handler
|
|
674
659
|
node.client.on('connect', function (connack) {
|
|
660
|
+
node.closing = false;
|
|
675
661
|
node.connecting = false;
|
|
676
662
|
node.connected = true;
|
|
677
663
|
if(!callbackDone && typeof callback == "function") {
|
|
@@ -740,6 +726,7 @@ module.exports = function(RED) {
|
|
|
740
726
|
reasonCode: rc,
|
|
741
727
|
reasonString: rs
|
|
742
728
|
}
|
|
729
|
+
node.connected = false;
|
|
743
730
|
node.log(RED._("mqtt.state.broker-disconnected", details));
|
|
744
731
|
setStatusDisconnected(node, true);
|
|
745
732
|
});
|
|
@@ -764,25 +751,31 @@ module.exports = function(RED) {
|
|
|
764
751
|
}
|
|
765
752
|
};
|
|
766
753
|
node.disconnect = function (callback) {
|
|
767
|
-
const _callback = function () {
|
|
754
|
+
const _callback = function (resetNodeConnectedState) {
|
|
768
755
|
setStatusDisconnected(node, true);
|
|
769
|
-
|
|
770
|
-
|
|
756
|
+
if(resetNodeConnectedState) {
|
|
757
|
+
node.closing = true;
|
|
758
|
+
node.connecting = false;
|
|
759
|
+
node.connected = false;
|
|
760
|
+
}
|
|
771
761
|
callback && typeof callback == "function" && callback();
|
|
772
762
|
};
|
|
773
763
|
|
|
774
|
-
if(node.
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
_callback();
|
|
783
|
-
}
|
|
764
|
+
if(node.closing) {
|
|
765
|
+
return _callback(false);
|
|
766
|
+
}
|
|
767
|
+
var endCallBack = function endCallBack() {
|
|
768
|
+
}
|
|
769
|
+
if(node.connected && node.closeMessage) {
|
|
770
|
+
node.publish(node.closeMessage, function (err) {
|
|
771
|
+
node.client.end(endCallBack);
|
|
772
|
+
_callback(true);
|
|
773
|
+
});
|
|
774
|
+
} else if(node.connected) {
|
|
775
|
+
node.client.end(endCallBack);
|
|
776
|
+
_callback(true);
|
|
784
777
|
} else {
|
|
785
|
-
_callback();
|
|
778
|
+
_callback(false);
|
|
786
779
|
}
|
|
787
780
|
}
|
|
788
781
|
node.subscriptionIds = {};
|
|
@@ -1074,6 +1067,8 @@ module.exports = function(RED) {
|
|
|
1074
1067
|
node.brokerConn.unsubscribe(node.topic,node.id, removed);
|
|
1075
1068
|
}
|
|
1076
1069
|
node.brokerConn.deregister(node, done);
|
|
1070
|
+
} else {
|
|
1071
|
+
done();
|
|
1077
1072
|
}
|
|
1078
1073
|
});
|
|
1079
1074
|
} else {
|
|
@@ -1134,7 +1129,11 @@ module.exports = function(RED) {
|
|
|
1134
1129
|
}
|
|
1135
1130
|
node.brokerConn.register(node);
|
|
1136
1131
|
node.on('close', function(done) {
|
|
1137
|
-
node.brokerConn
|
|
1132
|
+
if (node.brokerConn) {
|
|
1133
|
+
node.brokerConn.deregister(node,done);
|
|
1134
|
+
} else {
|
|
1135
|
+
done();
|
|
1136
|
+
}
|
|
1138
1137
|
});
|
|
1139
1138
|
} else {
|
|
1140
1139
|
node.error(RED._("mqtt.errors.missing-config"));
|