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

Janus core (headers) More...

#include <inttypes.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <jansson.h>
#include "mutex.h"
#include "ice.h"
#include "refcount.h"
#include "transports/transport.h"
#include "events/eventhandler.h"
#include "plugins/plugin.h"
Include dependency graph for janus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  janus_session
 Janus Core-Client session. More...
 
struct  janus_request
 Helper to address requests and their sources (e.g., a specific HTTP connection, websocket, RabbitMQ or others) More...
 

Macros

#define JANUS_BUFSIZE   8192
 

Typedefs

typedef struct janus_request janus_request
 Helper to address requests and their sources (e.g., a specific HTTP connection, websocket, RabbitMQ or others) More...
 
typedef struct janus_session janus_session
 Janus Core-Client session. More...
 

Functions

gchar * janus_get_server_pem (void)
 Helper method to return the path to the provided server certificate. More...
 
gchar * janus_get_server_key (void)
 Helper method to return the path to the provided server certificate key. More...
 
gchar * janus_get_local_ip (void)
 Helper method to return the local IP address (autodetected by default) More...
 
gchar * janus_get_public_ip (void)
 Helper method to return the IP address to use in the SDP (autodetected by default) More...
 
void janus_set_public_ip (const char *ip)
 Helper method to overwrite the IP address to use in the SDP. More...
 
gint janus_is_stopping (void)
 Helper method to check whether the server is being shut down. More...
 
Janus Core-Client session methods
janus_sessionjanus_session_create (guint64 session_id)
 Method to create a new Janus Core-Client session. More...
 
janus_sessionjanus_session_find (guint64 session_id)
 Method to find an existing Janus Core-Client session from its ID. More...
 
void janus_session_notify_event (janus_session *session, json_t *event)
 Method to add an event to notify to the queue of notifications for this session. More...
 
gint janus_session_destroy (janus_session *session)
 Method to destroy a Janus Core-Client session. More...
 
janus_ice_handlejanus_session_handles_find (janus_session *session, guint64 handle_id)
 Method to find an existing Janus ICE handle from its ID. More...
 
void janus_session_handles_insert (janus_session *session, janus_ice_handle *handle)
 Method to insert a Janus ICE handle in a session. More...
 
gint janus_session_handles_remove (janus_session *session, janus_ice_handle *handle)
 Method to remove a Janus ICE handle from a session. More...
 
void janus_session_handles_clear (janus_session *session)
 Method to remove all Janus ICE handles from a session. More...
 
json_tjanus_session_handles_list_json (janus_session *session)
 Method to list the IDs of all Janus ICE handles of a session as JSON. More...
 
Janus request processing

Since messages may come from different sources (plain HTTP, WebSockets, RabbitMQ and potentially even more in the future), we have a shared way to process messages: a method to process a request, and helper methods to return a success or an error message.

janus_requestjanus_request_new (janus_transport *transport, janus_transport_session *instance, void *request_id, gboolean admin, json_t *message)
 Helper to allocate a janus_request instance. More...
 
void janus_request_destroy (janus_request *request)
 Helper to destroy a janus_request instance. More...
 
int janus_process_incoming_request (janus_request *request)
 Helper to process an incoming request, no matter where it comes from. More...
 
int janus_process_incoming_admin_request (janus_request *request)
 Helper to process an incoming admin/monitor request, no matter where it comes from. More...
 
int janus_process_success (janus_request *request, json_t *payload)
 Method to return a successful Janus response message (JSON) to the browser. More...
 
