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); }