@@ -202,7 +202,7 @@ room-<unique room ID>: {
202
202
"secret" : "<room secret, mandatory if configured>",
203
203
"new_description" : "<new pretty name of the room, optional>",
204
204
"new_secret" : "<new password required to edit/destroy the room, optional>",
205
- "new_pin" : "<new password required to join the room, optional>",
205
+ "new_pin" : "<new PIN required to join the room, PIN will be removed if set to an empty string , optional>",
206
206
"new_is_private" : <true|false, whether the room should appear in a list request>,
207
207
"new_record_dir" : "<new path where new recording files should be saved>",
208
208
"new_mjrs_dir" : "<new path where new MJR files should be saved>",
@@ -354,6 +354,29 @@ room-<unique room ID>: {
354
354
{
355
355
"audiobridge" : "success",
356
356
}
357
+ \endverbatim
358
+ *
359
+ * If you're the administrator of a room (that is, you created it and have access
360
+ * to the secret) you can kick all participants using the \c kick_all request. Notice
361
+ * that this only kicks all users out of the room, but does not prevent them from
362
+ * re-joining: to ban them, you need to first remove them from the list of
363
+ * authorized users (see \c allowed request) and then perform \c kick_all.
364
+ * The \c kick_all request has to be formatted as follows:
365
+ *
366
+ \verbatim
367
+ {
368
+ "request" : "kick_all",
369
+ "secret" : "<room secret, mandatory if configured>",
370
+ "room" : <unique numeric ID of the room>
371
+ }
372
+ \endverbatim
373
+ *
374
+ * A successful request will result in a \c success response:
375
+ *
376
+ \verbatim
377
+ {
378
+ "audiobridge" : "success",
379
+ }
357
380
\endverbatim
358
381
*
359
382
* To get a list of the available rooms (excluded those configured or
@@ -3476,10 +3499,14 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
3476
3499
audiobridge -> room_secret = new_secret ;
3477
3500
g_free (old_secret );
3478
3501
}
3479
- if (pin && strlen ( json_string_value ( pin )) > 0 ) {
3502
+ if (pin ) {
3480
3503
char * old_pin = audiobridge -> room_pin ;
3481
- char * new_pin = g_strdup (json_string_value (pin ));
3482
- audiobridge -> room_pin = new_pin ;
3504
+ if (strlen (json_string_value (pin )) > 0 ) {
3505
+ char * new_pin = g_strdup (json_string_value (pin ));
3506
+ audiobridge -> room_pin = new_pin ;
3507
+ } else {
3508
+ audiobridge -> room_pin = NULL ;
3509
+ }
3483
3510
g_free (old_pin );
3484
3511
}
3485
3512
if (recdir ) {
@@ -3820,7 +3847,7 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
3820
3847
janus_mutex_unlock (& participant -> rec_mutex );
3821
3848
}
3822
3849
}
3823
- }
3850
+ }
3824
3851
janus_mutex_unlock (& audiobridge -> mutex );
3825
3852
janus_refcount_decrease (& audiobridge -> ref );
3826
3853
response = json_object ();
@@ -4349,8 +4376,8 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
4349
4376
goto prepare_response ;
4350
4377
}
4351
4378
janus_refcount_increase (& audiobridge -> ref );
4352
- janus_mutex_lock (& audiobridge -> mutex );
4353
4379
janus_mutex_unlock (& rooms_mutex );
4380
+ janus_mutex_lock (& audiobridge -> mutex );
4354
4381
/* A secret may be required for this action */
4355
4382
JANUS_CHECK_SECRET (audiobridge -> room_secret , root , "secret" , error_code , error_cause ,
4356
4383
JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_UNAUTHORIZED );
@@ -4412,6 +4439,100 @@ static json_t *janus_audiobridge_process_synchronous_request(janus_audiobridge_s
4412
4439
janus_mutex_unlock (& audiobridge -> mutex );
4413
4440
janus_refcount_decrease (& audiobridge -> ref );
4414
4441
goto prepare_response ;
4442
+ } else if (!strcasecmp (request_text , "kick_all" )) {
4443
+ JANUS_LOG (LOG_VERB , "Attempt to kick all participants from an existing AudioBridge room\n" );
4444
+ JANUS_VALIDATE_JSON_OBJECT (root , secret_parameters ,
4445
+ error_code , error_cause , TRUE,
4446
+ JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT );
4447
+ if (error_code != 0 )
4448
+ goto prepare_response ;
4449
+ if (!string_ids ) {
4450
+ JANUS_VALIDATE_JSON_OBJECT (root , room_parameters ,
4451
+ error_code , error_cause , TRUE,
4452
+ JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT );
4453
+ } else {
4454
+ JANUS_VALIDATE_JSON_OBJECT (root , roomstr_parameters ,
4455
+ error_code , error_cause , TRUE,
4456
+ JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT );
4457
+ }
4458
+ if (error_code != 0 )
4459
+ goto prepare_response ;
4460
+ json_t * room = json_object_get (root , "room" );
4461
+ guint64 room_id = 0 ;
4462
+ char room_id_num [30 ], * room_id_str = NULL ;
4463
+ if (!string_ids ) {
4464
+ room_id = json_integer_value (room );
4465
+ g_snprintf (room_id_num , sizeof (room_id_num ), "%" SCNu64 , room_id );
4466
+ room_id_str = room_id_num ;
4467
+ } else {
4468
+ room_id_str = (char * )json_string_value (room );
4469
+ }
4470
+ janus_mutex_lock (& rooms_mutex );
4471
+ janus_audiobridge_room * audiobridge = g_hash_table_lookup (rooms ,
4472
+ string_ids ? (gpointer )room_id_str : (gpointer )& room_id );
4473
+ if (audiobridge == NULL ) {
4474
+ janus_mutex_unlock (& rooms_mutex );
4475
+ error_code = JANUS_AUDIOBRIDGE_ERROR_NO_SUCH_ROOM ;
4476
+ JANUS_LOG (LOG_ERR , "No such room (%s)\n" , room_id_str );
4477
+ g_snprintf (error_cause , 512 , "No such room (%s)" , room_id_str );
4478
+ goto prepare_response ;
4479
+ }
4480
+ janus_refcount_increase (& audiobridge -> ref );
4481
+ janus_mutex_unlock (& rooms_mutex );
4482
+ janus_mutex_lock (& audiobridge -> mutex );
4483
+ /* A secret may be required for this action */
4484
+ JANUS_CHECK_SECRET (audiobridge -> room_secret , root , "secret" , error_code , error_cause ,
4485
+ JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT , JANUS_AUDIOBRIDGE_ERROR_UNAUTHORIZED );
4486
+ if (error_code != 0 ) {
4487
+ janus_mutex_unlock (& audiobridge -> mutex );
4488
+ janus_refcount_decrease (& audiobridge -> ref );
4489
+ goto prepare_response ;
4490
+ }
4491
+ GHashTableIter kick_iter ;
4492
+ gpointer kick_value ;
4493
+ g_hash_table_iter_init (& kick_iter , audiobridge -> participants );
4494
+ while (g_hash_table_iter_next (& kick_iter , NULL , & kick_value )) {
4495
+ janus_audiobridge_participant * participant = kick_value ;
4496
+ JANUS_LOG (LOG_VERB , "Kicking participant %s (%s)\n" ,
4497
+ participant -> user_id_str , participant -> display ? participant -> display : "??" );
4498
+ guint64 user_id = 0 ;
4499
+ char user_id_num [30 ], * user_id_str = NULL ;
4500
+ if (string_ids ) {
4501
+ user_id_str = participant -> user_id_str ;
4502
+ } else {
4503
+ user_id = participant -> user_id ;
4504
+ g_snprintf (user_id_num , sizeof (user_id_num ), "%" SCNu64 , user_id );
4505
+ user_id_str = user_id_num ;
4506
+ }
4507
+ /* Notify all participants about the kick */
4508
+ json_t * event = json_object ();
4509
+ json_object_set_new (event , "audiobridge" , json_string ("event" ));
4510
+ json_object_set_new (event , "room" , string_ids ? json_string (room_id_str ) : json_integer (room_id ));
4511
+ json_object_set_new (event , "kicked_all" , string_ids ? json_string (user_id_str ) : json_integer (user_id ));
4512
+ JANUS_LOG (LOG_VERB , "Notifying participant %s (%s)\n" , participant -> user_id_str , participant -> display ? participant -> display : "??" );
4513
+ int ret = gateway -> push_event (participant -> session -> handle , & janus_audiobridge_plugin , NULL , event , NULL );
4514
+ JANUS_LOG (LOG_VERB , " >> %d (%s)\n" , ret , janus_get_api_error (ret ));
4515
+ json_decref (event );
4516
+ /* Also notify event handlers */
4517
+ if (notify_events && gateway -> events_is_enabled ()) {
4518
+ json_t * info = json_object ();
4519
+ json_object_set_new (info , "event" , json_string ("kicked_all" ));
4520
+ json_object_set_new (info , "room" , string_ids ? json_string (room_id_str ) : json_integer (room_id ));
4521
+ json_object_set_new (info , "id" , string_ids ? json_string (user_id_str ) : json_integer (user_id ));
4522
+ gateway -> notify_event (& janus_audiobridge_plugin , session ? session -> handle : NULL , info );
4523
+ }
4524
+ /* Tell the core to tear down the PeerConnection, hangup_media will do the rest */
4525
+ if (participant && participant -> session )
4526
+ gateway -> close_pc (participant -> session -> handle );
4527
+ JANUS_LOG (LOG_VERB , "Kicked user %s from room %s\n" , user_id_str , room_id_str );
4528
+ }
4529
+ /* Prepare response */
4530
+ response = json_object ();
4531
+ json_object_set_new (response , "audiobridge" , json_string ("success" ));
4532
+ /* Done */
4533
+ janus_mutex_unlock (& audiobridge -> mutex );
4534
+ janus_refcount_decrease (& audiobridge -> ref );
4535
+ goto prepare_response ;
4415
4536
} else if (!strcasecmp (request_text , "listparticipants" )) {
4416
4537
/* List all participants in a room */
4417
4538
if (!string_ids ) {
0 commit comments