mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00: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.sessionId = null;
|
||||||
node.subscribtionIndex = 1;
|
node.subscribtionIndex = 1;
|
||||||
node.subscriptionIds = {};
|
node.subscriptionIds = {};
|
||||||
|
/** Array of callbacks to be called once the connection to the broker has been made */
|
||||||
|
node.connectedCallbacks = [];
|
||||||
/** @type { StompClient } */
|
/** @type { StompClient } */
|
||||||
node.client;
|
node.client;
|
||||||
node.setOptions = function(options, init) {
|
node.setOptions = function(options, init) {
|
||||||
@ -134,10 +136,20 @@ module.exports = function(RED) {
|
|||||||
*/
|
*/
|
||||||
node.register = function(stompNode, callback = () => {}) {
|
node.register = function(stompNode, callback = () => {}) {
|
||||||
node.users[stompNode.id] = stompNode;
|
node.users[stompNode.id] = stompNode;
|
||||||
|
|
||||||
|
if (!node.connected) {
|
||||||
|
node.connectedCallbacks.push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
// Auto connect when first STOMP processing node is added
|
// Auto connect when first STOMP processing node is added
|
||||||
if (Object.keys(node.users).length === 1) {
|
if (Object.keys(node.users).length === 1) {
|
||||||
node.connect(callback);
|
node.connect(() => {
|
||||||
|
while (node.connectedCallbacks.length) {
|
||||||
|
node.connectedCallbacks.shift().call();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// Execute callback directly as the connection to the STOMP server has already been made
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user