Skip to content

Commit

Permalink
Merge pull request #1270 from meetecho/nanomsg
Browse files Browse the repository at this point in the history
New Nanomsg transport plugin
  • Loading branch information
lminiero committed Jun 18, 2018
2 parents 709fce4 + 3d7f965 commit 4388d55
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 11 deletions.
10 changes: 10 additions & 0 deletions Makefile.am
Expand Up @@ -268,6 +268,16 @@ conf_DATA += conf/janus.transport.pfunix.cfg.sample
EXTRA_DIST += conf/janus.transport.pfunix.cfg.sample
endif

if ENABLE_NANOMSG
transport_LTLIBRARIES += transports/libjanus_nanomsg.la
transports_libjanus_nanomsg_la_SOURCES = transports/janus_nanomsg.c
transports_libjanus_nanomsg_la_CFLAGS = $(transports_cflags)
transports_libjanus_nanomsg_la_LDFLAGS = $(transports_ldflags) -lnanomsg
transports_libjanus_nanomsg_la_LIBADD = $(transports_libadd)
conf_DATA += conf/janus.transport.nanomsg.cfg.sample
EXTRA_DIST += conf/janus.transport.nanomsg.cfg.sample
endif

##
# Event handlers
##
Expand Down
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,8 @@ WebSockets and/or BoringSSL support, as they make use of it)
you are interested in RabbitMQ support for the Janus API)
* [paho.mqtt.c](https://eclipse.org/paho/clients/c) (only needed if
you are interested in MQTT support for the Janus API)
* [nanomsg](https://nanomsg.org/) (only needed if
you are interested in Nanomsg support for the Janus API)
* [libcurl](https://curl.haxx.se/libcurl/) (only needed if you are
interested in the TURN REST API support)

Expand Down Expand Up @@ -196,6 +198,13 @@ following steps:
* *Note:* you may want to set up a different install path for the library,
to achieve that, replace the last command by 'sudo prefix=/usr make install'.

In case you're interested in Nanomsg support, you'll need to install the
related C library. It is usually available as an easily installable
package in pretty much all repositories. The following is an example on
how to install it on Ubuntu:

aptitude install libnanomsg-dev

Finally, the same can be said for rabbitmq-c as well, which is needed
for the optional RabbitMQ support. In fact, several different versions
of the library can be found, and the versions usually available in most
Expand Down
26 changes: 26 additions & 0 deletions conf/janus.transport.nanomsg.cfg.sample
@@ -0,0 +1,26 @@
; You can also control a Janus instance using Nanomsg sockets. The only
; aspect you need to configure here is the address to use for the
; communication, and whether the address should be used to bind locally
; or to connect to a remote endpoint. Notice that the only supported
; pattern is NN_PAIR, so you'll only be able to have a single client
; controlling the API with this plugin. As usual, both Janus API and Admin
; API endpoints can be configured.
[general]
enabled = yes ; Whether to enable the Nanomsg interface
; for Janus API clients
json = indented ; Whether the JSON messages should be indented (default),
; plain (no indentation) or compact (no indentation and no spaces)
;mode = bind ; Whether we should 'bind' to the specified
; address (default), or connect to it if remote
address = ipc:///tmp/janus.ipc ; Address to use (Janus API), refer
; to the Nanomsg documentation for more info
; on different transports you can use here

; As with other transport plugins, you can use Nanomsg to interact with
; the Admin API as well: in case you're interested in it, a different
; address needs to be provided.
[admin]
admin_enabled = no ; Whether to enable the Nanomsg interface
; for Admin API clients
;admin_mode = bind
;admin_address = ipc:///tmp/janus-admin.ipc
26 changes: 26 additions & 0 deletions configure.ac
Expand Up @@ -129,6 +129,8 @@ AC_ARG_ENABLE([all-transports],
[enable_mqtt=no])
AS_IF([test "x$enable_unix_sockets" != "xyes"],
[enable_unix_sockets=no])
AS_IF([test "x$enable_nanomsg" != "xyes"],
[enable_nanomsg=no])
],
[])

Expand Down Expand Up @@ -189,6 +191,13 @@ AC_ARG_ENABLE([unix-sockets],
[enable_unix_sockets=no])],
[enable_unix_sockets=maybe])

AC_ARG_ENABLE([nanomsg],
[AS_HELP_STRING([--disable-nanomsg],
[Disable Nanomsg integration])],
[AS_IF([test "x$enable_nanomsg" != "xyes"],
[enable_nanomsg=no])],
[enable_nanomsg=maybe])

