Bugfix connecting state

This commit is contained in:
Olivier Verhaegen 2023-04-12 16:02:19 +02:00 committed by GitHub
parent 1a0d1ce173
commit 3b24d81db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,9 +87,7 @@ module.exports = function(RED) {
}); });
// Connect to server if needed and subscribe // Connect to server if needed and subscribe
node.status({fill:"grey",shape:"ring",text:"connecting"}); const subscribe = () => {
function subscribe() {
node.log('subscribing to: '+node.topic); node.log('subscribing to: '+node.topic);
node.client.subscribe(node.topic, node.subscribeHeaders, function(body, headers) { node.client.subscribe(node.topic, node.subscribeHeaders, function(body, headers) {
var newmsg={"headers":headers,"topic":node.topic} var newmsg={"headers":headers,"topic":node.topic}
@ -104,6 +102,7 @@ module.exports = function(RED) {
} }
if (!node.server.connected) { if (!node.server.connected) {
node.status({fill:"grey",shape:"ring",text:"connecting"});
node.client.connect(function(sessionId) { node.client.connect(function(sessionId) {
subscribe(); subscribe();
}, function(error) { }, function(error) {
@ -176,8 +175,8 @@ module.exports = function(RED) {
}); });
// Connect to server if needed // Connect to server if needed
node.status({fill:"grey",shape:"ring",text:"connecting"});
if(!node.serverConfig.connected) { if(!node.serverConfig.connected) {
node.status({fill:"grey",shape:"ring",text:"connecting"});
node.client.connect(function(sessionId) {}, function(error) { node.client.connect(function(sessionId) {}, function(error) {
node.status({fill:"grey",shape:"dot",text:"error"}); node.status({fill:"grey",shape:"dot",text:"error"});
node.warn(error); node.warn(error);
@ -250,8 +249,8 @@ module.exports = function(RED) {
}); });
// Connect to server if needed // Connect to server if needed
node.status({fill:"grey",shape:"ring",text:"connecting"});
if(!node.serverConfig.connected) { if(!node.serverConfig.connected) {
node.status({fill:"grey",shape:"ring",text:"connecting"});
node.client.connect(function(sessionId) {}, function(error) { node.client.connect(function(sessionId) {}, function(error) {
node.status({fill:"grey",shape:"dot",text:"error"}); node.status({fill:"grey",shape:"dot",text:"error"});
node.warn(error); node.warn(error);