Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions socketio.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
category: 'config',
defaults: {
port:{value:80, required:true, validate:RED.validators.number()},
options: {value: ''},
sendClient: {value:true},
path: {value:"/socket.io"},
bindToNode: {value: false}
Expand All @@ -26,11 +27,25 @@
$("#node-config-input-bindToNode").prop('checked', false);
}
$("#node-config-input-bindToNode").change();
this.editor = RED.editor.createEditor({
id: 'node-config-input-options-editor',
mode: 'ace/mode/json',
value: $("#node-config-input-options").val()
});
},
oneditsave: function () {
$("#node-config-input-options").val(this.editor.getValue());
this.editor.destroy();
delete this.editor;
},
oneditcancel: function () {
this.editor.destroy();
delete this.editor;
}
});
</script>

<script type="text/x-red" data-template-name="socketio-config">
<script type="text/html" data-template-name="socketio-config">
<div class="form-row">
<input type="checkbox" id="node-config-input-bindToNode" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-bindToNode" style="width: auto"> Bind to Node-red Instance</label>
Expand All @@ -47,10 +62,16 @@
<label for="node-config-input-path"><i class="fa fa-paper-plane-o"></i> InputPath?</label>
<input type="text" id="node-config-input-path" placeholder="/socket.io">
</div>

<div class="form-row">
<label for="node-config-input-options"><i class="fa fa-file-code-o"></i> Options:</label>
<input type="hidden" id="node-config-input-options" autofocus="autofocus">
</div>
<div class="form-row node-config-text-editor-row">
<div style="height:250px;" class="node-text-editor" id="node-config-input-options-editor"></div>
</div>
</script>

<script type="text/x-red" data-help-name="socketio-config">
<script type="text/html" data-help-name="socketio-config">
<p>Socket IO node</p>
<p>VUOTO</p>
</script>
Expand Down Expand Up @@ -108,7 +129,7 @@
});
</script>

<script type="text/x-red" data-template-name="socketio-in">
<script type="text/html" data-template-name="socketio-in">
<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">
Expand All @@ -122,7 +143,7 @@
</div>
</script>

<script type="text/x-red" data-help-name="socketio-in">
<script type="text/html" data-help-name="socketio-in">
<p>Socket IO Input node</p>
<p>Implementation of a SocketIO server</p>
<p>This node can be used to receive socket events from a web page</p>
Expand Down
10 changes: 8 additions & 2 deletions socketio.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ module.exports = function(RED) {
this.port = n.port || 80;
this.sendClient = n.sendClient;
this.path = n.path || "/socket.io";
try {
this.options = n.options ? JSON.parse(n.options) : {};
} catch (error) {
node.error("[Wrong Options] create socket.io instance fail!");
this.options = {};
}
this.bindToNode = n.bindToNode || false;

if (this.bindToNode) {
io = new Server(RED.server);
io = new Server(RED.server, this.options);
} else {
io = new Server();
io = new Server(this.options);
io.serveClient(node.sendClient);
io.path(node.path);
io.listen(node.port);
Expand Down