Revision 793d18b1

View differences:

plugins/janus_audiobridge.c
873 873
		*error = -2;
874 874
		return;
875 875
	}
876
	if(session->destroyed) {
877
		JANUS_LOG(LOG_WARN, "AudioBridge session already destroyed...\n");
878
		return;
879
	}
880 876
	JANUS_LOG(LOG_VERB, "Removing AudioBridge session...\n");
881 877
	janus_mutex_lock(&sessions_mutex);
882
	g_hash_table_remove(sessions, handle);
883
	janus_mutex_unlock(&sessions_mutex);
884
	janus_audiobridge_hangup_media(handle);
885
	/* Cleaning up and removing the session is done in a lazy way */
886
	session->destroyed = janus_get_monotonic_time();
887
	janus_mutex_lock(&sessions_mutex);
888
	old_sessions = g_list_append(old_sessions, session);
878
	if(!session->destroyed) {
879
		session->destroyed = janus_get_monotonic_time();
880
		g_hash_table_remove(sessions, handle);
881
		janus_audiobridge_hangup_media(handle);
882
		/* Cleaning up and removing the session is done in a lazy way */
883
		old_sessions = g_list_append(old_sessions, session);
884
	}
889 885
	janus_mutex_unlock(&sessions_mutex);
890 886

  
891 887
	return;
plugins/janus_echotest.c
390 390
	}
391 391
	JANUS_LOG(LOG_VERB, "Removing Echo Test session...\n");
392 392
	janus_mutex_lock(&sessions_mutex);
393
	g_hash_table_remove(sessions, handle);
394
	janus_mutex_unlock(&sessions_mutex);
395
	/* Cleaning up and removing the session is done in a lazy way */
396
	session->destroyed = janus_get_monotonic_time();
397
	janus_mutex_lock(&sessions_mutex);
398
	old_sessions = g_list_append(old_sessions, session);
393
	if(!session->destroyed) {
394
		session->destroyed = janus_get_monotonic_time();
395
		g_hash_table_remove(sessions, handle);
396
		/* Cleaning up and removing the session is done in a lazy way */
397
		old_sessions = g_list_append(old_sessions, session);
398
	}
399 399
	janus_mutex_unlock(&sessions_mutex);
400 400
	return;
401 401
}
plugins/janus_recordplay.c
661 661
		*error = -2;
662 662
		return;
663 663
	}
664
	if(session->destroyed) {
665
		JANUS_LOG(LOG_WARN, "Record&Play session already destroyed...\n");
666
		return;
667
	}
668
	JANUS_LOG(LOG_VERB, "Removing Record&Play session...\n");
669 664
	janus_mutex_lock(&sessions_mutex);
670
	g_hash_table_remove(sessions, handle);
671
	janus_mutex_unlock(&sessions_mutex);
672
	/* Cleaning up and removing the session is done in a lazy way */
673
	session->destroyed = janus_get_monotonic_time();
674
	janus_mutex_lock(&sessions_mutex);
675
	old_sessions = g_list_append(old_sessions, session);
665
	if(!session->destroyed) {
666
		session->destroyed = janus_get_monotonic_time();
667
		JANUS_LOG(LOG_VERB, "Removing Record&Play session...\n");
668
		g_hash_table_remove(sessions, handle);
669
		/* Cleaning up and removing the session is done in a lazy way */
670
		old_sessions = g_list_append(old_sessions, session);
671
	}
676 672
	janus_mutex_unlock(&sessions_mutex);
677 673
	return;
678 674
}
plugins/janus_sip.c
654 654
		*error = -2;
655 655
		return;
656 656
	}
657
	if(session->destroyed) {
658
		JANUS_LOG(LOG_VERB, "SIP session already destroyed...\n");
659
		return;
660
	}
661 657
	janus_mutex_lock(&sessions_mutex);
662
	g_hash_table_remove(sessions, handle);
663
	janus_mutex_unlock(&sessions_mutex);
664
	janus_sip_hangup_media(handle);
665
	JANUS_LOG(LOG_VERB, "Destroying SIP session (%s)...\n", session->account.username ? session->account.username : "unregistered user");
666
	/* Shutdown the NUA */
667
	nua_shutdown(session->stack->s_nua);
668
	/* Cleaning up and removing the session is done in a lazy way */
669
	session->destroyed = janus_get_monotonic_time();
670
	janus_mutex_lock(&sessions_mutex);
671
	old_sessions = g_list_append(old_sessions, session);
658
	if(!session->destroyed) {
659
		session->destroyed = janus_get_monotonic_time();
660
		g_hash_table_remove(sessions, handle);
661
		janus_sip_hangup_media(handle);
662
		JANUS_LOG(LOG_VERB, "Destroying SIP session (%s)...\n", session->account.username ? session->account.username : "unregistered user");
663
		/* Shutdown the NUA */
664
		nua_shutdown(session->stack->s_nua);
665
		/* Cleaning up and removing the session is done in a lazy way */
666
		old_sessions = g_list_append(old_sessions, session);
667
	}
