[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / io / 32-udp.html
1 <!--
2   Copyright 2013 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <!--  The Input Node  -->
18 <script type="text/x-red" data-template-name="udp in">
19     <div class="form-row">
20         <label for="node-input-port"><i class="fa fa-sign-in"></i> Listen</label>
21         on port <input type="text" id="node-input-port" placeholder="Port" style="width: 45px">
22         for <select id="node-input-multicast" style='width:40%'>
23           <option value="false">udp messages</option>
24           <option value="true">multicast messages</option>
25         </select>
26     </div>
27     <div class="form-row node-input-group">
28         <label for="node-input-group"><i class="fa fa-list"></i> Group</label>
29         <input type="text" id="node-input-group" placeholder="225.0.18.83">
30     </div>
31     <div class="form-row node-input-iface">
32         <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
33         <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
34     </div>
35     <div class="form-row">
36         <label for="node-input-datatype"><i class="fa fa-sign-out"></i> Output</label>
37         <select id="node-input-datatype" style="width: 70%;">
38             <option value="buffer">a Buffer</option>
39             <option value="utf8">a String</option>
40             <option value="base64">a Base64 encoded string</option>
41         </select>
42     </div>
43     <div class="form-row">
44         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
45         <input type="text" id="node-input-name" placeholder="Name">
46     </div>
47     <div class="form-tips">Tip: Make sure your firewall will allow the data in.</div>
48     <script>
49         $("#node-input-multicast").change(function() {
50             var id = $("#node-input-multicast option:selected").val();
51             if (id == "false") {
52                 $(".node-input-group").hide();
53                 $(".node-input-iface").hide();
54             }
55             else {
56                 $(".node-input-group").show();
57                 $(".node-input-iface").show();
58             }
59         });
60     </script>
61 </script>
62
63 <script type="text/x-red" data-help-name="udp in">
64     <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>
65     <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>
66     <p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
67 </script>
68
69 <script type="text/javascript">
70     RED.nodes.registerType('udp in',{
71         category: 'input',
72         color:"Silver",
73         defaults: {
74             name: {value:""},
75             iface: {value:""},
76             port: {value:"",required:true,validate:RED.validators.number()},
77             datatype: {value:"buffer",required:true},
78             multicast: {value:"false"},
79             group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} }
80         },
81         inputs:0,
82         outputs:1,
83         icon: "bridge-dash.png",
84         label: function() {
85             if (this.multicast=="false") {
86                 return this.name||"udp "+this.port;
87             }
88             else return this.name||"udp "+(this.group+":"+this.port);
89         },
90         labelStyle: function() {
91             return this.name?"node_label_italic":"";
92         }
93     });
94 </script>
95
96
97 <!--  The Output Node  -->
98 <script type="text/x-red" data-template-name="udp out">
99     <div class="form-row">
100         <label for="node-input-port"><i class="fa fa-envelope"></i> Send a</label>
101         <select id="node-input-multicast" style='width:40%'>
102           <option value="false">udp message</option>
103           <option value="broad">broadcast message</option>
104           <option value="multi">multicast message</option>
105         </select>
106         to port <input type="text" id="node-input-port" placeholder="port" style="width: 70px">
107     </div>
108     <div class="form-row node-input-addr">
109         <label for="node-input-addr" id="node-input-addr-label"><i class="fa fa-list"></i> Address</label>
110         <input type="text" id="node-input-addr" placeholder="destination ip" style="width: 70%;">
111     </div>
112     <div class="form-row node-input-iface">
113         <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
114         <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
115     </div>
116     <div class="form-row">
117         <label for="node-input-outport-type">&nbsp;</label>
118         <select id="node-input-outport-type">
119           <option id="node-input-outport-type-random" value="random">use random local port</option>
120           <option value="fixed">bind to local port</option>
121         </select>
122         <input type="text" id="node-input-outport"  style="width: 70px;" placeholder="port">
123     </div>
124     <div class="form-row">
125         <label>&nbsp;</label>
126         <input type="checkbox" id="node-input-base64" style="display: inline-block; width: auto; vertical-align: top;">
127         <label for="node-input-base64" style="width: 70%;">Decode Base64 encoded payload ?</label>
128     </div>
129     <div class="form-row">
130         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
131         <input type="text" id="node-input-name" placeholder="Name">
132     </div>
133     <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>
134     <script>
135         $("#node-input-multicast").change(function() {
136             var id = $("#node-input-multicast option:selected").val();
137             if (id !== "multi") {
138                 $(".node-input-iface").hide();
139                 $("#node-input-addr-label").html('<i class="fa fa-list"></i> Address');
140                 $("#node-input-addr")[0].placeholder = 'destination ip';
141             }
142             else {
143                 $(".node-input-iface").show();
144                 $("#node-input-addr-label").html('<i class="fa fa-list"></i> Group');
145                 $("#node-input-addr")[0].placeholder = '225.0.18.83';
146             }
147             if (id === "broad") {
148                 $("#node-input-addr")[0].placeholder = '255.255.255.255';
149             }
150         });
151     </script>
152 </script>
153
154 <script type="text/x-red" data-help-name="udp out">
155     <p>This node sends <b>msg.payload</b> to the designated udp host and port. Supports multicast.</p>
156     <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>
157     <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>
158     <p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
159 </script>
160
161 <script type="text/javascript">
162     RED.nodes.registerType('udp out',{
163         category: 'output',
164         color:"Silver",
165         defaults: {
166             name: {value:""},
167             addr: {value:""},
168             iface: {value:""},
169             port: {value:""},
170             outport: {value:""},
171             base64: {value:false,required:true},
172             multicast: {value:"false"}
173         },
174         inputs:1,
175         outputs:0,
176         icon: "bridge-dash.png",
177         align: "right",
178         label: function() {
179             return this.name||"udp "+(this.addr+":"+this.port);
180         },
181         labelStyle: function() {
182             return this.name?"node_label_italic":"";
183         },
184         oneditprepare: function() {
185             var type = this.outport==""?"random":"fixed";
186             $("#node-input-outport-type option").filter(function() {
187                 return $(this).val() == type;
188             }).attr('selected',true);
189
190             $("#node-input-outport-type").change(function() {
191                 var type = $(this).children("option:selected").val();
192                 if (type == "random") {
193                     $("#node-input-outport").val("").hide();
194                 } else {
195                     $("#node-input-outport").show();
196                 }
197             });
198
199             $("#node-input-outport-type").change();
200
201             $("#node-input-multicast").change(function() {
202                 var type = $(this).children("option:selected").val();
203                 if (type == "false") {
204                     $("#node-input-outport-type-random").html("bind to random local port");
205                 } else {
206                     $("#node-input-outport-type-random").html("bind to target port");
207                 }
208             });
209             $("#node-input-multicast").change();
210         }
211     });
212 </script>