node-red-contrib-tcp-client
Version:
250 lines (207 loc) • 10.6 kB
HTML
<script type="text/x-red" data-template-name="tcp-client">
<div class="form-row">
<label for="node-input-action"><i class="fa fa-tag"></i> Action</label>
<input type="text" id="node-input-action" placeholder="" style="width: 70%;">
<span style="display: block; padding-left: 106px; color: gray; font-size: x-small;">Available actions: Listen, Close and Write</span>
<input type="hidden" id="node-input-actionType">
</div>
<hr/>
<div class="form-row">Connection details:</div>
<div class="form-row">
<label for="node-input-host"><i class="fa fa-folder"></i> Host</label>
<input type="text" id="node-input-host" style="width:70%;" />
<span style="display: block; padding-left: 106px; color: gray; font-size: x-small;">Leave empty to wait for connections on the specified port</span>
<input type="hidden" id="node-input-hostType">
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-globe"></i> Port</label>
<input type="text" id="node-input-port" style="width:70%;" />
<span style="display: block; padding-left: 106px; color: gray; font-size: x-small;">Host port (if specified) or local port to listen</span>
<input type="hidden" id="node-input-portType">
</div>
<hr/>
<div class="form-row">On <b>listen</b>:</div>
<div class="form-row">
<label><i class="fa fa-sign-out"></i> Output</label>
<select id="node-input-datamode" style="width:110px;">
<option value="stream">stream of</option>
<option value="single">single</option>
</select>
<select id="node-input-datatype" style="width:140px;">
<option value="buffer">Buffer</option>
<option value="utf8">String</option>
<option value="base64">Base64 String</option>
<option value="xml">XML</option>
</select>
payload(s)
</div>
<div id="node-row-newline" class="form-row hidden" style="padding-left:110px;">
<span id="node-span-delimit">delimited by </span>
<input type="text" id="node-input-newline">
</div>
<div id="node-row-xml" class="form-row hidden">
<label><i class="fa fa-sliders"></i> Options</label>
<label for="node-input-xmlStrip" style="width:70%;">
Attribute prefix: <input type="text" id="node-input-xmlAttrkey" style="width:50px;" />
</label>
<label for="node-input-xmlStrip" style="width:70%; margin-left: 104px;">
Content prefix: <input type="text" id="node-input-xmlCharkey" style="width:50px;" />
</label>
<label for="node-input-xmlStrip" style="width:70%; margin-left: 104px;">
<input type="checkbox" id="node-input-xmlStrip" style="display:inline-block; width:22px; vertical-align:baseline;"><span for="node-input-xmlStrip"> Remove namespaces from response</span>
</label>
<label for="node-input-xmlArray" style="width:70%; margin-left: 104px;">
<input type="checkbox" id="node-input-xmlArray" style="display:inline-block; width:22px; vertical-align:baseline;"><span for="node-input-xmlArray"> Handle child nodes as arrays</span>
</label>
<label for="node-input-xmlNormalizeTags" style="width:70%; margin-left: 104px;">
<input type="checkbox" id="node-input-xmlNormalizeTags" style="display:inline-block; width:22px; vertical-align:baseline;"><span for="node-input-xmlNormalizeTags"> Normalize all tag names to lowercase</span>
</label>
<label for="node-input-xmlNormalize" style="width:70%; margin-left: 104px;">
<input type="checkbox" id="node-input-xmlNormalize" style="display:inline-block; width:22px; vertical-align:baseline;"><span for="node-input-xmlNormalize"> Trim whitespaces inside text nodes</span>
</label>
</div>
<hr/>
<div class="form-row">On <b>write</b>:</div>
<div class="form-row">
<label for="node-input-write"><i class="fa fa-pencil"></i> Message</label>
<input type="text" id="node-input-write" style="width:70%;" />
<input type="hidden" id="node-input-writeType">
</div>
<hr/>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tags"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="" style="width: 70%;">
</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="" style="width: 70%;">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-bug"></i> Debug</label>
<select id="node-input-debug" style="width:110px;">
<option value="none">Nothing</option>
<option value="errors">Only Errors</option>
<option value="all">Detailed</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="tcp-client">
<p>TCP client that listens for connections on specific port or connects to a specified host</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>action<span class="property-type">listen | close | write</span></dt>
<dd> the action to perform </dd>
<dt>host<span class="property-type">string</span></dt>
<dd> the optional server to connect to </dd>
<dt>port<span class="property-type">number</span></dt>
<dd> the port to accept incoming connections or the server port </dd>
<dt>output</dt>
<dd> output settings for the payload </dd>
<dt>write<span class="property-type">string</span></dt>
<dd> message or property to write to socket </dd>
<dt class="optional">topic <span class="property-type">string</span></dt>
<dd> the topic to publish to </dd>
<dt class="optional">name <span class="property-type">string</span></dt>
<dd> the name for this node </dd>
<dt class="optional">debug</dt>
<dd> level of debug messages to show </dd>
</dl>
</script>
<script type="text/javascript">
RED.nodes.registerType('tcp-client', {
category: 'network',
color: '#cc66ff',
defaults: {
action: { value: "Listen", required: true, validate: RED.validators.typedInput("actionType") },
actionType: { value: "str" },
host: { value: "", required: false, validate: RED.validators.typedInput("hostType") },
hostType: { value: "str" },
port: { value: "payload", required: true, validate: RED.validators.typedInput("portType") },
portType: { value: "msg" },
datamode: {value: "stream" },
datatype: {value: "buffer" },
newline: {value: "" },
xmlAttrkey: { value: "$" },
xmlCharkey: { value: "_" },
xmlStrip: { value: false },
xmlArray: { value: false },
xmlNormalizeTags: { value: false },
xmlNormalize: { value: false },
write: { value: "", required: false, validate: RED.validators.typedInput("writeType") },
writeType: { value: "str" },
topic: { value: "" },
name: { value: "" },
debug: { value: "none" }
},
inputs: 1,
outputs: 1,
icon: "bridge-dash.svg",
label: function () {
return this.name || "TCP";
},
oneditprepare: function () {
var updateOptions = function() {
var datamode = $("#node-input-datamode").val();
var datatype = $("#node-input-datatype").val();
if (datamode == "stream") {
if (datatype == "utf8" || datatype == "xml") {
$("#node-row-newline").show();
}
else {
$("#node-row-newline").hide();
}
}
else {
$("#node-row-newline").hide();
}
$("#node-span-delimit").text("delimited by ");
if (datatype == "xml") {
$("#node-row-xml").show();
$("#node-span-delimit").text("end tag ");
}
else {
$("#node-row-xml").hide();
}
};
updateOptions();
$("#node-input-datatype").change(updateOptions);
$("#node-input-datamode").change(updateOptions);
if (this.actionType == null || this.actionType === 'string' || this.actionType === 'none') {
this.actionType = "str";
}
$("#node-input-actionType").val(this.actionType);
$("#node-input-action").typedInput({
default: 'str',
typeField: $("#node-input-actionType"),
types: ['str', 'msg', 'flow', 'global', 'env']
});
if (this.hostType == null || this.hostType === 'string' || this.hostType === 'none') {
this.hostType = "str";
}
$("#node-input-hostType").val(this.hostType);
$("#node-input-host").typedInput({
default: 'str',
typeField: $("#node-input-hostType"),
types: ['str', 'msg', 'flow', 'global', 'env']
});
if (this.portType == null || this.portType === 'string' || this.portType === 'none') {
this.portType = "str";
}
$("#node-input-portType").val(this.portType);
$("#node-input-port").typedInput({
default: 'str',
typeField: $("#node-input-portType"),
types: ['str', 'msg', 'flow', 'global', 'env']
});
if (this.writeType == null || this.writeType === 'string' || this.writeType === 'none') {
this.writeType = "str";
}
$("#node-input-writeType").val(this.writeType);
$("#node-input-write").typedInput({
default: 'str',
typeField: $("#node-input-writeType"),
types: ['str', 'msg', 'flow', 'global', 'env']
});
}
});
</script>