|
| 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; |
0 commit comments