Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version of Janus module #3533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions db/schema/janus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
"https://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
%entities;

]>

<table id="janus" xmlns:db="http://docbook.org/ns/docbook">
<name>janus</name>
<version>1</version>
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
<description>
<db:para>This table is used by the JANUS module to store
definitions of socket(s) used to connect to.
More information can be found at: &OPENSIPS_MOD_DOC;janus.html.
</db:para>
</description>

<column id="id">
<name>id</name>
<type>unsigned int</type>
<size>&table_id_len;</size>
<autoincrement/>
<natural/>
<primary/>
<type db="dbtext">int,auto</type>
<description>Unique ID</description>
</column>

<column>
<name>janus_id</name>
<type>text</type>
<description>JANUS identifier as referenced from the OpenSIPS script. Example: "my_janus".
</description>
</column>

<column>
<name>janus_url</name>
<type>text</type>
<description>JANUS socket used to send commands.
Example: "janusws://1.2.3.4:80/janus?room=abcd".
</description>
</column>

</table>
12 changes: 12 additions & 0 deletions db/schema/opensips-janus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
"https://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
%entities;
]>

<database xmlns:xi="http://www.w3.org/2001/XInclude">
<name>JANUS</name>
<xi:include href="janus.xml"/>
</database>
2 changes: 1 addition & 1 deletion ip_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
enum sip_protos { PROTO_NONE = 0, PROTO_FIRST = 1, PROTO_UDP = 1, \
PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_WS, PROTO_WSS, PROTO_IPSEC, PROTO_BIN,
PROTO_BINS, PROTO_HEP_UDP, PROTO_HEP_TCP, PROTO_HEP_TLS, PROTO_SMPP, PROTO_MSRP,
PROTO_MSRPS, PROTO_OTHER };
PROTO_MSRPS, PROTO_JANUSWS, PROTO_JANUSWSS, PROTO_OTHER };
#define PROTO_LAST PROTO_OTHER

