mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Bugfix: only execute node register callbacks after connection to the server has been made
This commit is contained in:
parent
a2b7e1a30c
commit
8e9169c123
@ -84,6 +84,8 @@ module.exports = function(RED) {
|
||||
node.sessionId = null;
|
||||
node.subscribtionIndex = 1;
|
||||
node.subscriptionIds = {};
|
||||
/** Array of callbacks to be called once the connection to the broker has been made */
|
||||
node.connectedCallbacks = [];
|
||||
/** @type { StompClient } */
|
||||
node.client;
|
||||
node.setOptions = function(options, init) {
|
||||
@ -134,10 +136,20 @@ module.exports = function(RED) {
|
||||
*/
|
||||
node.register = function(stompNode, callback = () => {}) {
|
||||
node.users[stompNode.id] = stompNode;
|
||||
|
||||
if (!node.connected) {
|
||||
node.connectedCallbacks.push(callback);
|
||||
}
|
||||
|
||||
// Auto connect when first STOMP processing node is added
|
||||
if (Object.keys(node.users).length === 1) {
|
||||
node.connect(callback);
|
||||
node.connect(() => {
|
||||
while (node.connectedCallbacks.length) {
|
||||
node.connectedCallbacks.shift().call();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Execute callback directly as the connection to the STOMP server has already been made
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user