You can write your own transport layer by implementing thorin.Interface.Transport
and calling thorin.addTransport()
Since Thorin transports are designed to abstract away incoming connections and connection handling,
they must provide a common interface to make switching from one transport to another seamless and maintain your
application transport agnostic. The transport interface also extends the native EventEmitter
class,
transforming your transport into an event emitter by default.
The configuration of a transport should be placed under the transport
key of the application's root configuration object
and under the transport's name
property. A small example is available below.
'use strict';
// config/app.js file
module.exports = {
"transport.http": { // the "http" key is the transport's name property
port: 12345
}
};
Transport.TYPE.BI_DIRECTIONAL
[1], the transport can process both incoming and outgoing traffic (eg. websocket)
Transport.TYPE.RECEIVER
[2], the transport will only process inbound traffic, acting as a receiver (eg. http)
Transport.TYPE.SENDER
[3], the transport will only process outbound traffic, acting as a sender (eg. push notifications)
super()
constructor from your class, so that it can initiate any
other dependencies of the transport class.
name
property.'use strict';
class ThorinTransportHttp extends thorin.Interface.Transport {
// Our constructor function
constructor() {
super();
this.name = 'http';
this.server = null;
}
publicName() { return "Web server"; }
// Called when transport configuration is available
init(config) {
this.config = config;
}
// This is where we should bind our server and listen to a port
run(done) {
// initiate server and bind it.
done();
}
// Register an action with the server's handlers
routeAction(actionObj) {
// server specific functionality for routing.
}
// Toggle an action processing
disableAction(actionName) {
// remove or disable the action from the server's handlers
}
enableAction(actionName) {
// enable the processing of the given action
}
}
thorin.addTransport(ThorinTransportHttp, 'http');
You can always create a new issue on GitHub or contact one of the core founders by chat.