AC_ARG_ENABLE([sample-event-handler],
[AS_HELP_STRING([--disable-sample-event-handler],
[Disable sample event handler (HTTP POST) ])],
Expand Down Expand Up @@ -462,9 +471,23 @@ AC_CHECK_LIB([paho-mqtt3a],
AS_IF([test "x$enable_mqtt" = "xyes"],
[AC_MSG_ERROR([paho c client not found. See README.md for installation instructions or use --disable-mqtt])])
])
AC_CHECK_LIB([nanomsg],
[nn_socket],
[
AS_IF([test "x$enable_nanomsg" != "xno"],
[
AC_DEFINE(HAVE_NANOMSG)
enable_nanomsg=yes
])
],
[
AS_IF([test "x$enable_nanomsg" = "xyes"],
[AC_MSG_ERROR([nanomsg not found. See README.md for installation instructions or use --disable-nanomsg])])
])
AM_CONDITIONAL([ENABLE_RABBITMQ], [test "x$enable_rabbitmq" = "xyes"])
AM_CONDITIONAL([ENABLE_RABBITMQEVH], [test "x$enable_rabbitmq_event_handler" = "xyes"])
AM_CONDITIONAL([ENABLE_MQTT], [test "x$enable_mqtt" = "xyes"])
AM_CONDITIONAL([ENABLE_NANOMSG], [test "x$enable_nanomsg" = "xyes"])

