First of all, great job on Flow v10. It is a great tool and shows a lot of promise.
While playing with it, I went to create a new component that handles WebSocket routes but it appears that SOCKET routes do not work. I have been trying to look into how traffic is forwarded from the main process to a worker but I am unable to find it quickly so I figure it would be best to reach out.
Here is the example component I made to do some testing, it is a simple modification of the REST API -> Route but when creating the route, undefined is returned and attempting a WebSocket connection fails...
<script total>
exports.name = 'Socket';
exports.group = 'WebSocket';
exports.icon = 'fa fa-road';
exports.version = '1';
exports.author = 'Colton McInroy';
exports.config = { url: '/', timeout: 5000, limit: 5120, upload: false, send: 'all' };
exports.outputs = [{ id: 'open', name: 'Open' }, { id: 'close', name: 'Close' }, { id: 'message', name: 'Message' }];
exports.make = function(instance, config) {
var prev = null;
instance.configure = function() {
if (prev) {
prev && prev.remove();
prev = null;
}
if (config.url) {
var flags = [config.timeout];
config.upload && flags.push('upload');
console.log('Adding Route:', 'SOCKET ' + config.url);
prev = ROUTE('SOCKET ' + config.url, function() {
var ctrl = this;
ctrl.autodestroy();
var msg = instance.newmessage();
var data;
switch (config.send) {
case 'payload':
data = ctrl.body;
break;
case 'query':
data = ctrl.query;
break;
case 'files':
data = ctrl.files;
break;
case 'params':
data = ctrl.params;
break;
case 'headers':
data = ctrl.headers;
break;
default:
data = { body: ctrl.body, query: ctrl.query, files: ctrl.files, user: ctrl.user, url: ctrl.url, headers: ctrl.headers, params: ctrl.params, ip: ctrl.ip };
break;
}
msg.refs.controller = ctrl;
ctrl.on('open', function(client) {
msg.refs.client = client;
msg.send('open', data);
});
ctrl.on('close', function(client) {
msg.refs.client = client;
msg.send('close', data);
});
ctrl.on('message', function(client, message) {
msg.refs.client = client;
data.message = message;
msg.send('message', data);
});
// msg.send('output', data);
}, flags, config.limit);
console.log('Route:', prev);
}
};
instance.configure();
};
</script>
<readme>
This component registers an HTTP Route and sends request data next. It stores `controller` instance in the `message.refs.controller` property. You must respond to the REST response component.
< __IMPORTANT__:<br>The component works only with a defined Proxy endpoint in the Flow settings.
< __URL__:<br>The URL must be relative to the defined Proxy endpoint. So if the endpoint is `/users/` and the desired address is `http://example.com/users/find` then the value must be `/find`
__Output data__:
``js
{
"route": String,
"params": Object,
"query": Object,
"body": Object,
"files": Array,
"headers": Object,
"url": String,
"ip": String
}
``
</readme>
<settings>
<div class="padding">
<div class="row" data-bind="flow.head.worker__hide:!value || flow.head.origin.length < flow.head.proxyurl.length">
<div class="col-md-12 m">
<div class="message message-error"><b><i class="fa fa-warning"></i>No proxy endpoint defined.</b><br>This component will not work until then. Please go to main screen, open settings of this FlowStream instance and set the Endpoint.</div>
</div>
</div>
<div class="row">
<div class="col-md-9 m">
<div data---="input__?.url__required:1">Relative URL address</div>
<div class="help">Relative path to: <span data-bind="flow.head.proxyurl__text:value?value:window.location.origin"></span></div>
</div>
</div>
<div class="row">
<div class="col-md-3 m">
<div data---="input__?.timeout__required:1;type:number">Timeout</div>
</div>
<div class="col-md-3 m">
<div data---="input__?.limit__required:1;type:number;ricon:!kB;align:1">Request limit</div>
</div>
<div class="col-md-3 m">
<div data---="input__?.send__required:1;dirsource:all|Everything,payload|Payload,query|Query arguments,files|Files,params|Dynamic params,headers|Headers">Send to output</div>
</div>
</div>
</div>
</settings>
<style>
.CLASS footer { padding: 10px; }
.CLASS footer span { font-family: var(--monospace); }
.CLASS footer .method { background-color: var(--color); color: #FFF; padding: 2px 3px; border-radius: var(--radius); }
</style>
<body>
<header>
<i class="ICON"></i>NAME
</header>
<footer data-bind="CONFIG.method__show" class="hidden">
<div><span class="method">SOCKET</span> <a data-bind="CONFIG.url__text__href:flow.head.proxyurl + (value[0] === '/' ? value.substring(1) : value)" target="_blank"></a></div>
</footer>
</body>