Fork me on GitHub
Loading...
Searching...
No Matches
Data Structures | 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 "loggers/logger.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...
 

Typedefs

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.
 

Functions

gchar * janus_get_server_pem (void)
 Helper method to return the path to the provided server certificate.
 
gchar * janus_get_server_key (void)
 Helper method to return the path to the provided server certificate key.
 
gchar * janus_get_local_ip (void)
 Helper method to return the local IP address (autodetected by default)
 
gchar * janus_get_public_ip (guint index)
 Helper method to return a given public IP address to use in the SDP (if multiple are configured for 1-1 NAT)
 
guint janus_get_public_ip_count (void)
 Helper method to return the number of public IP addresses (if configured for 1-1 NAT)
 
void janus_add_public_ip (const char *ip)
 Helper method to add an IP address to use in the SDP.
 
gboolean janus_has_public_ipv4_ip (void)
 Helper method to check if we have at least one manually passed public IPv4 address (for 1-1 NAT management)
 
gboolean janus_has_public_ipv6_ip (void)
 Helper method to check if we have at least one manually passed public IPv6 address (for 1-1 NAT management)
 
gint janus_is_stopping (void)
 Helper method to check whether the server is being shut down.
 
gboolean janus_is_webrtc_encryption_enabled (void)
 Helper method to check whether WebRTC encryption is (as it should) enabled.
 
Janus Core-Client session methods
janus_sessionjanus_session_create (guint64 session_id)
 Method to create a new Janus Core-Client session.
 
janus_sessionjanus_session_find (guint64 session_id)
 Method to find an existing Janus Core-Client session from its ID.
 
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.
 
gint janus_session_destroy (janus_session *session)
 Method to destroy a Janus Core-Client session.
 
janus_ice_handlejanus_session_handles_find (janus_session *session, guint64 handle_id)
 Method to find an existing Janus ICE handle from its ID.
 
void janus_session_handles_insert (janus_session *session, janus_ice_handle *handle)
 Method to insert a Janus ICE handle in a session.
 
gint janus_session_handles_remove (janus_session *session, janus_ice_handle *handle)
 Method to remove a Janus ICE handle from a session.
 
void janus_session_handles_clear (janus_session *session)
 Method to remove all Janus ICE handles from a session.
 
json_tjanus_session_handles_list_json (janus_session *session)
 Method to list the IDs of all Janus ICE handles of a session as JSON.
 
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, json_error_t *error)
 Helper to allocate a janus_request instance.
 
void janus_request_destroy (janus_request *request)
 Helper to destroy a janus_request instance.
 
int janus_process_incoming_request (janus_request *request)
 Helper to process an incoming request, no matter where it comes from.
 
int janus_process_incoming_admin_request (janus_request *request)
 Helper to process an incoming admin/monitor request, no matter where it comes from.
 
int janus_process_success (janus_request *request, json_t *payload)
 Method to return a successful Janus response message (JSON) to the browser.
 
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.
 
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.
 
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.
 
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.
 
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.
 
Janus external logger plugin management

By default, Janus has integrated support for logging to stdout and to a static file. Custom and advanced logging can be accomplished using additional logger plugins. These logger plugins are shared objects that need to implement the interfaces defined in logger.h and as such are dynamically loaded by the server at startup, and unloaded when the server closes.

void janus_logger_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to destroy a logger instance.
 
void janus_loggerso_close (void *key, void *value, void *user_data)
 Callback (g_hash_table_foreach) invoked when it's time to close a logger plugin.
 
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.
 
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.
 
janus_pluginjanus_plugin_find (const gchar *package)
 Method to return a registered plugin instance out of its package name.
 

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

Typedef Documentation

◆ janus_request

typedef struct janus_request janus_request

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

◆ janus_session

typedef struct janus_session janus_session

Janus Core-Client session.

Function Documentation

◆ janus_add_public_ip()

void janus_add_public_ip ( const char *  ip)

Helper method to add an IP address to use in the SDP.

◆ janus_eventhandler_close()

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)

◆ janus_eventhandlerso_close()

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)

◆ janus_get_local_ip()

gchar * janus_get_local_ip ( void  )

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

◆ janus_get_public_ip()

gchar * janus_get_public_ip ( guint  index)

Helper method to return a given public IP address to use in the SDP (if multiple are configured for 1-1 NAT)

◆ janus_get_public_ip_count()

guint janus_get_public_ip_count ( void  )

Helper method to return the number of public IP addresses (if configured for 1-1 NAT)

◆ janus_get_server_key()

gchar * janus_get_server_key ( void  )

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

◆ janus_get_server_pem()

gchar * janus_get_server_pem ( void  )

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

◆ janus_has_public_ipv4_ip()

gboolean janus_has_public_ipv4_ip ( void  )

Helper method to check if we have at least one manually passed public IPv4 address (for 1-1 NAT management)

◆ janus_has_public_ipv6_ip()

gboolean janus_has_public_ipv6_ip ( void  )

Helper method to check if we have at least one manually passed public IPv6 address (for 1-1 NAT management)

◆ janus_is_stopping()

gint janus_is_stopping ( void  )

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

◆ janus_is_webrtc_encryption_enabled()

gboolean janus_is_webrtc_encryption_enabled ( void  )

Helper method to check whether WebRTC encryption is (as it should) enabled.

Note
This is required by the ICE and DTLS portions of the code to decide whether to do the DTLS handshake, and whether SRTP encryption is required. Disabling the WebRTC encryption is supposed to be a debugging tool you can use with the Chrome setting with the same name, --disable-webrtc-encryption , and you should NEVER use it otherwise (it would simply not work with regular WebRTC endpoints).
Returns
TRUE if WebRTC encryption is enabled (the default), and FALSE otherwise

◆ janus_logger_close()

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

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

Parameters
[in]keyKey of the loggers hash table (package name)
[in]valueThe janus_logger instance to destroy
[in]user_dataUser provided data (unused)

◆ janus_loggerso_close()

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

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

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

◆ janus_plugin_close()

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_find()

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

◆ janus_pluginso_close()

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)

◆ janus_process_error()

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

◆ janus_process_incoming_admin_request()

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

◆ janus_process_incoming_request()

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

◆ janus_process_success()

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

◆ janus_request_destroy()

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_new()

janus_request * janus_request_new ( janus_transport transport,
janus_transport_session instance,
void *  request_id,
gboolean  admin,
json_t message,
json_error_t *  error 
)

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_create()

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

◆ janus_session_destroy()

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_find()

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

◆ janus_session_handles_clear()

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_session_handles_find()

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

◆ janus_session_handles_insert()

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

◆ janus_session_handles_list_json()

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

◆ janus_session_handles_remove()

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

◆ janus_session_notify_event()

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

◆ janus_transport_close()

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)

◆ janus_transportso_close()

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)