AC_TRY_COMPILE([
#include <stdlib.h>
Expand Down Expand Up @@ -854,6 +877,9 @@ AM_COND_IF([ENABLE_MQTT],
AM_COND_IF([ENABLE_PFUNIX],
[echo " Unix Sockets: yes"],
[echo " Unix Sockets: no"])
AM_COND_IF([ENABLE_NANOMSG],
[echo " Nanomsg: yes"],
[echo " Nanomsg: no"])
echo "Plugins:"
AM_COND_IF([ENABLE_PLUGIN_ECHOTEST],
[echo " Echo Test: yes"],
Expand Down
39 changes: 28 additions & 11 deletions mainpage.dox
Expand Up @@ -90,6 +90,7 @@
* - \b libwebsockets: https://libwebsockets.org/ (\c optional, WebSockets)
* - \b rabbitmq-c: https://github.com/alanxz/rabbitmq-c (\c optional, v1.0.4, RabbitMQ)
* - \b paho.mqtt.c: https://eclipse.org/paho/clients/c (\c optional, v1.1.0, MQTT)
* - \b nanomsg: https://nanomsg.org/ (\c optional, Nanomsg)
* - \b Sofia-SIP: http://sofia-sip.sourceforge.net/ (\c optional, only needed for the SIP plugin)
* - \b libopus: http://opus-codec.org/ (\c optional, only needed for the bridge plugin)
* - \b libogg: http://xiph.org/ogg/ (\c optional, only needed for the voicemail plugin)
Expand All @@ -102,10 +103,10 @@

/*! \page JS JavaScript API
* The gateway exposes, assuming the HTTP transport has been compiled, a
* pseudo-RESTful interface, and optionally also WebSocket/RabbitMQ/MQTT/UnixSockets
* pseudo-RESTful interface, and optionally also WebSocket/RabbitMQ/MQTT/Nanomsg/UnixSockets
* interfaces as well, all of which based on JSON messages. These
* interfaces are described in more detail in the \ref plainhttp \ref WS
* \ref rabbit \ref mqtt and \ref unix documentation respectively, and all allow clients to
* \ref rabbit \ref apimqtt \ref apinanomsg and \ref unix documentation respectively, and all allow clients to
* take advantage of the features provided by Janus and the functionality
* made available by its plugins. Considering most clients will be web browsers,
* a common choice will be to rely on either the REST or the WebSockets
Expand Down Expand Up @@ -965,25 +966,25 @@ export const initialiseJanusLibrary = () => Janus.init({dependencies: setupDeps(
* otherwise pass an \c Error object like \c callback(error)
*/

/*! \page rest RESTful, WebSockets, RabbitMQ, MQTT and UnixSockets API
/*! \page rest RESTful, WebSockets, RabbitMQ, MQTT, Nanomsg and UnixSockets API
*
* Since version \c 0.0.6, there are three different ways to interact with a
* Janus instance: a \ref plainhttp (the default), a \ref WS, a \ref rabbit, \ref mqtt
* Janus instance: a \ref plainhttp (the default), a \ref WS, a \ref rabbit, \ref apimqtt, \ref apinanomsg
* and a \ref unix (both optional, need an external library to be available). All of
* the interfaces use the same messages (in terms of requests, responses
* and notifications), so almost all the concepts described in the
* \ref plainhttp section apply to the WebSocket/RabbitMQ/MQTT/UnixSockets interfaces as well.
* \ref plainhttp section apply to the WebSocket/RabbitMQ/MQTT/Nanomsg/UnixSockets interfaces as well.
* Besides, since version \c 0.1.0 the transport mechanism for the Janus API
* has been made modular, which means other protocols for transporting
* Janus API messages might become available in the future: considering the
* Janus protocol is supposed to be mostly agnostic to the protocol it is
* transported on, the concepts explained in the following sections should
* apply to those as well.
*
* As it will be explained later in the \ref WS, \ref rabbit and \ref unix sections
* As it will be explained later in the \ref WS, \ref rabbit, \ref apimqtt, \ref apinanomsg and \ref unix sections
* below, the only differences come when addressing specific sessions/handles
* and in part in how you handle notifications using something different than
* the REST interface: in fact, since with WebSockets, RabbitMQ, MQTT and UnixSockets
* the REST interface: in fact, since with WebSockets, RabbitMQ, MQTT, Nanomsg and UnixSockets
* (and, as anticipated, with other protocols that may be added in the future too)
* there's no REST-based path involved, you'll need a couple of additional
* identifiers to bridge the gap.
Expand Down Expand Up @@ -1498,7 +1499,7 @@ GET http://host:port/janus/<sessionid>?maxev=5
* As anticipated in the previous sections, Janus can send events and
* notifications at any time through the long poll channel (or, as it
* will be explained later, through the related push mechanisms made
* available by the \ref WS, \ref rabbit and \ref unix ). While this channel is
* available by other transport protocols ). While this channel is
* mostly used to convey asynchronous notifications originated by
* plugins as part of the messaging they may have with the application
* using it, the same channel is actually used by Janus to trigger
Expand Down Expand Up @@ -1780,7 +1781,7 @@ var websocket = new WebSocket('ws://1.2.3.4:8188', 'janus-protocol');
* implemented to do so, by looking at the Janus-level \c transaction
* identifier.
*
* \section mqtt MQTT interface
* \section apimqtt MQTT interface
* The semantics of how the requests have to be built, when compared to
* the usage of plain HTTP, is exactly the same as for WebSockets, so
* refer to the \ref WS documentation for details about that.
Expand All @@ -1800,11 +1801,21 @@ var websocket = new WebSocket('ws://1.2.3.4:8188', 'janus-protocol');
* The proper usage of these queues will allow you to implement the kind
* of bidirectional channel Janus needs.
*
* \section unix UnixSockets interface
* \section apinanomsg Nanomsg interface
* The semantics of how the requests have to be built, when compared to
* the usage of plain HTTP, is exactly the same as for WebSockets, RabbitMQ
* and MQTT, so refer to the \ref WS documentation for details about that.
*
* Apart from that, the only configuration needed is related to the Nanomsg
* address to use, and whether it should be used to bind locally or to
* connect to a remote endpoint. Notice that only the \c NN_PAIR pattern
* is supported by the plugin, so no Pub/Sub or other variations.
*
* \section unix UnixSockets interface
* The semantics of how the requests have to be built, when compared to
* the usage of plain HTTP, is exactly the same as for WebSockets, RabbitMQ
* MQTT and Nanomsg, so refer to the \ref WS documentation for details about that.
*
* Apart from that, the only configuration needed is related to the path
* the client and server will be sharing, and the socket type. Notice that only the
* \c SOCK_SEQPACKET and \c SOCK_DGRAM types are supported in the plugin.
Expand Down Expand Up @@ -3261,6 +3272,7 @@ ldd janus | grep asan
* -# <a href="#rabbitmq">Can I use RabbitMQ instead of HTTP/WebSockets to interact with Janus?</a>\n
* -# <a href="#unixsockets">Can I use Unix Sockets instead of HTTP/WebSockets/RabbitMQ to interact with Janus?</a>\n
* -# <a href="#mqtt">Can I use MQTT instead of HTTP/WebSockets/RabbitMQ/Unix Sockets to interact with Janus?</a>\n
* -# <a href="#nanomsg">Can I use Nanomsg instead of HTTP/WebSockets/RabbitMQ/MQTT/Unix Sockets to interact with Janus?</a>\n
* -# <a href="#transports">What about \<my favourite control protocol\> instead?</a>\n
* -# <a href="#demos">I've launched Janus, how do I try the demos?</a>\n
* -# <a href="#certificates">I'm trying the demos, but I get "Janus down" or certificate errors!</a>\n
Expand Down Expand Up @@ -3518,7 +3530,12 @@ ldd janus | grep asan
* .
* Since version \c 0.2.1, you can! This was a very welcome contribution by
* a Janus user, as it makes it even easier to have Janus interact with IoT deployments.
* For more information, check the \ref mqtt page. \n\n
* For more information, check the \ref apimqtt page. \n\n
* .
* \anchor nanomsg
* -# <b>Can I use Nanomsg instead of HTTP/WebSockets/RabbitMQ/MQTT/Unix Sockets to interact with Janus?</b>\n
* .
* Since version \c 0.4.2, you can! For more information, check the \ref apinanomsg page. \n\n
* .
* \anchor transports
* -# <b>What about \<my favourite control protocol\> instead?</b>\n
Expand Down

0 comments on commit 4388d55

Please sign in to comment.