From 02c7d014cb7aa1fd1c06578eb71592b42cdc6ce1 Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Sat, 29 Apr 2023 21:00:26 +0100 Subject: [PATCH] dont use subscriptionIdentifier no broker support --- .../node_modules/@node-red/nodes/core/network/10-mqtt.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index 0a7ed6dfa..f4fc9ad2c 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -697,7 +697,8 @@ module.exports = function(RED) { node.options.rejectUnauthorized = (node.verifyservercert == "true" || node.verifyservercert === true); } } - + node.v5 = () => node.options && node.options.protocolVersion == 5 + node.subscriptionIdentifiersAvailable = () => node.v5() && node.serverProperties && node.serverProperties.subscriptionIdentifiersAvailable n.autoConnect = n.autoConnect === "false" || n.autoConnect === false ? false : true; node.setOptions(n, true); @@ -920,7 +921,12 @@ module.exports = function(RED) { }; node.subscriptions[topic][ref] = sub; if (node.connected) { + const subIdsAvailable = node.subscriptionIdentifiersAvailable() node._clientOn('message',sub.handler); + // if the broker doesn't support subscription identifiers (e.g. AWS core), then don't send them + if (options.properties && options.properties.subscriptionIdentifier && subIdsAvailable !== true) { + delete options.properties.subscriptionIdentifier + } node.client.subscribe(topic, options); } };