Revision 793d18b1 plugins/janus_videoroom.c

View differences:

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
}

Also available in: Unified diff