672 668
	janus_mutex_unlock(&sessions_mutex);
673 669
	return;
674 670
}
plugins/janus_streaming.c
813 813
		janus_mutex_unlock(&session->mountpoint->mutex);
814 814
	}
815 815
	janus_mutex_lock(&sessions_mutex);
816
	g_hash_table_remove(sessions, handle);
817
	janus_mutex_unlock(&sessions_mutex);
818
	/* Cleaning up and removing the session is done in a lazy way */
819
	session->destroyed = janus_get_monotonic_time();
820
	janus_mutex_lock(&sessions_mutex);
821
	old_sessions = g_list_append(old_sessions, session);
816
	if(!session->destroyed) {
817
		session->destroyed = janus_get_monotonic_time();
818
		g_hash_table_remove(sessions, handle);
819
		/* Cleaning up and removing the session is done in a lazy way */
820
		old_sessions = g_list_append(old_sessions, session);
821
	}
822 822
	janus_mutex_unlock(&sessions_mutex);
823 823
	return;
824 824
}
plugins/janus_videocall.c
534 534
		*error = -2;
535 535
		return;
536 536
	}
537
	if(session->destroyed) {
538
		JANUS_LOG(LOG_VERB, "VideoCall session already destroyed...\n");
539
		return;
540
	}
541
	JANUS_LOG(LOG_VERB, "Removing VideoCall user %s session...\n", session->username ? session->username : "'unknown'");
542
	janus_videocall_hangup_media(handle);
543
	if(session->username != NULL) {
544
		janus_mutex_lock(&sessions_mutex);
545
		int res = g_hash_table_remove(sessions, (gpointer)session->username);
546
		JANUS_LOG(LOG_VERB, "  -- Removed: %d\n", res);
547
		janus_mutex_unlock(&sessions_mutex);
548
	}
549
	/* Cleaning up and removing the session is done in a lazy way */
550
	session->destroyed = janus_get_monotonic_time();
551 537
	janus_mutex_lock(&sessions_mutex);
552
	old_sessions = g_list_append(old_sessions, session);
538
	if(!session->destroyed) {
539
		session->destroyed = janus_get_monotonic_time();
540
		JANUS_LOG(LOG_VERB, "Removing VideoCall user %s session...\n", session->username ? session->username : "'unknown'");
541
		janus_videocall_hangup_media(handle);
542
		if(session->username != NULL) {
543
			int res = g_hash_table_remove(sessions, (gpointer)session->username);
544
			JANUS_LOG(LOG_VERB, "  -- Removed: %d\n", res);
545
		}
546
		/* Cleaning up and removing the session is done in a lazy way */
547
		old_sessions = g_list_append(old_sessions, session);
548
	}
553 549
	janus_mutex_unlock(&sessions_mutex);
554 550
	return;
555 551
}
plugins/janus_videoroom.c
774 774
		return;
775 775
	}
776 776
	JANUS_LOG(LOG_VERB, "Removing VideoRoom session...\n");
777
	/* Any related WebRTC PeerConnection is not available anymore either */
778
	janus_videoroom_hangup_media(handle);
779 777
	/* Cleaning up and removing the session is done in a lazy way */
780 778
	janus_mutex_lock(&sessions_mutex);
781
	session->destroyed = janus_get_monotonic_time();
782
	old_sessions = g_list_append(old_sessions, session);
783
	janus_mutex_unlock(&sessions_mutex);
