1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

design/TODO comments

This commit is contained in:
Steve-Mcl 2020-12-07 12:26:27 +00:00
parent 6bac207611
commit 00db43198d

View File

@ -439,12 +439,12 @@ module.exports = function(RED) {
} }
} }
}); });
//TODO: what to do with this event? Anything? Necessary?
node.client.on("disconnect", function(packet) { node.client.on("disconnect", function(packet) {
//Emitted after receiving disconnect packet from broker. MQTT 5.0 feature. //Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
console.log('MQTTBrokerNode disconnect', packet) console.log('MQTTBrokerNode disconnect', packet)
var rc = packet && packet.properties && packet.properties.reasonString; var rc = packet && packet.properties && packet.properties.reasonString;
var rc = packet && packet.properties && packet.reasonCode; var rc = packet && packet.properties && packet.reasonCode;
//TODO: what to do with this event? Anything necessary?
}); });
// Register disconnect handlers // Register disconnect handlers
node.client.on('close', function () { node.client.on('close', function () {
@ -733,6 +733,7 @@ module.exports = function(RED) {
msg.qos = Number(node.qos || msg.qos || 0); msg.qos = Number(node.qos || msg.qos || 0);
msg.retain = node.retain || msg.retain || false; msg.retain = node.retain || msg.retain || false;
msg.retain = ((msg.retain === true) || (msg.retain === "true")) || false; msg.retain = ((msg.retain === true) || (msg.retain === "true")) || false;
/** If node property exists, override/set that to property in msg */
let msgPropOverride = function(propName) { if(node[propName]) { msg[propName] = node[propName]; } } let msgPropOverride = function(propName) { if(node[propName]) { msg[propName] = node[propName]; } }
msgPropOverride("topic"); msgPropOverride("topic");
if(v5) { if(v5) {
@ -744,6 +745,8 @@ module.exports = function(RED) {
let correlationData = RED.util.evaluateNodeProperty(node.correlationData, node.correlationDataType, node, msg); let correlationData = RED.util.evaluateNodeProperty(node.correlationData, node.correlationDataType, node, msg);
if(correlationData) msg.correlationData = correlationData; if(correlationData) msg.correlationData = correlationData;
} }
//Next, update/override the msg.xxxx properties from config
//TODO: Should we be expecting msg.properties.xxxx instead of msg.xxxx?
msgPropOverride("responseTopic"); msgPropOverride("responseTopic");
msgPropOverride("contentType"); msgPropOverride("contentType");
msgPropOverride("topicAlias"); msgPropOverride("topicAlias");
@ -758,12 +761,15 @@ module.exports = function(RED) {
if ( msg.hasOwnProperty("payload")) { if ( msg.hasOwnProperty("payload")) {
let topicOK = msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== ""); let topicOK = msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "");
if (!topicOK && v5) { if (!topicOK && v5) {
//NOTE: A value of 0 (in server props topicAliasMaximum) indicates that the Server does not accept any Topic Aliases on this connection
if (msg.hasOwnProperty("topicAlias") && typeof msg.topicAlias === "number" && msg.topicAlias >= 0 && node.brokerConn.serverProperties.topicAliasMaximum && node.brokerConn.serverProperties.topicAliasMaximum >= msg.topicAlias) { if (msg.hasOwnProperty("topicAlias") && typeof msg.topicAlias === "number" && msg.topicAlias >= 0 && node.brokerConn.serverProperties.topicAliasMaximum && node.brokerConn.serverProperties.topicAliasMaximum >= msg.topicAlias) {
topicOK = true; topicOK = true;
msg.topic = ""; //must be empty string msg.topic = ""; //must be empty string
} else if (msg.hasOwnProperty("responseTopic") && (typeof msg.responseTopic === "string") && (msg.responseTopic !== "")) { } else if (msg.hasOwnProperty("responseTopic") && (typeof msg.responseTopic === "string") && (msg.responseTopic !== "")) {
//TODO: if topic is empty but responseTopic has a string value, use that instead. Is this desirable?
topicOK = true; topicOK = true;
msg.topic = msg.responseTopic; msg.topic = msg.responseTopic;
//TODO: delete msg.responseTopic - to prevent it being resent?
} }
} }
if (topicOK) { // topic must exist if (topicOK) { // topic must exist