2013-10-11 22:42:34 +02:00
<!--
2016-01-17 11:34:40 +01:00
Copyright 2013,2016 IBM Corp.
2013-10-11 22:42:34 +02:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The Input Node -->
< script type = "text/x-red" data-template-name = "udp in" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-port" > < i class = "fa fa-sign-in" > < / i > < span data-i18n = "udp.label.listen" > < / span > < / label >
2016-06-27 00:48:59 +02:00
< select id = "node-input-multicast" style = 'width:70%' >
2015-05-10 22:47:22 +02:00
< option value = "false" data-i18n = "udp.udpmsgs" > < / option >
< option value = "true" data-i18n = "udp.mcmsgs" > < / option >
2013-10-11 22:42:34 +02:00
< / select >
< / div >
< div class = "form-row node-input-group" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-group" > < i class = "fa fa-list" > < / i > < span data-i18n = "udp.label.group" > < / span > < / label >
2013-10-11 22:42:34 +02:00
< input type = "text" id = "node-input-group" placeholder = "225.0.18.83" >
< / div >
< div class = "form-row node-input-iface" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-iface" > < i class = "fa fa-random" > < / i > < span data-i18n = "udp.label.interface" > < / span > < / label >
2016-02-11 23:21:12 +01:00
< input type = "text" id = "node-input-iface" data-i18n = "[placeholder]udp.label.interfaceprompt" >
2013-10-11 22:42:34 +02:00
< / div >
2015-03-05 14:07:38 +01:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-port" > < i class = "fa fa-sign-in" > < / i > < span data-i18n = "udp.label.onport" > < / span > < / label >
2015-05-28 22:55:22 +02:00
< input type = "text" id = "node-input-port" style = "width: 80px" >
2015-05-10 22:47:22 +02:00
< span data-i18n = "udp.label.using" > < / span > < select id = "node-input-ipv" style = "width:80px" >
2015-03-05 14:07:38 +01:00
< option value = "udp4" > ipv4< / option >
< option value = "udp6" > ipv6< / option >
< / select >
< / div >
2013-10-11 22:42:34 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-datatype" > < i class = "fa fa-sign-out" > < / i > < span data-i18n = "udp.label.output" > < / span > < / label >
2013-10-11 22:42:34 +02:00
< select id = "node-input-datatype" style = "width: 70%;" >
2015-05-28 22:55:22 +02:00
< option value = "buffer" data-i18n = "udp.output.buffer" > < / option >
< option value = "utf8" data-i18n = "udp.output.string" > < / option >
< option value = "base64" data-i18n = "udp.output.base64" > < / option >
2013-10-11 22:42:34 +02:00
< / select >
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-10-11 22:42:34 +02:00
< / div >
2015-05-28 22:55:22 +02:00
< div class = "form-tips" > < span data-i18n = "udp.tip.in" > < / span > < / div >
2016-01-17 11:34:40 +01:00
< div class = "form-tips" id = "udpporttip" > < span data-i18n = "[html]udp.tip.port" > < / span > < / div >
2013-10-11 22:42:34 +02:00
< / script >
< script type = "text/x-red" data-help-name = "udp in" >
2016-02-11 23:21:12 +01:00
< p > A UDP input node, that produces a < code > msg.payload< / code > containing a
Buffer, string, or base64 encoded string. Supports multicast.< / p >
< p > It also provides < code > msg.ip< / code > and < code > msg.port< / code > set to the
ip address and port from which the message was received.< / p >
2016-02-12 14:17:21 +01:00
< p > < b > Note< / b > : On some systems you may need to be root to use ports below 1024 and/or broadcast.< / p >
2013-10-11 22:42:34 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('udp in',{
category: 'input',
color:"Silver",
defaults: {
name: {value:""},
iface: {value:""},
port: {value:"",required:true,validate:RED.validators.number()},
2015-03-05 14:07:38 +01:00
ipv: {value:"udp4"},
2013-10-11 22:42:34 +02:00
multicast: {value:"false"},
2015-03-05 14:07:38 +01:00
group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} },
datatype: {value:"buffer",required:true}
2013-10-11 22:42:34 +02:00
},
inputs:0,
outputs:1,
icon: "bridge-dash.png",
label: function() {
if (this.multicast=="false") {
return this.name||"udp "+this.port;
}
else return this.name||"udp "+(this.group+":"+this.port);
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2015-05-10 22:47:22 +02:00
},
oneditprepare: function() {
$("#node-input-multicast").change(function() {
var id = $("#node-input-multicast option:selected").val();
if (id == "false") {
$(".node-input-group").hide();
$(".node-input-iface").hide();
}
else {
$(".node-input-group").show();
$(".node-input-iface").show();
}
});
$("#node-input-multicast").change();
2016-01-17 11:34:40 +01:00
var porttip = this._("udp.tip.port");
var alreadyused = this._("udp.errors.alreadyused");
var portsInUse = {};
$.getJSON('udp-ports/'+this.id,function(data) {
portsInUse = data || {};
$('#udpporttip').html(porttip + Object.keys(data||{}));
});
$("#node-input-port").change(function() {
var portnew = $("#node-input-port").val();
if (portsInUse.hasOwnProperty($("#node-input-port").val())) {
RED.notify(alreadyused+" "+$("#node-input-port").val(),"warn");
}
});
2013-10-11 22:42:34 +02:00
}
});
< / script >
<!-- The Output Node -->
< script type = "text/x-red" data-template-name = "udp out" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-port" > < i class = "fa fa-envelope" > < / i > < span data-i18n = "udp.label.send" > < / span > < / label >
2015-03-05 14:07:38 +01:00
< select id = "node-input-multicast" style = "width:40%" >
2015-05-10 22:47:22 +02:00
< option value = "false" data-i18n = "udp.udpmsg" > < / option >
< option value = "broad" data-i18n = "udp.bcmsg" > < / option >
< option value = "multi" data-i18n = "udp.mcmsg" > < / option >
2013-10-11 22:42:34 +02:00
< / select >
2015-05-28 22:55:22 +02:00
< span data-i18n = "udp.label.toport" > < / span > < input type = "text" id = "node-input-port" style = "width: 70px" >
2013-10-11 22:42:34 +02:00
< / div >
< div class = "form-row node-input-addr" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-addr" id = "node-input-addr-label" > < i class = "fa fa-list" > < / i > < span data-i18n = "udp.label.address" > < / span > < / label >
2015-05-28 22:55:22 +02:00
< input type = "text" id = "node-input-addr" data-i18n = "[placeholder]udp.placeholder.address" style = "width: 50%;" >
2015-03-05 14:07:38 +01:00
< select id = "node-input-ipv" style = "width:70px" >
< option value = "udp4" > ipv4< / option >
< option value = "udp6" > ipv6< / option >
< / select >
2013-10-11 22:42:34 +02:00
< / div >
< div class = "form-row node-input-iface" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-iface" > < i class = "fa fa-random" > < / i > < span data-i18n = "udp.label.interface" > < / span > < / label >
2015-05-28 22:55:22 +02:00
< input type = "text" id = "node-input-iface" data-i18n = "[placeholder]udp.placeholder.interface" >
2014-03-28 00:27:43 +01:00
< / div >
< div class = "form-row" >
2014-03-31 00:05:59 +02:00
< label for = "node-input-outport-type" > < / label >
< select id = "node-input-outport-type" >
2015-05-28 22:55:22 +02:00
< option id = "node-input-outport-type-random" value = "random" data-i18n = "udp.bind.random" > < / option >
< option value = "fixed" data-i18n = "udp.bind.local" > < / option >
2014-03-31 00:05:59 +02:00
< / select >
2015-05-28 22:55:22 +02:00
< input type = "text" id = "node-input-outport" style = "width: 70px;" >
2013-10-11 22:42:34 +02:00
< / div >
< div class = "form-row" >
< label > < / label >
2014-03-28 00:27:43 +01:00
< input type = "checkbox" id = "node-input-base64" style = "display: inline-block; width: auto; vertical-align: top;" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-base64" style = "width: 70%;" > < span data-i18n = "udp.label.decode-base64" > < / span > < / label >
2013-10-11 22:42:34 +02:00
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-10-11 22:42:34 +02:00
< / div >
2015-05-28 22:55:22 +02:00
< div class = "form-tips" > < span data-i18n = "[html]udp.tip.out" > < / span > < / div >
2013-10-11 22:42:34 +02:00
< / script >
< script type = "text/x-red" data-help-name = "udp out" >
2016-02-11 23:21:12 +01:00
< p > This node sends < code > msg.payload< / code > to the designated UDP host and port. Supports multicast.< / p >
2016-02-12 14:17:21 +01:00
< p > You may also use < code > msg.ip< / code > and < code > msg.port< / code > to set the destination values, but the statically configured values have precedence.< / p >
2013-10-11 22:42:34 +02:00
< 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 >
2016-02-12 14:17:21 +01:00
< p > < b > Note< / b > : On some systems you may need to be root to use ports below 1024 and/or broadcast.< / p >
2013-10-11 22:42:34 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('udp out',{
category: 'output',
color:"Silver",
defaults: {
name: {value:""},
2013-10-25 12:27:21 +02:00
addr: {value:""},
2013-10-11 22:42:34 +02:00
iface: {value:""},
2013-10-25 12:27:21 +02:00
port: {value:""},
2015-03-05 14:07:38 +01:00
ipv: {value:"udp4"},
2014-03-28 00:27:43 +01:00
outport: {value:""},
2013-10-11 22:42:34 +02:00
base64: {value:false,required:true},
multicast: {value:"false"}
},
inputs:1,
outputs:0,
icon: "bridge-dash.png",
align: "right",
label: function() {
return this.name||"udp "+(this.addr+":"+this.port);
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2014-03-31 00:05:59 +02:00
},
oneditprepare: function() {
2015-05-10 22:47:22 +02:00
var addresslabel = this._("udp.label.address");
2015-05-28 22:55:22 +02:00
var addressph = this._("udp.placeholder.address");
2015-05-10 22:47:22 +02:00
var grouplabel = this._("udp.label.group");
2015-05-28 22:55:22 +02:00
var bindrandom = this._("udp.bind.random");
var bindtarget = this._("udp.bind.target");
2015-05-10 22:47:22 +02:00
2014-03-31 00:05:59 +02:00
var type = this.outport==""?"random":"fixed";
$("#node-input-outport-type option").filter(function() {
return $(this).val() == type;
}).attr('selected',true);
2014-09-07 23:12:25 +02:00
2014-03-31 00:05:59 +02:00
$("#node-input-outport-type").change(function() {
var type = $(this).children("option:selected").val();
if (type == "random") {
$("#node-input-outport").val("").hide();
} else {
$("#node-input-outport").show();
}
});
$("#node-input-outport-type").change();
2014-09-07 23:12:25 +02:00
2014-03-31 14:06:29 +02:00
$("#node-input-multicast").change(function() {
2015-05-10 22:47:22 +02:00
var id = $("#node-input-multicast option:selected").val();
if (id === "multi") {
$(".node-input-iface").show();
$("#node-input-addr-label").html('< i class = "fa fa-list" > < / i > ' + grouplabel);
$("#node-input-addr")[0].placeholder = '225.0.18.83';
}
else if (id === "broad") {
$(".node-input-iface").hide();
$("#node-input-addr-label").html('< i class = "fa fa-list" > < / i > ' + addresslabel);
$("#node-input-addr")[0].placeholder = '255.255.255.255';
}
else {
$(".node-input-iface").hide();
$("#node-input-addr-label").html('< i class = "fa fa-list" > < / i > ' + addresslabel);
$("#node-input-addr")[0].placeholder = addressph;
}
2014-03-31 14:06:29 +02:00
var type = $(this).children("option:selected").val();
if (type == "false") {
2015-05-10 22:47:22 +02:00
$("#node-input-outport-type-random").html(bindrandom);
2014-03-31 14:06:29 +02:00
} else {
2015-05-10 22:47:22 +02:00
$("#node-input-outport-type-random").html(bindtarget);
2014-03-31 14:06:29 +02:00
}
});
$("#node-input-multicast").change();
2013-10-11 22:42:34 +02:00
}
});
< / script >