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

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 (node.connected) {
if (msg.payload === null || msg.payload === undefined) { if (msg.payload === null || msg.payload === undefined) {
msg.payload = ""; msg.payload = "";
@ -350,7 +350,10 @@ module.exports = function(RED) {
qos: msg.qos || 0, qos: msg.qos || 0,
retain: msg.retain || false 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) { if (this.brokerConn) {
this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"}); 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) { if (msg.qos) {
msg.qos = parseInt(msg.qos); msg.qos = parseInt(msg.qos);
if ((msg.qos !== 0) && (msg.qos !== 1) && (msg.qos !== 2)) { 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("payload")) {
if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) { // topic must exist 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) { if (this.brokerConn.connected) {

View File

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

View File

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