mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'master' into tabs
This commit is contained in:
commit
adc6b44840
@ -30,6 +30,7 @@ function Xml2jsNode(n) {
|
||||
this.useEyes = n.useEyes;
|
||||
var node = this;
|
||||
this.on("input", function(msg) {
|
||||
try {
|
||||
parseString(msg.payload, function (err, result) {
|
||||
if (err) { node.error(err); }
|
||||
else {
|
||||
@ -41,6 +42,8 @@ function Xml2jsNode(n) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(e) { console.log(e); }
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xml2js",Xml2jsNode);
|
||||
|
@ -79,9 +79,7 @@ function HTTPRequest(n) {
|
||||
var httplib = (/^https/.test(url))?https:http;
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
if (msg.url) {
|
||||
httplib = (/^https/.test(msg.url))?https:http;
|
||||
}
|
||||
|
||||
var opts = urllib.parse(msg.url||url);
|
||||
opts.method = (msg.method||method).toUpperCase();
|
||||
if (msg.headers) {
|
||||
@ -89,16 +87,14 @@ function HTTPRequest(n) {
|
||||
}
|
||||
var req = httplib.request(opts,function(res) {
|
||||
res.setEncoding('utf8');
|
||||
var message = {
|
||||
statusCode: res.statusCode,
|
||||
headers: res.headers,
|
||||
payload: ""
|
||||
};
|
||||
msg.statusCode = res.statusCode;
|
||||
msg.headers = res.headers;
|
||||
msg.payload = "";
|
||||
res.on('data',function(chunk) {
|
||||
message.payload += chunk;
|
||||
msg.payload += chunk;
|
||||
});
|
||||
res.on('end',function() {
|
||||
node.send(message);
|
||||
node.send(msg);
|
||||
});
|
||||
});
|
||||
req.on('error',function(err) {
|
||||
@ -106,7 +102,7 @@ function HTTPRequest(n) {
|
||||
msg.statusCode = err.code;
|
||||
node.send(msg);
|
||||
});
|
||||
if (msg.payload && (method == "POST" || method == "PUT") ) {
|
||||
if (msg.payload && (method == "PUSH" || method == "PUT") ) {
|
||||
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
|
||||
req.write(msg.payload);
|
||||
} else if (typeof msg.payload == "number") {
|
||||
|
@ -62,7 +62,8 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="udp in">
|
||||
<p>A udp input node, that produces a <b>msg.payload</b> containing a <i>BUFFER</i>, string, or base64 encoded string. Supports multicast.</p>
|
||||
<p>It also provides <b>msg.fromip</b> in the form ipaddress:port .</p>
|
||||
<p>It also provides <b>msg.ip</b> and <b>msg.port</b> to the ip address and port from which the message was received.</b>
|
||||
<p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -122,6 +123,7 @@
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">Tip: leave address and port blank if you want to set using <b>msg.ip</b> and <b>msg.port</b>.</div>
|
||||
<script>
|
||||
$("#node-input-multicast").change(function() {
|
||||
var id = $("#node-input-multicast option:selected").val();
|
||||
@ -145,8 +147,9 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="udp out">
|
||||
<p>This node sends <b>msg.payload</b> to the designated udp host and port. Supports multicast.</p>
|
||||
<p>You may also use <b>msg.ip</b> and <b>msg.port</b> to set the destination values.<br/><b>Note</b>: the statically configured values have precedence.</p>
|
||||
<p>If you select broadcast either set the address to the local broadcast ip address, or maybe try 255.255.255.255, which is the global broadcast address.</p>
|
||||
<p>On some systems you may need to be root to use broadcast.</p>
|
||||
<p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -155,10 +158,9 @@
|
||||
color:"Silver",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
addr: {value:"",required:true},
|
||||
//group: {value:""},
|
||||
addr: {value:""},
|
||||
iface: {value:""},
|
||||
port: {value:"",required:true,validate:RED.validators.number()},
|
||||
port: {value:""},
|
||||
base64: {value:false,required:true},
|
||||
multicast: {value:"false"}
|
||||
},
|
||||
|
@ -31,7 +31,9 @@ function UDPin(n) {
|
||||
var server = dgram.createSocket('udp4');
|
||||
|
||||
server.on("error", function (err) {
|
||||
console.log("udp listener error:\n" + err.stack);
|
||||
//console.log("udp listener error:\n" + err.stack);
|
||||
if ((err.code == "EACCES") && (node.port < 1024)) { node.error("UDP access error, you may need root access for ports below 1024"); }
|
||||
else { node.error("UDP error : "+err.code); }
|
||||
server.close();
|
||||
});
|
||||
|
||||
@ -39,7 +41,7 @@ function UDPin(n) {
|
||||
var msg;
|
||||
if (node.datatype =="base64") { msg = { payload:message.toString('base64'), fromip:remote.address+':'+remote.port }; }
|
||||
else if (node.datatype =="utf8") { msg = { payload:message.toString('utf8'), fromip:remote.address+':'+remote.port }; }
|
||||
else { msg = { payload:message, fromip:remote.address+':'+remote.port }; }
|
||||
else { msg = { payload:message, fromip:remote.address+':'+remote.port, ip:remote.address, port:remote.port }; }
|
||||
node.send(msg);
|
||||
});
|
||||
|
||||
@ -93,15 +95,22 @@ function UDPout(n) {
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload != null) {
|
||||
//console.log("UDP:",msg.payload);
|
||||
var add = node.addr || msg.ip || "";
|
||||
var por = node.port || msg.port || 0;
|
||||
if (add == "") { node.warn("udp: ip address not set"); }
|
||||
else if (por == 0) { node.warn("udp: port not set"); }
|
||||
else if (isNaN(por) || (por < 1) || (por > 65535)) { node.warn("udp: port number not valid"); }
|
||||
else {
|
||||
var message;
|
||||
if (node.base64) { message = new Buffer(b64string, 'base64'); }
|
||||
else if (msg.payload instanceof Buffer) { message = msg.payload; }
|
||||
else { message = new Buffer(""+msg.payload); }
|
||||
console.log("UDP send :",node.addr,node.port);
|
||||
sock.send(message, 0, message.length, node.port, node.addr, function(err, bytes) {
|
||||
console.log("UDP send :",add,por,msg.payload.toString());
|
||||
sock.send(message, 0, message.length, por, add, function(err, bytes) {
|
||||
if (err) node.error("udp : "+err);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
node.on("close", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user