aboutsummaryrefslogtreecommitdiffstats
path: root/dgbuilder/core_nodes/io/32-udp.html
blob: 1c2eed575d9269dfe4751ef580c67a6f6770b813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!--
  Copyright 2013 IBM Corp.

  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">
        <label for="node-input-port"><i class="fa fa-sign-in"></i> Listen</label>
        on port <input type="text" id="node-input-port" placeholder="Port" style="width: 45px">
        for <select id="node-input-multicast" style='width:40%'>
          <option value="false">udp messages</option>
          <option value="true">multicast messages</option>
        </select>
    </div>
    <div class="form-row node-input-group">
        <label for="node-input-group"><i class="fa fa-list"></i> Group</label>
        <input type="text" id="node-input-group" placeholder="225.0.18.83">
    </div>
    <div class="form-row node-input-iface">
        <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
        <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
    </div>
    <div class="form-row">
        <label for="node-input-datatype"><i class="fa fa-sign-out"></i> Output</label>
        <select id="node-input-datatype" style="width: 70%;">
            <option value="buffer">a Buffer</option>
            <option value="utf8">a String</option>
            <option value="base64">a Base64 encoded string</option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-tips">Tip: Make sure your firewall will allow the data in.</div>
    <script>
        $("#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();
            }
        });
    </script>
</script>

<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.ip</b> and <b>msg.port</b> to the ip address and port from which the message was received.</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">
    RED.nodes.registerType('udp in',{
        category: 'input',
        color:"Silver",
        defaults: {
            name: {value:""},
            iface: {value:""},
            port: {value:"",required:true,validate:RED.validators.number()},
            datatype: {value:"buffer",required:true},
            multicast: {value:"false"},
            group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} }
        },
        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":"";
        }
    });
</script>


<!--  The Output Node  -->
<script type="text/x-red" data-template-name="udp out">
    <div class="form-row">
        <label for="node-input-port"><i class="fa fa-envelope"></i> Send a</label>
        <select id="node-input-multicast" style='width:40%'>
          <option value="false">udp message</option>
          <option value="broad">broadcast message</option>
          <option value="multi">multicast message</option>
        </select>
        to port <input type="text" id="node-input-port" placeholder="port" style="width: 70px">
    </div>
    <div class="form-row node-input-addr">
        <label for="node-input-addr" id="node-input-addr-label"><i class="fa fa-list"></i> Address</label>
        <input type="text" id="node-input-addr" placeholder="destination ip" style="width: 70%;">
    </div>
    <div class="form-row node-input-iface">
        <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
        <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
    </div>
    <div class="form-row">
        <label for="node-input-outport-type">&nbsp;</label>
        <select id="node-input-outport-type">
          <option id="node-input-outport-type-random" value="random">use random local port</option>
          <option value="fixed">bind to local port</option>
        </select>
        <input type="text" id="node-input-outport"  style="width: 70px;" placeholder="port">
    </div>
    <div class="form-row">
        <label>&nbsp;</label>
        <input type="checkbox" id="node-input-base64" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-base64" style="width: 70%;">Decode Base64 encoded payload ?</label>
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-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();
            if (id !== "multi") {
                $(".node-input-iface").hide();
                $("#node-input-addr-label").html('<i class="fa fa-list"></i> Address');
                $("#node-input-addr")[0].placeholder = 'destination ip';
            }
            else {
                $(".node-input-iface").show();
                $("#node-input-addr-label").html('<i class="fa fa-list"></i> Group');
                $("#node-input-addr")[0].placeholder = '225.0.18.83';
            }
            if (id === "broad") {
                $("#node-input-addr")[0].placeholder = '255.255.255.255';
            }
        });
    </script>
</script>

<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 ports below 1024 and/or broadcast.</p>
</script>

<script type="text/javascript">
    RED.nodes.registerType('udp out',{
        category: 'output',
        color:"Silver",
        defaults: {
            name: {value:""},
            addr: {value:""},
            iface: {value:""},
            port: {value:""},
            outport: {value:""},
            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":"";
        },
        oneditprepare: function() {
            var type = this.outport==""?"random":"fixed";
            $("#node-input-outport-type option").filter(function() {
                return $(this).val() == type;
            }).attr('selected',true);

            $("#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();

            $("#node-input-multicast").change(function() {
                var type = $(this).children("option:selected").val();
                if (type == "false") {
                    $("#node-input-outport-type-random").html("bind to random local port");
                } else {
                    $("#node-input-outport-type-random").html("bind to target port");
                }
            });
            $("#node-input-multicast").change();
        }
    });
</script>