Fork me on GitHub
Data Structures | Macros | Typedefs
transport.h File Reference

Modular Janus API transports. More...

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <inttypes.h>
#include <glib.h>
#include <jansson.h>
Include dependency graph for transport.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  janus_transport
 The transport plugin session and callbacks interface. More...
 
struct  janus_transport_callbacks
 Callbacks to contact the gateway. More...
 

Macros

#define JANUS_TRANSPORT_API_VERSION   6
 Version of the API, to match the one transport plugins were compiled against. More...
 
#define JANUS_TRANSPORT_INIT(...)
 Initialization of all transport plugin properties to NULL. More...
 

Typedefs

typedef struct janus_transport_callbacks janus_transport_callbacks
 Callbacks to contact the gateway. More...
 
typedef struct janus_transport janus_transport
 The transport plugin session and callbacks interface. More...
 
typedef janus_transportcreate_t(void)
 The hook that transport plugins need to implement to be created from the gateway. More...
 

Detailed Description

Modular Janus API transports.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

This header contains the definition of the callbacks both the gateway and all the transports need to implement to interact with each other. The structures to make the communication possible are defined here as well.

In particular, the gateway implements the janus_transport_callbacks interface. This means that, as a transport plugin, you can use the methods it exposes to contact the gateway, e.g., in order to notify an incoming message. In particular, the methods the gateway exposes to transport plugins are:

On the other hand, a transport plugin that wants to register at the gateway needs to implement the janus_transport interface. Besides, as a transport plugin is a shared object, and as such external to the gateway itself, in order to be dynamically loaded at startup it needs to implement the create_t() hook as well, that should return a pointer to the plugin instance. This is an example of such a step:

static janus_transport mytransport = {
        [..]
};

janus_transport *create(void) {
        JANUS_LOG(LOG_VERB, , "%s created!\n", MY_TRANSPORT_NAME);
        return &mytransport;
}

This will make sure that your transport plugin is loaded at startup by the gateway, if it is deployed in the proper folder.

As anticipated and described in the above example, a transport plugin must basically be an instance of the janus_transport type. As such, it must implement the following methods and callbacks for the gateway:

All the above methods and callbacks are mandatory: the Janus core will reject a transport plugin that doesn't implement any of the mandatory callbacks.

The gateway janus_transport_callbacks interface is provided to a transport plugin, together with the path to the configurations files folder, in the init() method. This path can be used to read and parse a configuration file for the transport plugin: the transport plugins we made available out of the box use the package name as a name for the file (e.g., janus.transport.http.cfg for the HTTP/HTTPS transport plugin), but you're free to use a different one, as long as it doesn't collide with existing ones. Besides, the existing transport plugins use the same INI format for configuration files the gateway uses (relying on the janus_config helpers for the purpose) but again, if you prefer a different format (XML, JSON, etc.) that's up to you.

Transport API

Macro Definition Documentation

◆ JANUS_TRANSPORT_API_VERSION

#define JANUS_TRANSPORT_API_VERSION   6

Version of the API, to match the one transport plugins were compiled against.

◆ JANUS_TRANSPORT_INIT

#define JANUS_TRANSPORT_INIT (   ...)
Value:
{ \
.init = NULL, \
.destroy = NULL, \
.get_api_compatibility = NULL, \
.get_version = NULL, \
.get_version_string = NULL, \
.get_description = NULL, \
.get_name = NULL, \
.get_author = NULL, \
.get_package = NULL, \
.is_janus_api_enabled = NULL, \
.is_admin_api_enabled = NULL, \
.send_message = NULL, \
.session_created = NULL, \
.session_over = NULL, \
## __VA_ARGS__ }

Initialization of all transport plugin properties to NULL.

Note
All transport plugins MUST add this as the FIRST line when initializing their transport plugin structure, e.g.:
static janus_transport janus_http_transport plugin =
        {
                JANUS_TRANSPORT_INIT,
                
                .init = janus_http_init,
                [..]

Typedef Documentation

◆ create_t

typedef janus_transport* create_t(void)

The hook that transport plugins need to implement to be created from the gateway.

◆ janus_transport

The transport plugin session and callbacks interface.

◆ janus_transport_callbacks

Callbacks to contact the gateway.