96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
exports.id = 'tcpipclient';
|
|
exports.title = 'TCP/IP Client';
|
|
exports.group = 'TCP/IP';
|
|
exports.color = '#888600';
|
|
exports.version = '1.0.0';
|
|
exports.icon = 'exchange';
|
|
exports.input = false;
|
|
exports.output = 0;
|
|
exports.author = 'Lukas Muransky';
|
|
exports.variables = true;
|
|
exports.options = { ip: '127.0.0.1', port: 9999 };
|
|
exports.traffic = false;
|
|
|
|
exports.html = `<div class="padding">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div data-jc="textbox" data-jc-path="ip" data-jc-config="placeholder:127.0.0.1;required:true" class="m">Hostname or IP address</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div data-jc="textbox" data-jc-path="port" data-jc-config="placeholder:9999;required:true" class="m">Port</div>
|
|
</div>
|
|
</div>
|
|
<div data-jc="checkbox" data-jc-path="helvar">@(Helvar)</div>
|
|
</div>
|
|
<script>
|
|
ON('save.tcpip', function(component, options) {
|
|
!component.name && (component.name = '{0}:{1}'.format(options.ip, options.port));
|
|
});
|
|
</script>`;
|
|
|
|
exports.readme = `
|
|
# TCP/IP Clients`;
|
|
|
|
var CLIENTS = [];
|
|
var tcpip;
|
|
|
|
global.TCPIP_CLIENTS = [];
|
|
|
|
exports.install = function(instance) {
|
|
|
|
var client;
|
|
|
|
instance.custom.reconfigure = function(o, old_options) {
|
|
if (old_options)
|
|
CLIENTS = CLIENTS.remove(function(b){
|
|
return b.id === old_options.id;
|
|
});
|
|
|
|
var options = instance.options;
|
|
|
|
if (!options.ip || !options.port) {
|
|
instance.status('Not configured', 'red');
|
|
return;
|
|
}
|
|
|
|
options.id = instance.name;
|
|
|
|
instance.custom.createClient();
|
|
TCPIP_CLIENTS = [];
|
|
CLIENTS.forEach(n => TCPIP_CLIENTS.push(n));
|
|
};
|
|
|
|
instance.custom.createClient = function () {
|
|
|
|
var o = instance.options;
|
|
var opts = {
|
|
ip: o.ip,
|
|
port: o.port,
|
|
helvar: o.helvar,
|
|
id: o.id
|
|
};
|
|
|
|
client = new Client(opts);
|
|
|
|
CLIENTS.push(client);
|
|
|
|
instance.status('Ready');
|
|
};
|
|
|
|
instance.on('options', instance.custom.reconfigure);
|
|
instance.custom.reconfigure();
|
|
};
|
|
|
|
FLOW.trigger('tcpip.clients', function(next) {
|
|
var clients = [];
|
|
CLIENTS.forEach(n => clients.push(n.id));
|
|
next(clients);
|
|
});
|
|
|
|
|
|
function Client(options) {
|
|
var self = this;
|
|
self.id = options.id;
|
|
self.options = options;
|
|
return self;
|
|
}
|