[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / io / 22-websocket.html
1 <!--\r
2   Copyright 2013 IBM Corp.\r
3 \r
4   Licensed under the Apache License, Version 2.0 (the "License");\r
5   you may not use this file except in compliance with the License.\r
6   You may obtain a copy of the License at\r
7 \r
8   http://www.apache.org/licenses/LICENSE-2.0\r
9 \r
10   Unless required by applicable law or agreed to in writing, software\r
11   distributed under the License is distributed on an "AS IS" BASIS,\r
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13   See the License for the specific language governing permissions and\r
14   limitations under the License.\r
15 -->\r
16 \r
17 <!-- WebSocket Input Node -->\r
18 <script type="text/x-red" data-template-name="websocket in">\r
19     <div class="form-row">\r
20         <label for="node-input-server"><i class="fa fa-bookmark"></i> Path</label>\r
21         <input type="text" id="node-input-server">\r
22     </div>\r
23     <div class="form-row">\r
24         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>\r
25         <input type="text" id="node-input-name" placeholder="Name">\r
26     </div>\r
27 </script>\r
28 \r
29 <script type="text/x-red" data-help-name="websocket in">\r
30     <p>WebSocket input node.</p>\r
31     <p>By default, the data received from the WebSocket will be in <b>msg.payload</b>.\r
32     The listener can be configured to expect a properly formed JSON string, in which\r
33     case it will parse the JSON and send on the resulting object as the entire message.</p>\r
34 </script>\r
35 \r
36 <script type="text/javascript">\r
37     RED.nodes.registerType('websocket in',{\r
38         category: 'input',\r
39         defaults: {\r
40             name: {value:""},\r
41             server: {type:"websocket-listener"}\r
42         },\r
43         color:"rgb(215, 215, 160)",\r
44         inputs:0,\r
45         outputs:1,\r
46         icon: "white-globe.png",\r
47         label: function() {\r
48             var wsNode = RED.nodes.node(this.server);\r
49             return this.name||(wsNode?"[ws] "+wsNode.label():"websocket");\r
50         },\r
51         labelStyle: function() {\r
52             return this.name?"node_label_italic":"";\r
53         }\r
54     });\r
55 </script>\r
56 \r
57 <!-- WebSocket out Node -->\r
58 <script type="text/x-red" data-template-name="websocket out">\r
59     <div class="form-row">\r
60         <label for="node-input-server"><i class="fa fa-bookmark"></i> Path</label>\r
61         <input type="text" id="node-input-server">\r
62     </div>\r
63     <div class="form-row">\r
64         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>\r
65         <input type="text" id="node-input-name" placeholder="Name">\r
66     </div>\r
67 </script>\r
68 \r
69 <script type="text/x-red" data-help-name="websocket out">\r
70     <p>WebSocket out node.</p>\r
71     <p>By default, <b>msg.payload</b> will be sent over the WebSocket. The listener\r
72     can be configured to encode the entire message object as a JSON string and send that\r
73     over the WebSocket.</p>\r
74 \r
75     <p>If the message arriving at this node started at a WebSocket In node, the message\r
76     will be sent back to the client that triggered the flow. Otherwise, the message\r
77     will be broadcast to all connected clients.</p>\r
78     <p>If you want to broadcast a message that started at a WebSocket In node, you\r
79     should delete the <b>msg._session</b> property within the flow</p>.\r
80 </script>\r
81 \r
82 <script type="text/javascript">\r
83     RED.nodes.registerType('websocket out',{\r
84         category: 'output',\r
85         defaults: {\r
86             name: {value:""},\r
87             server: {type:"websocket-listener", required:true}\r
88         },\r
89         color:"rgb(215, 215, 160)",\r
90         inputs:1,\r
91         outputs:0,\r
92         icon: "white-globe.png",\r
93         align: "right",\r
94         label: function() {\r
95             var wsNode = RED.nodes.node(this.server);\r
96             return this.name||(wsNode?"[ws] "+wsNode.label():"websocket");\r
97         },\r
98         labelStyle: function() {\r
99             return this.name?"node_label_italic":"";\r
100         }\r
101     });\r
102 </script>\r
103 \r
104 <!-- WebSocket Server configuration node -->\r
105 <script type="text/x-red" data-template-name="websocket-listener">\r
106     <div class="form-row">\r
107         <label for="node-config-input-path"><i class="fa fa-bookmark"></i> Path</label>\r
108         <input type="text" id="node-config-input-path" placeholder="/ws/example">\r
109     </div>\r
110     <div class="form-row">\r
111         <label for="node-config-input-wholemsg">&nbsp;</label>\r
112         <select type="text" id="node-config-input-wholemsg" style="width: 70%;">\r
113             <option value="false">Send/Receive payload</option>\r
114             <option value="true">Send/Receive entire message</option>\r
115         </select>\r
116     </div>\r
117     <div class="form-tips">\r
118     Be default, <code>payload</code> will contain the data to be sent over, or received from a websocket.\r
119     The listener can be configured to send or receive the entire message object as a JSON formatted string.\r
120     <p id="node-config-ws-tip">This path will be relative to <code><span id="node-config-ws-path"></span></code>.</p>\r
121     </div>\r
122 </script>\r
123 \r
124 <script type="text/x-red" data-help-name="websocket-listener">\r
125    <p>This configuration node creates a WebSocket Server using the specified path</p>\r
126 </script>\r
127 \r
128 <script type="text/javascript">\r
129     RED.nodes.registerType('websocket-listener',{\r
130         category: 'config',\r
131         defaults: {\r
132             path: {value:"",required:true,validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/) },\r
133             wholemsg: {value:"false"}\r
134         },\r
135         inputs:0,\r
136         outputs:0,\r
137         label: function() {\r
138             var root = RED.settings.httpNodeRoot;\r
139             if (root.slice(-1) != "/") { \r
140                 root = root+"/";\r
141             }\r
142             if (this.path.charAt(0) == "/") {\r
143                 root += this.path.slice(1);\r
144             } else {\r
145                 root += this.path;\r
146             }\r
147             return root;\r
148         },\r
149         oneditprepare: function() {\r
150             var root = RED.settings.httpNodeRoot;\r
151             if (root.slice(-1) == "/") { \r
152                 root = root.slice(0,-1);\r
153             }\r
154             if (root == "") {\r
155                 $("#node-config-ws-tip").hide();\r
156             } else {\r
157                 $("#node-config-ws-path").html(root);\r
158                 $("#node-config-ws-tip").show();\r
159             }\r
160             //document.getElementById("node-config-wsdocpath").innerHTML=\r
161         }\r
162     });\r
163 </script>\r