From df161ce67204474a12434e1c1969007735d03747 Mon Sep 17 00:00:00 2001 From: Lars Oldiges Date: Wed, 22 Aug 2018 13:20:49 +0200 Subject: [PATCH] Allows MQTT Shared Subscriptions for MQTT-In core node --- nodes/core/io/10-mqtt.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js index 509099aa4..d7cc027d3 100644 --- a/nodes/core/io/10-mqtt.js +++ b/nodes/core/io/10-mqtt.js @@ -24,6 +24,19 @@ module.exports = function(RED) { if (ts == "#") { return true; } + /* The following allows shared subscriptions (as in MQTT v5) + http://docs.oasis-open.org/mqtt/mqtt/v5.0/cs02/mqtt-v5.0-cs02.html#_Toc514345522 + + 4.8.2 describes shares like: + $share/{ShareName}/{filter} + $share is a literal string that marks the Topic Filter as being a Shared Subscription Topic Filter. + {ShareName} is a character string that does not include "/", "+" or "#" + {filter} The remainder of the string has the same syntax and semantics as a Topic Filter in a non-shared subscription. Refer to section 4.7. + */ + else if(ts.startsWith("$share")){ + ts = ts.replace(/^\$share\/[^#+/]+\/(.*)/g,"$1"); + + } var re = new RegExp("^"+ts.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(\/.*)?")+"$"); return re.test(t); }