int janus_process_error (janus_request *request, uint64_t session_id, const char *transaction, gint error, const char *format,...) G_GNUC_PRINTF(5
 Method to return an error Janus response message (JSON) to the browser. More...
 
Janus transport plugin management

The core doesn't support any transport for the Janus API by default. In order to be able to with external clients, transport plugins are needed, e.g., to provide support for REST HTTP/HTTPS, WebSockets, RabbitMQ or others. These transport plugins are shared objects that need to implement the interfaces defined in transport.h and as such are dynamically loaded by the server at startup, and unloaded when the server closes.

void janus_transport_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to destroy a transport instance. More...
 
void janus_transportso_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to close a transport plugin. More...
 
Janus event handler plugin management

The core doesn't notify anyone, except session originators, and only then only about stuff relevant to them. In order to allow for a more apt management of core and plugin related events on a broader sense, event handler plugins are needed. These event handler plugins are shared objects that need to implement the interfaces defined in eventhandler.h and as such are dynamically loaded by the server at startup, and unloaded when the server closes.

void janus_eventhandler_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to destroy an eventhandler instance. More...
 
void janus_eventhandlerso_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to close an eventhandler plugin. More...
 
Janus plugin management

As anticipated, the server doesn't provide any specific feature: it takes care of WebRTC-related stuff, and of sending and receiving JSON-based messages. To implement applications based on these foundations, plugins can be used. These plugins are shared objects that need to implement the interfaces defined in plugin.h and as such are dynamically loaded by the server at startup, and unloaded when the server closes.

void janus_plugin_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to destroy a plugin instance. More...
 
void janus_pluginso_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to close a plugin. More...
 
janus_pluginjanus_plugin_find (const gchar *package)
 Method to return a registered plugin instance out of its package name. More...
 

Detailed Description

Janus core (headers)

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

Implementation of the Janus core. This code takes care of the server initialization (command line/configuration) and setup, and makes use of the available transport plugins (by default HTTP, WebSockets, RabbitMQ, if compiled) and Janus protocol (a JSON-based protocol) to interact with the applications, whether they're web based or not. The core also takes care of bridging peers and plugins accordingly, in terms of both messaging and real-time media transfer via WebRTC.

Core

Macro Definition Documentation

#define JANUS_BUFSIZE   8192

Typedef Documentation

typedef struct janus_request janus_request

Helper to address requests and their sources (e.g., a specific HTTP connection, websocket, RabbitMQ or others)

typedef struct janus_session janus_session

Janus Core-Client session.

Function Documentation

void janus_eventhandler_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to destroy an eventhandler instance.

Parameters
[in]keyKey of the events hash table (package name)
[in]valueThe janus_eventhandler instance to destroy
[in]user_dataUser provided data (unused)
void janus_eventhandlerso_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to close an eventhandler plugin.

Parameters
[in]keyKey of the events hash table (package name)
[in]valueThe janus_eventhandler instance to close
[in]user_dataUser provided data (unused)
gchar* janus_get_local_ip ( void  )

Helper method to return the local IP address (autodetected by default)

gchar* janus_get_public_ip ( void  )

Helper method to return the IP address to use in the SDP (autodetected by default)

gchar* janus_get_server_key ( void  )

Helper method to return the path to the provided server certificate key.

gchar* janus_get_server_pem ( void  )

Helper method to return the path to the provided server certificate.

gint janus_is_stopping ( void  )

Helper method to check whether the server is being shut down.

void janus_plugin_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to destroy a plugin instance.

Parameters
[in]keyKey of the plugins hash table (package name)
[in]valueThe janus_plugin plugin instance to destroy
[in]user_dataUser provided data (unused)
janus_plugin* janus_plugin_find ( const gchar *  package)

Method to return a registered plugin instance out of its package name.

Parameters
[in]packageThe unique package name of the plugin
Returns
The plugin instance
void janus_pluginso_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to close a plugin.

Parameters
[in]keyKey of the plugins hash table (package name)
[in]valueThe janus_plugin plugin instance to close
[in]user_dataUser provided data (unused)
int janus_process_error ( janus_request request,
uint64_t  session_id,
const char *  transaction,
gint  error,
const char *  format,
  ... 
)

Method to return an error Janus response message (JSON) to the browser.

Parameters
[in]requestThe request instance and its source
[in]session_idJanus session identifier this error refers to
[in]transactionThe Janus transaction identifier
[in]errorThe error code as defined in apierror.h
[in]formatThe printf format of the reason string, followed by a variable number of arguments, if needed; if format is NULL, a pre-configured string associated with the error code is used
Returns
0 on success, a negative integer otherwise
int janus_process_incoming_admin_request ( janus_request request)

Helper to process an incoming admin/monitor request, no matter where it comes from.

Parameters
[in]requestThe request instance and its source
Returns
0 on success, a negative integer otherwise
int janus_process_incoming_request ( janus_request request)

Helper to process an incoming request, no matter where it comes from.

Parameters
[in]requestThe JSON request
Returns
0 on success, a negative integer otherwise
int janus_process_success ( janus_request request,
json_t payload 
)

Method to return a successful Janus response message (JSON) to the browser.

Parameters
[in]requestThe request instance and its source
[in]payloadThe payload to return as a JSON object
Returns
0 on success, a negative integer otherwise
void janus_request_destroy ( janus_request request)

Helper to destroy a janus_request instance.

Parameters
[in]requestThe janus_request instance to destroy
Note
The opaque pointers in the instance are not destroyed, that's up to you
janus_request* janus_request_new ( janus_transport transport,
janus_transport_session instance,
void *  request_id,
gboolean  admin,
json_t message 
)

Helper to allocate a janus_request instance.

Parameters
[in]transportPointer to the transport
[in]instancePointer to the transport-provided session instance
[in]request_idOpaque pointer to the request ID, if available
[in]adminWhether this is a Janus API or Admin API request
[in]messageOpaque pointer to the original request, if available
Returns
A pointer to a janus_request instance if successful, NULL otherwise
janus_session* janus_session_create ( guint64  session_id)

Method to create a new Janus Core-Client session.

Parameters
[in]session_idThe desired Janus Core-Client session ID, or 0 if it needs to be generated randomly
Returns
The created Janus Core-Client session if successful, NULL otherwise
gint janus_session_destroy ( janus_session session)

Method to destroy a Janus Core-Client session.

Parameters
[in]sessionThe Janus Core-Client session to destroy
Returns
0 in case of success, a negative integer otherwise
janus_session* janus_session_find ( guint64  session_id)

Method to find an existing Janus Core-Client session from its ID.

Parameters
[in]session_idThe Janus Core-Client session ID
Returns
The created Janus Core-Client session if successful, NULL otherwise
void janus_session_handles_clear ( janus_session session)

Method to remove all Janus ICE handles from a session.

Parameters
[in]sessionThe Janus Core-Client session
janus_ice_handle* janus_session_handles_find ( janus_session session,
guint64  handle_id 
)

Method to find an existing Janus ICE handle from its ID.

Parameters
[in]sessionThe Janus Core-Client session this ICE handle belongs to
[in]handle_idThe Janus ICE handle ID
Returns
The Janus ICE handle if successful, NULL otherwise
void janus_session_handles_insert ( janus_session session,
janus_ice_handle handle 
)

Method to insert a Janus ICE handle in a session.

Parameters
[in]sessionThe Janus Core-Client session
[in]handleThe Janus ICE handle
json_t* janus_session_handles_list_json ( janus_session session)

Method to list the IDs of all Janus ICE handles of a session as JSON.

Parameters
[in]sessionThe Janus Core-Client session
Returns
The JSON array
gint janus_session_handles_remove ( janus_session session,
janus_ice_handle handle 
)

Method to remove a Janus ICE handle from a session.

Parameters
[in]sessionThe Janus Core-Client session
[in]handleThe Janus ICE handle
Returns
The error code of janus_ice_handle_destroy
void janus_session_notify_event ( janus_session session,
json_t event 
)

Method to add an event to notify to the queue of notifications for this session.

Parameters
[in]sessionThe Janus Core-Client session this notification is related to
[in]eventThe event to notify as a Jansson JSON object
void janus_set_public_ip ( const char *  ip)

Helper method to overwrite the IP address to use in the SDP.

void janus_transport_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to destroy a transport instance.

Parameters
[in]keyKey of the transports hash table (package name)
[in]valueThe janus_transport instance to destroy
[in]user_dataUser provided data (unused)
void janus_transportso_close ( void *  key,
void *  value,
void *  user_data 
)

Callback (g_hash_table_foreach) invoked when it's time to close a transport plugin.

Parameters
[in]keyKey of the transports hash table (package name)
[in]valueThe janus_transport instance to close
[in]user_dataUser provided data (unused)