struct ip_addr{
Expand Down
13 changes: 13 additions & 0 deletions modules/janus/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# JANUS implementation
#
#
# WARNING: do not run this directly, it should be run by the master Makefile

include ../../Makefile.defs
auto_gen=
NAME=janus.so
LIBS=

include ../../Makefile.modules

246 changes: 246 additions & 0 deletions modules/janus/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
JANUS Module
__________________________________________________________

Table of Contents

1. Admin Guide

1.1. Overview
1.2. External Libraries or Applications

1.2.1. OpenSIPS Modules

1.3. Exported Parameters

1.3.1. janus_send_timeout (integer)
1.3.2. janus_max_msg_chunks (integer)
1.3.3. janus_cmd_timeout (integer)
1.3.4. janus_cmd_polling_itv (integer)
1.3.5. janus_ping_interval (integer)
1.3.6. janus_db_url (string)
1.3.7. janus_db_table (string)

1.4. Exported Functions

1.4.1. janus_send_requeest(janus_id, janus_command[,
response_var])

1.4.2. Exported Events

List of Examples

1.1. Setting the janus_send_timeout parameter
1.2. Setting the janus_max_msg_chunks parameter
1.3. Setting the janus_cmd_timeout parameter
1.4. Setting the janus_cmd_polling_itv parameter
1.5. Setting the janus_ping_interval parameter
1.6. Setting the janus_db_url parameter
1.7. Setting the janus_db_table parameter
1.8. janus_send_request() usage
1.9. E_JANUS_EVENT example

Chapter 1. Admin Guide

1.1. Overview

The "janus" module is a C driver for the Janus websocket
protocol. It can interact with one or more Janus servers either
by issuing commands to them, or by receiving events from them.

This driver can be seen as a centralized Janus connection
manager. It will connect to each Janus server, establish the
connection hanler ID and the clients can be transparent from
the connection handler ID point of view, simply passing the
desired Janus commands that they want to run.

1.2. External Libraries or Applications

1.2.1. OpenSIPS Modules

The following modules must be loaded together with this module:
* an SQL DB module

The following libraries or applications must be installed
before running OpenSIPS with this module loaded:
* None

1.3. Exported Parameters

1.3.1. janus_send_timeout (integer)

Time in milliseconds after a Janus WebSocket connection will be
closed if it is not available for blocking writing in this
interval (and OpenSIPS wants to send something on it).

Default value is "1000" (milliseconds).

Example 1.1. Setting the janus_send_timeout parameter
...
modparam("janus", "janus_send_timeout", 2000)
...

1.3.2. janus_max_msg_chunks (integer)

The maximum number of chunks in which a Janus message is
expected to arrive via WebSocket. If a received packet is more
fragmented than this, the connection is dropped

Default value is "4"

Example 1.2. Setting the janus_max_msg_chunks parameter
...
modparam("janus", "janus_max_msg_chunks", 8)
...

1.3.3. janus_cmd_timeout (integer)

The maximally allowed duration for the execution of an Janus
command. This interval does not include the connect duration.

Default value is "5000" (milliseconds).

Example 1.3. Setting the janus_cmd_timeout parameter
...
modparam("janus", "janus_cmd_timeout", 3000)
...

1.3.4. janus_cmd_polling_itv (integer)

The sleep interval used when polling for an Janus command
response. Since the value of this parameter imposes a minimal
duration for any Janus command, you should run OpenSIPS in
debug mode in order to first determine an expected response
time for an arbitrary Janus command, then tune this parameter
accordingly.

Default value is "1000" (microseconds).

Example 1.4. Setting the janus_cmd_polling_itv parameter
...
modparam("janus", "janus_cmd_polling_itv", 3000)
...

1.3.5. janus_ping_interval (integer)

The time interval at which OpenSIPS will do keepalive pinging
on the Janus connect

Default value is "5" (seconds).

Example 1.5. Setting the janus_ping_interval parameter
...
modparam("janus", "janus_ping_interval", 10)
...

1.3.6. janus_db_url (string)

The DB URL from where OpenSIPS will load the list of Janus
connection

Default value is ""none"" (needs to be set for the module to
start).

Example 1.6. Setting the janus_db_url parameter
...
modparam("janus", "janus_db_url", "mysql://root@localhost/opensips")
...

1.3.7. janus_db_table (string)

The DB Table from where OpenSIPS will load the list of Janus
connection

Default value is "janus"

Example 1.7. Setting the janus_db_table parameter
...
modparam("janus", "janus_db_table", "my_janus_table")
...

1.4. Exported Functions

1.4.1. janus_send_requeest(janus_id, janus_command[, response_var])

Run an arbitrary command on an arbitrary Janus socket. The
janus_id must be defined in the database

The current OpenSIPS worker will block until an answer from
Janus arrives. The timeout for this operation can be controlled
via the janus_cmd_timeout param.

Meaning of the parameters is as follows:
* janus_id (string) - the ID of the janus connection as
defined in the databsae.
* janus_command (string) - the JANUS command to run.
* response_var (var, optional) - a variable which will hold
the text result of the Janus command.

Return value
* 1 (success) - the Janus command executed successfully and
any output variables were successfully written to. Note
that this does not say anything about the nature of the
Janus answer (it may well be a "-ERR" type of response)
* -1 (failure) - internal error or the Janus command failed
to execute

This function can be used from any route.

Example 1.8. janus_send_request() usage
...
# if the DB contains:
# id: 1
# janus_id: test_janus
# janus_url: janusws://my_janus_host:80/janus?room=abcd

$var(rc) = janus_send_request("test_janus", "{
"janus": "attach",
"plugin": "janus.plugin.videoroom",
"transaction": "abcdef123456",
"session_id": 987654321
}", $var(response));
if (!$var(rc)) {
xlog("failed to execute Janus command ($var(rc))\n");
return -1;
}
xlog("Janus response is $var(response) \n");
...
...

1.4.2. Exported Events

1.4.2.1. E_JANUS_EVENT

This event is raised when a notification is received from a
Janus server.

Parameters represent the janus_id and the janus_url that
originated the notification, and the full janus_body of the
event received
* janus_id - the janus id as defined in the database
* janus_url - the janus url as defined in the database
* janus_body - full body of the notification received from
janus

Example 1.9. E_JANUS_EVENT example
...
# if the DB contains:
# id: 1
# janus_id: test_janus
# janus_url: janusws://my_janus_host:80/janus?room=abcd

event_route[E_JANUS_EVENT] {
xlog("Received janus event from $param(janus_id) - $param(janus_
url) - $param(janus_body) \n");
$json(janus_body) := $param(janus_body);
$avp(janus_sender) = $json(janus_body/sender);
if ($avp(janus_sender) != NULL) {
xlog("Received event from sender $avp(janus_sender) \n")
;
}
}
...
...

Documentation Copyrights:

Copyright © 2024 OpenSIPS Project;
24 changes: 24 additions & 0 deletions modules/janus/doc/janus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [


<!ENTITY admin SYSTEM "janus_admin.xml">

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../doc/entities.xml">
%docentities;

]>

<book>
<bookinfo>
<title>JANUS Module</title>
</bookinfo>
<toc></toc>

&admin;

&docCopyrights;
<para>&copyright; 2024 OpenSIPS Project;</para>
</book>
Loading
Loading