Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the UNIX sockets transport to Janode.
The UNIX socket transport is a more efficient way of establishing connections with Janus when Janode is co-located on the host OS, since in this case the adapter and the server will communicate through Inter-Process Communication (IPC) using a UNIX socket without traversing the network stack.
When dealing with UNIX sockets Janus only supports
SOCK_SEQPACKET
(default) andSOCK_DGRAM
because those modes preserve message boundaries thus keeping both the implementation and the communication simple.On the other hand, node only offers
SOCK_STREAM
for IPC (net.Socket Class) on Linux, so it is impossibile to rely on native node modules.Since we didn't manage to find any external library implementing
SOCK_SEQPACKET
IPC, we've ended up using unix-dgram-socket. This library has a simple C++SOCK_DGRAM
implementation with js code binding to it.Caveats when using SOCK_DGRAM IPC
SOCK_DGRAM
IPC means that the socket is connection-less, thus:/tmp/.janode-someid
close
notification, so the liveness of the channel must be checked with a higher level mechanism (such as session keep-alives). Any error when sending a message will trigger a connection tear-down.How to use it
In order to use this transport edit the
janus.transport.pfunix.jcfg
Janus configuration:/tmp/janusapi
)Then edit the Janode app configuration, setting a Janus url that starts with the
file://
scheme and matches the server socket path:Difference with WebSockets over UNIX sockets
Another chance to indirectly rely on UNIX sockets is to use the WebSocket transport providing a scheme
ws+unix://
in the janus url.Ref meetecho/janus-gateway#2620.
In that case everything will work as normal WebSockets on both client and server but the communication will not happen on top of TCP/IP but over UNIX sockets (probably
SOCK_STREAM
), preserving the WebSockets framing.Raw UNIX sockets transport will instead push JSON datagrams from/to the sockets without any other framing.
Skip dependency installation
If by any reason you do not want to install the unix-dgram dependency on your system, just build janode without optional dependencies
Supported platforms
This PR has been tested on Linux only.
Windows is not supported by the third-party library (installation will not fail, the compiled module will only contain an empty stub).
Browsers
Of course this transport does not work on browsers.
We have updated the sample
bundle.sh
script to ignore thetransport-unix.js
file and replace it with an empty blob.