diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html
index d1a783ee0..45d6a2707 100644
--- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html
+++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html
@@ -76,15 +76,27 @@
+
+
+
+
+
+
@@ -110,16 +122,6 @@
-
-
-
-
@@ -135,9 +137,9 @@
qos: {value: "2"},
datatype: {value:"auto",required:true},
broker: {type:"mqtt-broker", required:true},
- userPropertiesType: {value:"json"},
- userProperties: {value:"{}"},
- subscriptionIdentifier: {value:0},
+ // userProperties: {value:"userProperties"},
+ // userPropertiesType: {value:"none"},
+ // subscriptionIdentifier: {value:0},
nl: {value:false},
rap: {value:true},
rh: {value:0},
@@ -168,11 +170,12 @@
if (this.datatype === undefined) {
$("#node-input-datatype").val("auto");
}
- $("#node-input-userProperties").typedInput({
- default: "json",
- types:['json','flow','global'],
- typeField: $("#node-input-userPropertiesType")
- });
+ // FUTURE
+ // $("#node-input-userProperties").typedInput({
+ // default: "none",
+ // types:[{ value: 'none', label: 'None', hasValue: false },'flow','global','json'],
+ // typeField: $("#node-input-userPropertiesType")
+ // });
}
});
@@ -203,33 +206,38 @@
+
+
+
+
+
-
+
+
-
-
-
-
-
-
+
+
-
+
+
+
+
@@ -257,16 +265,19 @@
topic: {value:""},
qos: {value:""},
retain: {value:""},
- responseTopic: {value:""},
- contentType: {value:""},
+ responseTopic: {value:"responseTopic"},
+ responseTopicType: {value:'none'},
+ contentType: {value:"contentType"},
+ contentTypeType: {value:'none'},
userProperties: {value:'userProperties'},
- userPropertiesType: {value:'msg'},
+ userPropertiesType: {value:'none'},
correlationData: {value:'correlationData'},
- correlationDataType: {value:'msg'},
- topicAlias: {value:0},
- messageExpiryInterval: {value:0},
- payloadFormatIndicator: {value:false},
- subscriptionIdentifier: {value:0},
+ correlationDataType: {value:'none'},
+ messageExpiryInterval: {value:"messageExpiryInterval"},
+ messageExpiryIntervalType: {value:'none'},
+ // FUTURE topicAlias: {value:0},
+ // FUTURE payloadFormatIndicator: {value:false},
+ // FUTURE subscriptionIdentifier: {value:0},
broker: {type:"mqtt-broker", required:true}
},
color:"#d8bfd8",
@@ -275,10 +286,13 @@
icon: "bridge.svg",
align: "right",
label: function() {
- return this.name||this.topic||(this.topicAlias ? "@"+this.topicAlias : "mqtt");
+ return this.name||this.topic||"mqtt";
+ // FUTURE return this.name||this.topic||(this.topicAlias ? "@"+this.topicAlias : "mqtt");
},
oneditprepare: function() {
- $("#node-input-broker").change(function(d){
+ var typedInputNoneOpt = { value: 'none', label: 'None', hasValue: false };
+
+ function showHideDynamicFields() {
var confNode = RED.nodes.node($("#node-input-broker").val());
var v5 = confNode && confNode.protocolVersion == "5";
if(v5) {
@@ -286,17 +300,99 @@
} else {
$("div.form-row.mqtt5").hide();
}
- });
- $("#node-input-correlationData").typedInput({
- default: "none",
- types:[{ value:"none", label: "None", hasValue:false },'bin','msg','flow','global'],
+ var t = $("#node-input-responseTopic").typedInput("type");
+ if (t == 'none') {
+ $("#node-input-correlationData").parent().hide();
+ } else {
+ $("#node-input-correlationData").parent().show();
+ }
+ }
+
+ $("#node-input-broker").change(function(d){
+ showHideDynamicFields();
+ });
+
+ var responseTopicTI = $("#node-input-responseTopic").typedInput({
+ default: 'none',
+ types: [typedInputNoneOpt, 'msg', 'flow', 'global', 'str'],
+ typeField: $("#node-input-responseTopicType")
+ });
+
+ var correlationDataTI = $("#node-input-correlationData").typedInput({
+ default: 'none',
+ types: [typedInputNoneOpt, 'msg', 'flow', 'global', 'bin'],
typeField: $("#node-input-correlationDataType")
});
+ //show / hide correlation data depending on responseTopic
+ responseTopicTI.on("change", function() {
+ showHideDynamicFields();
+ });
+ responseTopicTI.triggerHandler("change");
+
$("#node-input-userProperties").typedInput({
- default: "msg",
- types:['msg','flow','global','json'],
+ default: 'none',
+ types: [typedInputNoneOpt, 'msg', 'flow', 'global', 'json'],
typeField: $("#node-input-userPropertiesType")
});
+
+ $("#node-input-messageExpiryInterval").typedInput({
+ default: 'none',
+ types: [typedInputNoneOpt, 'msg', 'flow', 'global', 'num'],
+ typeField: $("#node-input-messageExpiryIntervalType")
+ });
+
+ var makeTypedInputOpt = function(value, label, tooltip){
+ return {
+ label: label,
+ value: value || label,
+ title: tooltip,
+ multiple: true
+ }
+ }
+ //TODO: i18n
+ var commonOpts = [
+ makeTypedInputOpt("application/gzip", "application/gzip", "GZip Compressed Archive"),
+ makeTypedInputOpt("application/json", "application/json", "JSON format"),
+ makeTypedInputOpt("application/octet-stream", "application/octet-stream", "Any kind of binary data"),
+ makeTypedInputOpt("application/ogg", "application/ogg", "OGG"),
+ makeTypedInputOpt("application/pdf", "application/pdf", "AdobeĀ Portable Document FormatĀ (PDF)"),
+ makeTypedInputOpt("application/zip", "application/zip", "ZIP archive"),
+ makeTypedInputOpt("audio/aac", "audio/aac", "AAC audio"),
+ makeTypedInputOpt("audio/midi", "audio/midi", "Musical Instrument Digital Interface (MIDI)"),
+ makeTypedInputOpt("audio/x-midi", "audio/x-midi", "Musical Instrument Digital Interface (MIDI)"),
+ makeTypedInputOpt("audio/mpeg", "audio/mpeg", "MP3 audio"),
+ makeTypedInputOpt("audio/ogg", "audio/ogg", "OGG audio"),
+ makeTypedInputOpt("audio/wav", "audio/wav", "Waveform Audio Format"),
+ makeTypedInputOpt("audio/webm", "audio/webm", "WEBM audio"),
+ makeTypedInputOpt("image/bmp", "image/bmp", "Windows OS/2 Bitmap Graphics"),
+ makeTypedInputOpt("image/gif", "image/gif", "Graphics Interchange Format (GIF)"),
+ makeTypedInputOpt("image/jpeg", "image/jpeg", "JPEG images"),
+ makeTypedInputOpt("image/png", "image/png", "Portable Network Graphics"),
+ makeTypedInputOpt("image/tiff", "image/tiff", "Tagged Image File Format (TIFF)"),
+ makeTypedInputOpt("image/webp", "image/webp", "WEBP image"),
+ makeTypedInputOpt("text/csv", "text/csv", "Comma-separated values (CSV)"),
+ makeTypedInputOpt("text/html", "text/html", "HyperText Markup Language (HTML)"),
+ makeTypedInputOpt("text/plain", "text/plain", "Text, (generally ASCII or ISO 8859-n)"),
+ makeTypedInputOpt("video/mpeg", "video/mpeg", "MPEG Video"),
+ makeTypedInputOpt("video/ogg", "video/ogg", "OGG video"),
+ makeTypedInputOpt("video/webm", "video/webm", "WEBM video"),
+ ];
+ $("#node-input-contentType").typedInput({
+ default: 'none',
+ types: [
+ typedInputNoneOpt,
+ {
+ value: "preset",
+ label: "Preset",
+ title: "Preset Content-Types",
+ icon: "fa fa-list",
+ showLabel: false,
+ multiple: false,
+ options: commonOpts,
+ default: "application/json"
+ }, 'msg', 'flow', 'global', 'str'],
+ typeField: $("#node-input-contentTypeType")
+ });
},
labelStyle: function() {
return this.name?"node_label_italic":"";
@@ -353,7 +449,8 @@
-
+
+
@@ -500,11 +597,11 @@
willRetain: {value:false},
willPayload: {value:""},
sessionExpiryInterval: {value:0},
- topicAliasMaximum: {value:0},
- maximumPacketSize: {value:0},
- receiveMaximum: {value:0},
- userPropertiesType: {value:"json"},
- userProperties: {value:"{}"},
+ // FUTURE topicAliasMaximum: {value:0},
+ // FUTURE maximumPacketSize: {value:0},
+ // FUTURE receiveMaximum: {value:0},
+ // FUTURE userPropertiesType: {value:"json"},
+ // FUTURE userProperties: {value:"{}"},
},
credentials: {
user: {type:"text"},
@@ -607,11 +704,12 @@
updateSessionExpiryIntervalVisibility();
});
$("#node-config-input-protocolVersion").val(this.protocolVersion);
- $("#node-config-input-userProperties").typedInput({
- default: "json",
- types:['json'],
- typeField: $("#node-config-input-userPropertiesType")
- });
+ // FUTURE
+ // $("#node-config-input-userProperties").typedInput({
+ // default: "json",
+ // types:['json'],
+ // typeField: $("#node-config-input-userPropertiesType")
+ // });
if (typeof this.keepalive === 'undefined') {
this.keepalive = 15;
$("#node-config-input-keepalive").val(this.keepalive);
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 5c9194b1a..103e161c5 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
@@ -140,7 +140,7 @@ module.exports = function(RED) {
if(!dst) return;
if (src && dst) {
var buf = src[propName];
- if (buf && typeof Buffer.isBuffer(buf)) {
+ if (buf && typeof Buffer.isBuffer(buf)) {
dst[propName] = Buffer.from(buf);
}
} else {
@@ -432,7 +432,7 @@ module.exports = function(RED) {
}
});
node.client.on("reconnect", function() {
- debug('MQTTBrokerNode reconnect event', packet); //TODO: remove
+ debug('MQTTBrokerNode reconnect event'); //TODO: remove
for (var id in node.users) {
if (node.users.hasOwnProperty(id)) {
node.users[id].status({fill:"yellow",shape:"ring",text:"node-red:common.status.connecting"});
@@ -560,15 +560,16 @@ module.exports = function(RED) {
if(node.options.protocolVersion == 5) {
options.properties = options.properties || {};
setStrProp(msg, options.properties, "responseTopic");
- setStrProp(msg, options.properties, "contentType");
- setIntProp(msg, options.properties, "topicAlias", 1, node.serverProperties.topicAliasMaximum || 0);
- setIntProp(msg, options.properties, "subscriptionIdentifier", 1, 268435455);
- setIntProp(msg, options.properties, "messageExpiryInterval", 0);
- setBoolProp(msg, options.properties, "payloadFormatIndicator");
- setUserProperties(msg.userProperties, options.properties);
setBufferProp(msg, options.properties, "correlationData");
+ setStrProp(msg, options.properties, "contentType");
+ setIntProp(msg, options.properties, "messageExpiryInterval", 0);
+ setUserProperties(msg.userProperties, options.properties);
+ setIntProp(msg, options.properties, "topicAlias", 1, node.serverProperties.topicAliasMaximum || 0);
+ setBoolProp(msg, options.properties, "payloadFormatIndicator");
+ //FUTURE setIntProp(msg, options.properties, "subscriptionIdentifier", 1, 268435455);
}
- debug(`MQTTBrokerNode:${node.id}: publish - sending payload to ${msg.topic ? msg.topic : (msg.topicAlias ? 'topicAlias-'+msg.topicAlias : '???') } `, options);//TODO: remove
+ // debug(`MQTTBrokerNode:${node.id}: publish - sending payload to ${msg.topic ? msg.topic : (msg.topicAlias ? 'topicAlias-'+msg.topicAlias : '???') } `, options);//TODO: remove
+ debug(`MQTTBrokerNode:${node.id}: publish - sending payload to ${msg.topic} `, options);//TODO: remove
node.client.publish(msg.topic, msg.payload, options, function(err) {
if(err) node.error(err,msg);//catch errors
done && done();
@@ -669,14 +670,14 @@ module.exports = function(RED) {
if(v5 && packet.properties) {
//msg.properties = packet.properties;
setStrProp(packet.properties, msg, "responseTopic");
+ setBufferProp(packet.properties, msg, "correlationData");
setStrProp(packet.properties, msg, "contentType");
- setIntProp(packet.properties, msg, "topicAlias", 1, node.brokerConn.serverProperties.topicAliasMaximum || 0);
- setIntProp(packet.properties, msg, "subscriptionIdentifier", 1, 268435455);
+ // setIntProp(packet.properties, msg, "topicAlias", 1, node.brokerConn.serverProperties.topicAliasMaximum || 0);
+ // setIntProp(packet.properties, msg, "subscriptionIdentifier", 1, 268435455);
setIntProp(packet.properties, msg, "messageExpiryInterval", 0);
setBoolProp(packet.properties, msg, "payloadFormatIndicator");
setStrProp(packet.properties, msg, "reasonString");
setUserProperties(packet.properties.userProperties, msg);
- setBufferProp(packet.properties, msg, "correlationData");
}
if ((node.brokerConn.broker === "localhost")||(node.brokerConn.broker === "127.0.0.1")) {
msg._topic = topic;
@@ -709,15 +710,18 @@ module.exports = function(RED) {
this.retain = n.retain;
this.broker = n.broker;
this.responseTopic = n.responseTopic;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901114
+ this.responseTopicType = n.responseTopicType;
this.correlationData = n.correlationData;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901115
this.correlationDataType = n.correlationDataType;
this.contentType = n.contentType;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901118
- this.topicAlias = n.topicAlias; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113
+ this.contentTypeType = n.contentTypeType;
this.messageExpiryInterval = n.messageExpiryInterval; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901112
- this.payloadFormatIndicator = n.payloadFormatIndicator; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901111
- this.subscriptionIdentifier = n.subscriptionIdentifier;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901117
+ this.messageExpiryIntervalType = n.messageExpiryIntervalType;
this.userProperties = n.userProperties;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901116
this.userPropertiesType = n.userPropertiesType;
+ // this.topicAlias = n.topicAlias; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113
+ // this.payloadFormatIndicator = n.payloadFormatIndicator; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901111
+ // this.subscriptionIdentifier = n.subscriptionIdentifier;//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901117
this.brokerConn = RED.nodes.getNode(this.broker);
var node = this;
@@ -740,26 +744,35 @@ module.exports = function(RED) {
let msgPropOverride = function(propName) { if(node[propName]) { msg[propName] = node[propName]; } }
msgPropOverride("topic");
if(v5) {
- if(node.userProperties) {
+ if(node.userProperties && node.userPropertiesType !== "none") {
let userProperties = RED.util.evaluateNodeProperty(node.userProperties, node.userPropertiesType, node, msg);
if(userProperties) msg.userProperties = userProperties;
}
+ if(node.responseTopic && node.responseTopicType !== "none") {
+ let responseTopic = RED.util.evaluateNodeProperty(node.responseTopic, node.responseTopicType, node, msg);
+ if(responseTopic) msg.responseTopic = responseTopic;
+ }
if(node.correlationData && node.correlationDataType !== "none") {
let correlationData = RED.util.evaluateNodeProperty(node.correlationData, node.correlationDataType, node, msg);
if(correlationData) msg.correlationData = correlationData;
}
- //Next, update/override the msg.xxxx properties from config
+ if(node.contentType && node.contentTypeType !== "none") {
+ let contentType = RED.util.evaluateNodeProperty(node.contentType, node.contentTypeType, node, msg);
+ if(contentType) msg.contentType = contentType;
+ }
+ if(node.messageExpiryInterval && node.messageExpiryIntervalType !== "none") {
+ let messageExpiryInterval = RED.util.evaluateNodeProperty(node.messageExpiryInterval, node.messageExpiryIntervalType, node, msg);
+ if(messageExpiryInterval) msg.messageExpiryInterval = messageExpiryInterval;
+ }
+ //Next, update/override the msg.xxxx properties from node config
//TODO: Should we be expecting msg.properties.xxxx instead of msg.xxxx?
- msgPropOverride("responseTopic");
- msgPropOverride("contentType");
- msgPropOverride("topicAlias");
- msgPropOverride("messageExpiryInterval");
- msgPropOverride("payloadFormatIndicator");
- msgPropOverride("subscriptionIdentifier");
- setIntProp(msg,msg,"topicAlias");
- setIntProp(msg,msg,"messageExpiryInterval");
- setBoolProp(msg,msg,"payloadFormatIndicator");
- setIntProp(msg,msg,"subscriptionIdentifier");
+ // setStrProp(node,msg,"responseTopic");
+ // setBufferProp(node,msg,"correlationData");
+ // setStrProp(node,msg,"contentType");
+ // setIntProp(node,msg,"messageExpiryInterval");
+ //FUTURE setStrProp(node,msg,"topicAlias");
+ //FUTURE setBoolProp(node,msg,"payloadFormatIndicator");
+ //FUTURE setIntProp(node,msg,"subscriptionIdentifier");
}
if ( msg.hasOwnProperty("payload")) {
let topicOK = msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "");