Skip to content

Commit 326b2b3

Browse files
authored
Merge pull request #3533 from vladpaiu/janus_mod
Initial version of Janus module
2 parents 1d4e266 + 62233d4 commit 326b2b3

29 files changed

+4831
-0
lines changed

db/schema/janus.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
3+
"https://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [
4+
5+
<!ENTITY % entities SYSTEM "entities.xml">
6+
%entities;
7+
8+
]>
9+
10+
<table id="janus" xmlns:db="http://docbook.org/ns/docbook">
11+
<name>janus</name>
12+
<version>1</version>
13+
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
14+
<description>
15+
<db:para>This table is used by the JANUS module to store
16+
definitions of socket(s) used to connect to.
17+
More information can be found at: &OPENSIPS_MOD_DOC;janus.html.
18+
</db:para>
19+
</description>
20+
21+
<column id="id">
22+
<name>id</name>
23+
<type>unsigned int</type>
24+
<size>&table_id_len;</size>
25+
<autoincrement/>
26+
<natural/>
27+
<primary/>
28+
<type db="dbtext">int,auto</type>
29+
<description>Unique ID</description>
30+
</column>
31+
32+
<column>
33+
<name>janus_id</name>
34+
<type>text</type>
35+
<description>JANUS identifier as referenced from the OpenSIPS script. Example: "my_janus".
36+
</description>
37+
</column>
38+
39+
<column>
40+
<name>janus_url</name>
41+
<type>text</type>
42+
<description>JANUS socket used to send commands.
43+
Example: "janusws://1.2.3.4:80/janus?room=abcd".
44+
</description>
45+
</column>
46+
47+
</table>

db/schema/opensips-janus.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE database PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
3+
"https://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [
4+
5+
<!ENTITY % entities SYSTEM "entities.xml">
6+
%entities;
7+
]>
8+
9+
<database xmlns:xi="http://www.w3.org/2001/XInclude">
10+
<name>JANUS</name>
11+
<xi:include href="janus.xml"/>
12+
</database>

modules/janus/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# JANUS implementation
3+
#
4+
#
5+
# WARNING: do not run this directly, it should be run by the master Makefile
6+
7+
include ../../Makefile.defs
8+
auto_gen=
9+
NAME=janus.so
10+
LIBS=
11+
12+
include ../../Makefile.modules
13+

modules/janus/README

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
JANUS Module
2+
__________________________________________________________
3+
4+
Table of Contents
5+
6+
1. Admin Guide
7+
8+
1.1. Overview
9+
1.2. External Libraries or Applications
10+
11+
1.2.1. OpenSIPS Modules
12+
13+
1.3. Exported Parameters
14+
15+
1.3.1. janus_send_timeout (integer)
16+
1.3.2. janus_max_msg_chunks (integer)
17+
1.3.3. janus_cmd_timeout (integer)
18+
1.3.4. janus_cmd_polling_itv (integer)
19+
1.3.5. janus_ping_interval (integer)
20+
1.3.6. janus_db_url (string)
21+
1.3.7. janus_db_table (string)
22+
23+
1.4. Exported Functions
24+
25+
1.4.1. janus_send_requeest(janus_id, janus_command[,
26+
response_var])
27+
28+
1.4.2. Exported Events
29+
30+
List of Examples
31+
32+
1.1. Setting the janus_send_timeout parameter
33+
1.2. Setting the janus_max_msg_chunks parameter
34+
1.3. Setting the janus_cmd_timeout parameter
35+
1.4. Setting the janus_cmd_polling_itv parameter
36+
1.5. Setting the janus_ping_interval parameter
37+
1.6. Setting the janus_db_url parameter
38+
1.7. Setting the janus_db_table parameter
39+
1.8. janus_send_request() usage
40+
1.9. E_JANUS_EVENT example
41+
42+
Chapter 1. Admin Guide
43+
44+
1.1. Overview
45+
46+
The "janus" module is a C driver for the Janus websocket
47+
protocol. It can interact with one or more Janus servers either
48+
by issuing commands to them, or by receiving events from them.
49+
50+
This driver can be seen as a centralized Janus connection
51+
manager. It will connect to each Janus server, establish the
52+
connection hanler ID and the clients can be transparent from
53+
the connection handler ID point of view, simply passing the
54+
desired Janus commands that they want to run.
55+
56+
1.2. External Libraries or Applications
57+
58+
1.2.1. OpenSIPS Modules
59+
60+
The following modules must be loaded together with this module:
61+
* an SQL DB module
62+
63+
The following libraries or applications must be installed
64+
before running OpenSIPS with this module loaded:
65+
* None
66+
67+
1.3. Exported Parameters
68+
69+
1.3.1. janus_send_timeout (integer)
70+
71+
Time in milliseconds after a Janus WebSocket connection will be
72+
closed if it is not available for blocking writing in this
73+
interval (and OpenSIPS wants to send something on it).
74+
75+
Default value is "1000" (milliseconds).
76+
77+
Example 1.1. Setting the janus_send_timeout parameter
78+
...
79+
modparam("janus", "janus_send_timeout", 2000)
80+
...
81+
82+
1.3.2. janus_max_msg_chunks (integer)
83+
84+
The maximum number of chunks in which a Janus message is
85+
expected to arrive via WebSocket. If a received packet is more
86+
fragmented than this, the connection is dropped
87+
88+
Default value is "4"
89+
90+
Example 1.2. Setting the janus_max_msg_chunks parameter
91+
...
92+
modparam("janus", "janus_max_msg_chunks", 8)
93+
...
94+
95+
1.3.3. janus_cmd_timeout (integer)
96+
97+
The maximally allowed duration for the execution of an Janus
98+
command. This interval does not include the connect duration.
99+
100+
Default value is "5000" (milliseconds).
101+
102+
Example 1.3. Setting the janus_cmd_timeout parameter
103+
...
104+
modparam("janus", "janus_cmd_timeout", 3000)
105+
...
106+
107+
1.3.4. janus_cmd_polling_itv (integer)
108+
109+
The sleep interval used when polling for an Janus command
110+
response. Since the value of this parameter imposes a minimal
111+
duration for any Janus command, you should run OpenSIPS in
112+
debug mode in order to first determine an expected response
113+
time for an arbitrary Janus command, then tune this parameter
114+
accordingly.
115+
116+
Default value is "1000" (microseconds).
117+
118+
Example 1.4. Setting the janus_cmd_polling_itv parameter
119+
...
120+
modparam("janus", "janus_cmd_polling_itv", 3000)
121+
...
122+
123+
1.3.5. janus_ping_interval (integer)
124+
125+
The time interval at which OpenSIPS will do keepalive pinging
126+
on the Janus connect
127+
128+
Default value is "5" (seconds).
129+
130+
Example 1.5. Setting the janus_ping_interval parameter
131+
...
132+
modparam("janus", "janus_ping_interval", 10)
133+
...
134+
135+
1.3.6. janus_db_url (string)
136+
137+
The DB URL from where OpenSIPS will load the list of Janus
138+
connection
139+
140+
Default value is ""none"" (needs to be set for the module to
141+
start).
142+
143+
Example 1.6. Setting the janus_db_url parameter
144+
...
145+
modparam("janus", "janus_db_url", "mysql://root@localhost/opensips")
146+
...
147+
148+
1.3.7. janus_db_table (string)
149+
150+
The DB Table from where OpenSIPS will load the list of Janus
151+
connection
152+
153+
Default value is "janus"
154+
155+
Example 1.7. Setting the janus_db_table parameter
156+
...
157+
modparam("janus", "janus_db_table", "my_janus_table")
158+
...
159+
160+
1.4. Exported Functions
161+
162+
1.4.1. janus_send_requeest(janus_id, janus_command[, response_var])
163+
164+
Run an arbitrary command on an arbitrary Janus socket. The
165+
janus_id must be defined in the database
166+
167+
The current OpenSIPS worker will block until an answer from
168+
Janus arrives. The timeout for this operation can be controlled
169+
via the janus_cmd_timeout param.
170+
171+
Meaning of the parameters is as follows:
172+
* janus_id (string) - the ID of the janus connection as
173+
defined in the databsae.
174+
* janus_command (string) - the JANUS command to run.
175+
* response_var (var, optional) - a variable which will hold
176+
the text result of the Janus command.
177+
178+
Return value
179+
* 1 (success) - the Janus command executed successfully and
180+
any output variables were successfully written to. Note
181+
that this does not say anything about the nature of the
182+
Janus answer (it may well be a "-ERR" type of response)
183+
* -1 (failure) - internal error or the Janus command failed
184+
to execute
185+
186+
This function can be used from any route.
187+
188+
Example 1.8. janus_send_request() usage
189+
...
190+
# if the DB contains:
191+
# id: 1
192+
# janus_id: test_janus
193+
# janus_url: janusws://my_janus_host:80/janus?room=abcd
194+
195+
$var(rc) = janus_send_request("test_janus", "{
196+
"janus": "attach",
197+
"plugin": "janus.plugin.videoroom",
198+
"transaction": "abcdef123456",
199+
"session_id": 987654321
200+
}", $var(response));
201+
if (!$var(rc)) {
202+
xlog("failed to execute Janus command ($var(rc))\n");
203+
return -1;
204+
}
205+
xlog("Janus response is $var(response) \n");
206+
...
207+
...
208+
209+
1.4.2. Exported Events
210+
211+
1.4.2.1. E_JANUS_EVENT
212+
213+
This event is raised when a notification is received from a
214+
Janus server.
215+
216+
Parameters represent the janus_id and the janus_url that
217+
originated the notification, and the full janus_body of the
218+
event received
219+
* janus_id - the janus id as defined in the database
220+
* janus_url - the janus url as defined in the database
221+
* janus_body - full body of the notification received from
222+
janus
223+
224+
Example 1.9. E_JANUS_EVENT example
225+
...
226+
# if the DB contains:
227+
# id: 1
228+
# janus_id: test_janus
229+
# janus_url: janusws://my_janus_host:80/janus?room=abcd
230+
231+
event_route[E_JANUS_EVENT] {
232+
xlog("Received janus event from $param(janus_id) - $param(janus_
233+
url) - $param(janus_body) \n");
234+
$json(janus_body) := $param(janus_body);
235+
$avp(janus_sender) = $json(janus_body/sender);
236+
if ($avp(janus_sender) != NULL) {
237+
xlog("Received event from sender $avp(janus_sender) \n")
238+
;
239+
}
240+
}
241+
...
242+
...
243+
244+
Documentation Copyrights:
245+
246+
Copyright � 2024 OpenSIPS Project;

modules/janus/doc/janus.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding='UTF-8'?>
2+
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3+
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4+
5+
6+
<!ENTITY admin SYSTEM "janus_admin.xml">
7+
8+
<!-- Include general documentation entities -->
9+
<!ENTITY % docentities SYSTEM "../../../doc/entities.xml">
10+
%docentities;
11+
12+
]>
13+
14+
<book>
15+
<bookinfo>
16+
<title>JANUS Module</title>
17+
</bookinfo>
18+
<toc></toc>
19+
20+
&admin;
21+
22+
&docCopyrights;
23+
<para>&copyright; 2024 OpenSIPS Project;</para>
24+
</book>

0 commit comments

Comments
 (0)