mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
882b7d0391
commit
3902a343f3
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright 2013 IBM Corp.
|
Copyright 2013,2016 IBM Corp.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -52,6 +52,7 @@
|
|||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><span data-i18n="udp.tip.in"></span></div>
|
<div class="form-tips"><span data-i18n="udp.tip.in"></span></div>
|
||||||
|
<div class="form-tips" id="udpporttip"><span data-i18n="[html]udp.tip.port"></span></div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="udp in">
|
<script type="text/x-red" data-help-name="udp in">
|
||||||
@ -98,6 +99,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#node-input-multicast").change();
|
$("#node-input-multicast").change();
|
||||||
|
|
||||||
|
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())) {
|
||||||
|
console.log($("#node-input-port").val());
|
||||||
|
RED.notify(alreadyused+" "+$("#node-input-port").val(),"warn");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 IBM Corp.
|
* Copyright 2013,2016 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,6 +17,7 @@
|
|||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var dgram = require('dgram');
|
var dgram = require('dgram');
|
||||||
|
var udpInputPortsInUse = {};
|
||||||
|
|
||||||
// The Input Node
|
// The Input Node
|
||||||
function UDPin(n) {
|
function UDPin(n) {
|
||||||
@ -28,6 +29,12 @@ module.exports = function(RED) {
|
|||||||
this.multicast = n.multicast;
|
this.multicast = n.multicast;
|
||||||
this.ipv = n.ipv || "udp4";
|
this.ipv = n.ipv || "udp4";
|
||||||
var node = this;
|
var node = this;
|
||||||
|
if (!udpInputPortsInUse.hasOwnProperty(this.port)) {
|
||||||
|
udpInputPortsInUse[this.port] = n.id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.warn(RED._("udp.errors.alreadyused",node.port));
|
||||||
|
}
|
||||||
|
|
||||||
var opts = {type:node.ipv, reuseAddr:true};
|
var opts = {type:node.ipv, reuseAddr:true};
|
||||||
if (process.version.indexOf("v0.10") === 0) { opts = node.ipv; }
|
if (process.version.indexOf("v0.10") === 0) { opts = node.ipv; }
|
||||||
@ -76,6 +83,10 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.on("close", function() {
|
node.on("close", function() {
|
||||||
|
console.log("ID=",node.id);
|
||||||
|
if (udpInputPortsInUse[node.port] === node.id) {
|
||||||
|
delete udpInputPortsInUse[node.port];
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
server.close();
|
server.close();
|
||||||
node.log(RED._("udp.status.listener-stopped"));
|
node.log(RED._("udp.status.listener-stopped"));
|
||||||
@ -86,9 +97,11 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
server.bind(node.port,node.iface);
|
server.bind(node.port,node.iface);
|
||||||
}
|
}
|
||||||
|
RED.httpAdmin.get('/udp-ports/:id', RED.auth.needsPermission('udp-in.read'), function(req,res) {
|
||||||
|
res.json(udpInputPortsInUse);
|
||||||
|
});
|
||||||
RED.nodes.registerType("udp in",UDPin);
|
RED.nodes.registerType("udp in",UDPin);
|
||||||
|
|
||||||
|
|
||||||
// The Output Node
|
// The Output Node
|
||||||
function UDPout(n) {
|
function UDPout(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
@ -398,7 +398,8 @@
|
|||||||
},
|
},
|
||||||
"tip": {
|
"tip": {
|
||||||
"in": "Tip: Make sure your firewall will allow the data in.",
|
"in": "Tip: Make sure your firewall will allow the data in.",
|
||||||
"out": "Tip: leave address and port blank if you want to set using <b>msg.ip</b> and <b>msg.port</b>."
|
"out": "Tip: leave address and port blank if you want to set using <b>msg.ip</b> and <b>msg.port</b>.",
|
||||||
|
"port": "Ports already in use: "
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"listener-at": "udp listener at __host__:__port__",
|
"listener-at": "udp listener at __host__:__port__",
|
||||||
@ -417,7 +418,8 @@
|
|||||||
"interface": "Must be ip address of the required interface",
|
"interface": "Must be ip address of the required interface",
|
||||||
"ip-notset": "udp: ip address not set",
|
"ip-notset": "udp: ip address not set",
|
||||||
"port-notset": "udp: port not set",
|
"port-notset": "udp: port not set",
|
||||||
"port-invalid": "udp: port number not valid"
|
"port-invalid": "udp: port number not valid",
|
||||||
|
"alreadyused": "udp: port already in use"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"switch": {
|
"switch": {
|
||||||
|
Loading…
Reference in New Issue
Block a user