Add node done to mqtt, http req and ws output nodes

This commit is contained in:
Nick O'Leary 2019-08-14 15:54:06 +01:00
parent fb9828badc
commit 84232f25f0
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 23 additions and 9 deletions

View File

@ -334,7 +334,7 @@ module.exports = function(RED) {
}
};
this.publish = function (msg) {
this.publish = function (msg,done) {
if (node.connected) {
if (msg.payload === null || msg.payload === undefined) {
msg.payload = "";
@ -350,7 +350,10 @@ module.exports = function(RED) {
qos: msg.qos || 0,
retain: msg.retain || false
};
node.client.publish(msg.topic, msg.payload, options, function(err) {return});
node.client.publish(msg.topic, msg.payload, options, function(err) {
done && done();
return
});
}
};
@ -453,7 +456,7 @@ module.exports = function(RED) {
if (this.brokerConn) {
this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
this.on("input",function(msg) {
this.on("input",function(msg,send,done) {
if (msg.qos) {
msg.qos = parseInt(msg.qos);
if ((msg.qos !== 0) && (msg.qos !== 1) && (msg.qos !== 2)) {
@ -468,9 +471,13 @@ module.exports = function(RED) {
}
if ( msg.hasOwnProperty("payload")) {
if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) { // topic must exist
this.brokerConn.publish(msg); // send the message
this.brokerConn.publish(msg, done); // send the message
} else {
node.warn(RED._("mqtt.errors.invalid-topic"));
done();
}
else { node.warn(RED._("mqtt.errors.invalid-topic")); }
} else {
done();
}
});
if (this.brokerConn.connected) {

View File

@ -50,7 +50,7 @@ module.exports = function(RED) {
noprox = proxyConfig.noproxy;
}
this.on("input",function(msg) {
this.on("input",function(msg,nodeSend,nodeDone) {
var preRequestTimestamp = process.hrtime();
node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"});
var url = nodeUrl || msg.url;
@ -62,12 +62,14 @@ module.exports = function(RED) {
}
if (!url) {
node.error(RED._("httpin.errors.no-url"),msg);
nodeDone();
return;
}
// url must start http:// or https:// so assume http:// if not set
if (url.indexOf("://") !== -1 && url.indexOf("http") !== 0) {
node.warn(RED._("httpin.errors.invalid-transport"));
node.status({fill:"red",shape:"ring",text:"httpin.errors.invalid-transport"});
nodeDone();
return;
}
if (!((url.indexOf("http://") === 0) || (url.indexOf("https://") === 0))) {
@ -261,10 +263,12 @@ module.exports = function(RED) {
}
} catch(err) {
node.error(RED._("httpin.errors.invalid-payload"),msg);
nodeDone();
return;
}
} else {
node.error(RED._("httpin.errors.invalid-payload"),msg);
nodeDone();
return;
}
}
@ -320,7 +324,8 @@ module.exports = function(RED) {
}
msg.payload = err.toString() + " : " + url;
msg.statusCode = err.code;
node.send(msg);
nodeSend(msg);
nodeDone();
}else{
msg.statusCode = res.statusCode;
msg.headers = res.headers;
@ -354,7 +359,8 @@ module.exports = function(RED) {
}
}
node.status({});
node.send(msg);
nodeSend(msg);
nodeDone();
}
});
});

View File

@ -309,7 +309,7 @@ module.exports = function(RED) {
node.status(status);
});
}
this.on("input", function(msg) {
this.on("input", function(msg, nodeSend, nodeDone) {
var payload;
if (this.serverConfig.wholemsg) {
var sess;
@ -337,6 +337,7 @@ module.exports = function(RED) {
});
}
}
nodeDone();
});
this.on('close', function() {
node.status({});