784
	if(session->participant_type == janus_videoroom_p_type_publisher) {
785
		/* Get rid of publisher */
786
		janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
787
		participant->audio = FALSE;
788
		participant->video = FALSE;
789
		participant->data = FALSE;
790
		participant->audio_active = FALSE;
791
		participant->video_active = FALSE;
792
		participant->recording_active = FALSE;
793
		if(participant->recording_base)
794
			g_free(participant->recording_base);
795
		participant->recording_base = NULL;
796
		json_t *event = json_object();
797
		json_object_set_new(event, "videoroom", json_string("event"));
798
		json_object_set_new(event, "room", json_integer(participant->room->room_id));
799
		json_object_set_new(event, "leaving", json_integer(participant->user_id));
800
		char *leaving_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
801
		json_decref(event);
802
		GHashTableIter iter;
803
		gpointer value;
804
		/* we need to check if the room still exists, may have been destroyed already */
805
		if(participant->room) {
806
			if(!participant->room->destroyed) {
807
				janus_mutex_lock(&participant->room->participants_mutex);
808
				g_hash_table_iter_init(&iter, participant->room->participants);
809
				while (!participant->room->destroyed && g_hash_table_iter_next(&iter, NULL, &value)) {
810
					janus_videoroom_participant *p = value;
811
					if(p == participant) {
812
						continue;	/* Skip the leaving publisher itself */
779
	if(!session->destroyed) {
780
		session->destroyed = janus_get_monotonic_time();
781
		/* Any related WebRTC PeerConnection is not available anymore either */
782
		janus_videoroom_hangup_media(handle);
783
		old_sessions = g_list_append(old_sessions, session);
784
		if(session->participant_type == janus_videoroom_p_type_publisher) {
785
			/* Get rid of publisher */
786
			janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
787
			participant->audio = FALSE;
788
			participant->video = FALSE;
789
			participant->data = FALSE;
790
			participant->audio_active = FALSE;
791
			participant->video_active = FALSE;
792
			participant->recording_active = FALSE;
793
			if(participant->recording_base)
794
				g_free(participant->recording_base);
795
			participant->recording_base = NULL;
796
			json_t *event = json_object();
797
			json_object_set_new(event, "videoroom", json_string("event"));
798
			json_object_set_new(event, "room", json_integer(participant->room->room_id));
799
			json_object_set_new(event, "leaving", json_integer(participant->user_id));
800
			char *leaving_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
801
			json_decref(event);
802
			GHashTableIter iter;
803
			gpointer value;
804
			/* we need to check if the room still exists, may have been destroyed already */
805
			if(participant->room) {
806
				if(!participant->room->destroyed) {
807
					janus_mutex_lock(&participant->room->participants_mutex);
808
					g_hash_table_iter_init(&iter, participant->room->participants);
809
					while (!participant->room->destroyed && g_hash_table_iter_next(&iter, NULL, &value)) {
810
						janus_videoroom_participant *p = value;
811
						if(p == participant) {
812
							continue;	/* Skip the leaving publisher itself */
813
						}
814
						JANUS_LOG(LOG_VERB, "Notifying participant %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
815
						int ret = gateway->push_event(p->session->handle, &janus_videoroom_plugin, NULL, leaving_text, NULL, NULL);
816
						JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
813 817
					}
814
					JANUS_LOG(LOG_VERB, "Notifying participant %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
815
					int ret = gateway->push_event(p->session->handle, &janus_videoroom_plugin, NULL, leaving_text, NULL, NULL);
816
					JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
818
					g_hash_table_remove(participant->room->participants, GUINT_TO_POINTER(participant->user_id));
819
					janus_mutex_unlock(&participant->room->participants_mutex);
817 820
				}
818
				g_hash_table_remove(participant->room->participants, GUINT_TO_POINTER(participant->user_id));
819
				janus_mutex_unlock(&participant->room->participants_mutex);
820 821
			}
822
			g_free(leaving_text);
823
		} else if(session->participant_type == janus_videoroom_p_type_subscriber) {
824
			/* Detaching this listener from its publisher is already done by hangup_media */
825
		} else if(session->participant_type == janus_videoroom_p_type_subscriber_muxed) {
826
			/* Detaching this listener from its publishers is already done by hangup_media */
821 827
		}
822
		g_free(leaving_text);
823
	} else if(session->participant_type == janus_videoroom_p_type_subscriber) {
824
		/* Detaching this listener from its publisher is already done by hangup_media */
825
	} else if(session->participant_type == janus_videoroom_p_type_subscriber_muxed) {
826
		/* Detaching this listener from its publishers is already done by hangup_media */
827 828
	}
829
	janus_mutex_unlock(&sessions_mutex);
828 830

  
829 831
	return;
830 832
}
plugins/janus_voicemail.c
475 475
		*error = -2;
476 476
		return;
477 477
	}
478
	if(session->destroyed) {
479
		JANUS_LOG(LOG_WARN, "VoiceMail session already destroyed...\n");
480
		return;
481
	}
482
	JANUS_LOG(LOG_VERB, "Removing VoiceMail session...\n");
483 478
	janus_mutex_lock(&sessions_mutex);
484
	g_hash_table_remove(sessions, handle);
485
	janus_mutex_unlock(&sessions_mutex);
486
	janus_voicemail_hangup_media(handle);
487
	/* Cleaning up and removing the session is done in a lazy way */
488
	session->destroyed = janus_get_monotonic_time();
489
	janus_mutex_lock(&sessions_mutex);
490
	old_sessions = g_list_append(old_sessions, session);
479
	if(!session->destroyed) {
480
		session->destroyed = janus_get_monotonic_time();
481
		JANUS_LOG(LOG_VERB, "Removing VoiceMail session...\n");
482
		g_hash_table_remove(sessions, handle);
483
		janus_voicemail_hangup_media(handle);
484
		/* Cleaning up and removing the session is done in a lazy way */
485
		old_sessions = g_list_append(old_sessions, session);
486
	}
491 487
	janus_mutex_unlock(&sessions_mutex);
492 488

  
493 489
	return;

Also available in: Unified diff