The hook that plugins need to implement to be created from the Janus core. More...

Janus plugin results

When a client sends a message to a plugin (e.g., a request or a command) this is notified to the plugin through a handle_message() callback. The plugin can then either handle the request immediately and provide a response (synchronous approach) or decide to queue it and process it later (asynchronous approach). In both cases the plugin must return a janus_plugin_result instance to the core, that will allow the client to: 1. know whether a response is immediately available or it will be later on through notifications, and 2. what the actual content of the result might be. Of course, notifications related to the transaction may occur later on even for synchronous requests, if the plugin was implemented with use cases that envisage this approach.

Note

An error may be returned as well, but this would cause a core-level error to be returned to the client. If you want to provide indications about a failed operation for application-level reason, the correct approach is to return a success with a plugin-specific payload describing the error.

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

In particular, the Janus core implements the janus_callbacks interface. This means that, as a plugin, you can use the methods it exposes to contact the core, e.g., in order to have it relay a message, event or RTP/RTCP packet to the peer you're handling. In particular, the methods the core exposes to plugins are:

push_event(): to send a JSON message/event to the peer (with or without an attached JSEP formatted SDP to negotiate a WebRTC PeerConnection); the syntax of the message/event is completely up to you, the only important thing is that it MUST be a JSON object, as it will be included as such within the Janus session/handle protocol;

relay_rtp(): to send/relay the peer an RTP packet;

relay_rtcp(): to send/relay the peer an RTCP message.

relay_data(): to send/relay the peer a SCTP DataChannel message.

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

create_session(): this method is called by the core to create a session between you and a peer;

handle_message(): a callback to notify you the peer sent you a message/request;

setup_media(): a callback to notify you the peer PeerConnection is now ready to be used;

incoming_rtp(): a callback to notify you a peer has sent you a RTP packet;

incoming_rtcp(): a callback to notify you a peer has sent you a RTCP message;

incoming_data(): a callback to notify you a peer has sent you a message on a SCTP DataChannel;

slow_link(): a callback to notify you a peer has sent a lot of NACKs recently, and the media path may be slow;

hangup_media(): a callback to notify you the peer PeerConnection has been closed (e.g., after a DTLS alert);

query_session(): this method is called by the core to get plugin-specific info on a session between you and a peer;

destroy_session(): this method is called by the core to destroy a session between you and a peer.

All the above methods and callbacks, except for incoming_rtp , incoming_rtcp , incoming_data and slow_link , are mandatory: the Janus core will reject a plugin that doesn't implement any of the mandatory callbacks. The previously mentioned ones, instead, are optional, so you're free to implement only those you care about. If your plugin will not handle any data channel, for instance, it makes sense to not implement the incoming_data callback at all. At the same time, if your plugin is ONLY going to use data channels and can't care less about RTP or RTCP, incoming_rtp and incoming_rtcp can be left out. Finally, slow_link is just there as a helper, some additional information you may be interested about, but you're not forced to receive it if you don't care.

The Janus core janus_callbacks interface is provided to a 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 plugin: the plugins we made available out of the box use the package name as a name for the file (e.g., janus.plugin.echotest.cfg for the Echo Test plugin), but you're free to use a different one, as long as it doesn't collide with existing ones. Besides, the existing plugins use the same INI format for configuration files the core 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.

Both the the Janus core and a plugin can have several different sessions with the same and/or different peers: to match a specific session, a plugin can rely on a mapping called janus_plugin_session that is what all the communication between the plugins and the core (that is, both methods invoked by the core and callbacks invoked by the plugins) will make use of. See the janus_videoroom.c plugin for an example of multiple handles associated to the same peer.

All messages/requests/events sent to and received from a plugin are asynchronous, meaning there's no way to immediately reply to a message sent by a browser, for instance. Messages/requests coming from browsers in a handle_message() callback, though, have a transaction identifier, which you can use in a push_event() reply to allow the browser to match it to the original request, if needed.

As anticipated, both handle_message() and push_event() can attach a JSEP/SDP payload. This means that a browser, for instance, can attach a JSEP/SDP offer to negotiate a WebRTC PeerConnection with a plugin: the plugin would then need to provide, immediately or not, a JSEP/SDP answer to do so. At the same time, a plugin may want to originate the call instead: in that case, the plugin would attach a JSEP/SDP offer in a push_event() call, to which the browser would then need to reply with a JSEP/SDP answer, as described in JavaScript API. Renegotiating a session can be done using the same mechanism above: in case plugins want to force an ICE restart, though, they must add a boolean property called restart to the JSEP object before passing it to the core. Notice that the core adds a property called update whenever the remote user is requesting a renegotiation, whether it's for ICE restarts or just for some media related change.

Note

It's important to notice that, while the Janus core would indeed take care of the WebRTC PeerConnection setup itself in terms of ICE/DTLS/RT(C)P on your behalf, plugins are what will actually manipulate the media flowing around, and as such it's them who are responsible for what concerns the codec negotiation in a JSEP/SDP offer/answer. This normally is not something you need to worry about, especially if you're just moving SDP around (e.g., janus_echotest.c or janus_videocall.c). If your plugin is going to generate media frames (e.g., as janus_audiobridge.c), you only support some codecs (e.g., Opus in janus_audiobridge.c) or you want to use the same SDP offer for several different sessions (e.g., a webinar), you need to make sure that your offer/answer does not contain anything you don't support. Besides, you also need to make sure that you use SDP-provided information (e.g., payload types, increasing versions in case of renegotiations) coherently.

Right now plugins can only interact with peers through the Janus core. Besides, a single PeerConnection can at the moment be used by only one plugin, as that plugin is actually the "owner" of the PeerConnection itself.

Macro Definition Documentation

#define JANUS_PLUGIN_API_VERSION 12

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

Note

This was added in version 0.0.7 of Janus, to address changes to the API that might break existing plugin or the core itself. All plugins MUST implement the get_api_compatibility() method to make this work. Do NOT try to launch a pre 0.0.7 plugin on a >= 0.0.7 Janus instance or it will crash.

#define JANUS_PLUGIN_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, \

.create_session = NULL, \

.handle_message = NULL, \

.setup_media = NULL, \

.incoming_rtp = NULL, \

.incoming_rtcp = NULL, \

.incoming_data = NULL, \

.slow_link = NULL, \

.hangup_media = NULL, \

.destroy_session = NULL, \

.query_session = NULL, \

## __VA_ARGS__ }

Initialization of all plugin properties to NULL.

Note

This was added in version 0.0.8 of Janus, to address changes to the API that might break existing plugin or the core itself. All plugins MUST add this as the FIRST line when initializing their plugin structure, e.g.: