2013-11-22 22:28:05 +01:00
|
|
|
<!--
|
|
|
|
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.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!-- WebSocket Input Node -->
|
|
|
|
<script type="text/x-red" data-template-name="websocket in">
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-server"><i class="icon-bookmark"></i> Path</label>
|
|
|
|
<input type="text" id="node-input-server">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
|
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="websocket in">
|
2013-12-08 21:41:57 +01:00
|
|
|
<p>WebSocket input node.</p>
|
|
|
|
<p>By default, the data received from the WebSocket will be in <b>msg.payload</b>.
|
|
|
|
The listener can be configured to expect a properly formed JSON string, in which
|
|
|
|
case it will parse the JSON and send on the resulting object as the entire message.</p>
|
2013-11-22 22:28:05 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('websocket in',{
|
|
|
|
category: 'input',
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
|
|
|
server: {type:"websocket-listener"}
|
|
|
|
},
|
|
|
|
color:"rgb(215, 215, 160)",
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
|
|
|
icon: "white-globe.png",
|
|
|
|
label: function() {
|
|
|
|
var wsNode = RED.nodes.node(this.server);
|
|
|
|
return this.name||(wsNode?"[ws] "+wsNode.label():"websocket");
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- WebSocket out Node -->
|
|
|
|
<script type="text/x-red" data-template-name="websocket out">
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-server"><i class="icon-bookmark"></i> Path</label>
|
|
|
|
<input type="text" id="node-input-server">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
|
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="websocket out">
|
2013-12-08 21:41:57 +01:00
|
|
|
<p>WebSocket out node.</p>
|
|
|
|
<p>By default, <b>msg.payload</b> will be sent over the WebSocket. The listener
|
|
|
|
can be configured to encode the entire message object as a JSON string and send that
|
|
|
|
over the WebSocket.</p>
|
|
|
|
|
|
|
|
<p>If the message arriving at this node started at a WebSocket In node, the message
|
|
|
|
will be sent back to the client that triggered the flow. Otherwise, the message
|
|
|
|
will be broadcast to all conntected clients.</p>
|
|
|
|
<p>If you want to broadcast a message that started at a WebSocket In node, you
|
|
|
|
should delete the <b>msg._session</b> property within the flow</p>.
|
2013-11-22 22:28:05 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('websocket out',{
|
|
|
|
category: 'output',
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
|
|
|
server: {type:"websocket-listener", required:true}
|
|
|
|
},
|
|
|
|
color:"rgb(215, 215, 160)",
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
|
|
|
icon: "white-globe.png",
|
|
|
|
align: "right",
|
|
|
|
label: function() {
|
|
|
|
var wsNode = RED.nodes.node(this.server);
|
|
|
|
return this.name||(wsNode?"[ws] "+wsNode.label():"websocket");
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- WebSocket Server configuration node -->
|
|
|
|
<script type="text/x-red" data-template-name="websocket-listener">
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-config-input-path"><i class="icon-bookmark"></i> Path</label>
|
|
|
|
<input type="text" id="node-config-input-path" placeholder="/ws/example">
|
|
|
|
</div>
|
2013-12-08 21:31:56 +01:00
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-config-input-wholemsg"> </label>
|
|
|
|
<select type="text" id="node-config-input-wholemsg" style="width: 70%;">
|
|
|
|
<option value="false">Send/Receive payload</option>
|
|
|
|
<option value="true">Send/Receive entire message</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-tips">
|
|
|
|
Be default, <code>payload</code> will contain the data to be sent over, or received from a websocket.
|
|
|
|
The listener can be configured to send or receive the entire message object as a JSON formatted string.
|
|
|
|
<p id="node-config-ws-tip">This path will be relative to <code><span id="node-config-ws-path"></span></code>.</p>
|
|
|
|
</div>
|
2013-11-22 22:28:05 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="websocket-listener">
|
|
|
|
<p>This configuration node creates a WebSocket Server using the specified path</p>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('websocket-listener',{
|
|
|
|
category: 'config',
|
|
|
|
defaults: {
|
2013-12-08 21:31:56 +01:00
|
|
|
path: {value:"",required:true,validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/) },
|
|
|
|
wholemsg: {value:"false"}
|
2013-11-22 22:28:05 +01:00
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:0,
|
|
|
|
label: function() {
|
|
|
|
var root = document.location.pathname.slice(0,-1);
|
|
|
|
root += this.path;
|
|
|
|
return root;
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
var root = document.location.pathname.slice(0,-1);
|
|
|
|
if (root == "") {
|
|
|
|
$("#node-config-ws-tip").hide();
|
|
|
|
} else {
|
|
|
|
$("#node-config-ws-path").html(root);
|
|
|
|
$("#node-config-ws-tip").show();
|
|
|
|
}
|
|
|
|
//document.getElementById("node-config-wsdocpath").innerHTML=
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|