Revision 1d31e31f janus.c

View differences:

janus.c
170 170
	}
171 171
	json_object_set_new(info, "api_secret", json_string(api_secret != NULL ? "true" : "false"));
172 172
	json_object_set_new(info, "auth_token", json_string(janus_auth_is_enabled() ? "true" : "false"));
173
	json_object_set_new(info, "event_handlers", json_string(janus_events_is_enabled() ? "true" : "false"));
173 174
	/* Available transports */
174 175
	json_t *t_data = json_object();
175 176
	if(transports && g_hash_table_size(transports) > 0) {
......
331 332
		.relay_data = janus_plugin_relay_data,
332 333
		.close_pc = janus_plugin_close_pc,
333 334
		.end_session = janus_plugin_end_session,
335
		.events_is_enabled = janus_events_is_enabled,
334 336
		.notify_event = janus_plugin_notify_event,
335 337
	}; 
336 338
///@}
......
380 382
					session->source->transport->session_over(session->source->instance, session->session_id, TRUE);
381 383
				}
382 384
				/* Notify event handlers as well */
383
				janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session->session_id, "timeout");
385
				if(janus_events_is_enabled())
386
					janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session->session_id, "timeout");
384 387

  
385 388
				/* Mark the session as over, we'll deal with it later */
386 389
				session->timeout = 1;
......
444 447
	g_hash_table_insert(sessions, GUINT_TO_POINTER(session_id), session);
445 448
	janus_mutex_unlock(&sessions_mutex);
446 449
	/* Notify event handlers */
447
	janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session_id, "created");
450
	if(janus_events_is_enabled())
451
		janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session_id, "created");
448 452
	return session;
449 453
}
450 454

  
......
815 819
		/* Send the success reply */
816 820
		ret = janus_process_success(request, reply);
817 821
		/* Notify event handlers as well */
818
		janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session_id, "destroyed");
822
		if(janus_events_is_enabled())
823
			janus_events_notify_handlers(JANUS_EVENT_TYPE_SESSION, session_id, "destroyed");
819 824
	} else if(!strcasecmp(message_text, "detach")) {
820 825
		if(handle == NULL) {
821 826
			/* Query is an handle-level command */
......
954 959
				goto jsondone;
955 960
			}
956 961
			/* Notify event handlers */
957
			janus_events_notify_handlers(JANUS_EVENT_TYPE_JSEP,
958
				session_id, handle_id, "remote", jsep_type, jsep_sdp);
962
			if(janus_events_is_enabled()) {
963
				janus_events_notify_handlers(JANUS_EVENT_TYPE_JSEP,
964
					session_id, handle_id, "remote", jsep_type, jsep_sdp);
965
			}
959 966
			/* FIXME We're only handling single audio/video lines for now... */
960 967
			JANUS_LOG(LOG_VERB, "[%"SCNu64"] Audio %s been negotiated, Video %s been negotiated, SCTP/DataChannels %s been negotiated\n",
961 968
			                    handle->handle_id,
......
2573 2580
	JANUS_LOG(LOG_VERB, "[%"SCNu64"] Sending event to transport...\n", ice_handle->handle_id);
2574 2581
	janus_session_notify_event(session->session_id, event);
2575 2582

  
2576
	if(jsep != NULL) {
2583
	if(jsep != NULL && janus_events_is_enabled()) {
2577 2584
		/* Notify event handlers as well */
2578 2585
		janus_events_notify_handlers(JANUS_EVENT_TYPE_JSEP,
2579 2586
			session->session_id, ice_handle->handle_id, "local", sdp_type, sdp);
......
2982 2989

  
2983 2990
void janus_plugin_notify_event(janus_plugin_session *plugin_session, json_t *event) {
2984 2991
	/* A plugin asked to notify an event to the handlers */
2992
	if(!event || !json_is_object(event))
2993
		return;
2985 2994
	if((plugin_session < (janus_plugin_session *)0x1000) || !janus_plugin_session_is_alive(plugin_session) || plugin_session->stopped) {
2986
			if(event)
2987
			json_decref(event);
2995
		json_decref(event);
2988 2996
		return;
2989 2997
	}
2990 2998
	janus_ice_handle *ice_handle = (janus_ice_handle *)plugin_session->gateway_handle;
2991 2999
	if(!ice_handle) {
2992
		if(event)
2993
			json_decref(event);
3000
		json_decref(event);
2994 3001
		return;
2995 3002
	}
2996 3003
	janus_session *session = (janus_session *)ice_handle->session;
2997 3004
	if(!session) {
2998
		if(event)
2999
			json_decref(event);
3005
		json_decref(event);
3000 3006
		return;
3001 3007
	}
3002 3008
	janus_plugin *plugin_t = (janus_plugin *)ice_handle->app;
3003 3009
	/* Notify event handlers */
3004
	janus_events_notify_handlers(JANUS_EVENT_TYPE_PLUGIN,
3005
		session->session_id, ice_handle->handle_id, plugin_t->get_package(), event);
3010
	if(janus_events_is_enabled()) {
3011
		janus_events_notify_handlers(JANUS_EVENT_TYPE_PLUGIN,
3012
			session->session_id, ice_handle->handle_id, plugin_t->get_package(), event);
3013
	} else {
3014
		json_decref(event);
3015
	}
3006 3016
}
3007 3017

  
3008 3018

  
......
3642 3652
	} else {
3643 3653
		/* Any event handlers to ignore? */
3644 3654
		gchar **disabled_eventhandlers = NULL;
3645
		item = janus_config_get_item_drilldown(config, "events", "disable");
3655
		item = janus_config_get_item_drilldown(config, "events", "broadcast");
3656
		gboolean enable_events = TRUE;
3646 3657
		if(item && item->value)
3647
			disabled_eventhandlers = g_strsplit(item->value, ",", -1);
3648
		/* Open the shared objects */
3649
		struct dirent *eventent = NULL;
3650
		char eventpath[1024];
3651
		while((eventent = readdir(dir))) {
3652
			int len = strlen(eventent->d_name);
3653
			if (len < 4) {
3654
				continue;
3655
			}
3656
			if (strcasecmp(eventent->d_name+len-strlen(SHLIB_EXT), SHLIB_EXT)) {
3657
				continue;
3658
			}
3659
			/* Check if this event handler has been disabled in the configuration file */
3660
			if(disabled_eventhandlers != NULL) {
3661
				gchar *index = disabled_eventhandlers[0];
3662
				if(index != NULL) {
3663
					int i=0;
3664
					gboolean skip = FALSE;
3665
					while(index != NULL) {
3666
						while(isspace(*index))
3667
							index++;
3668
						if(strlen(index) && !strcmp(index, eventent->d_name)) {
3669
							JANUS_LOG(LOG_WARN, "Event handler plugin '%s' has been disabled, skipping...\n", eventent->d_name);
3670
							skip = TRUE;
3671
							break;
3672
						}
3673
						i++;
3674
						index = disabled_eventhandlers[i];
3675
					}
3676
					if(skip)
3677
						continue;
3678
				}
3679
			}
3680
			JANUS_LOG(LOG_INFO, "Loading event handler plugin '%s'...\n", eventent->d_name);
3681
			memset(eventpath, 0, 1024);
3682
			g_snprintf(eventpath, 1024, "%s/%s", path, eventent->d_name);
3683
			void *event = dlopen(eventpath, RTLD_LAZY);
3684
			if (!event) {
3685
				JANUS_LOG(LOG_ERR, "\tCouldn't load event handler plugin '%s': %s\n", eventent->d_name, dlerror());
3686
			} else {
3687
				create_e *create = (create_e*) dlsym(event, "create");
3688
				const char *dlsym_error = dlerror();
3689
				if (dlsym_error) {
3690
					JANUS_LOG(LOG_ERR, "\tCouldn't load symbol 'create': %s\n", dlsym_error);
3691
					continue;
3692
				}
3693
				janus_eventhandler *janus_eventhandler = create();
3694
				if(!janus_eventhandler) {
3695
					JANUS_LOG(LOG_ERR, "\tCouldn't use function 'create'...\n");
3658
			enable_events = janus_is_true(item->value);
3659
		if(!enable_events) {
3660
			JANUS_LOG(LOG_WARN, "Event handlers support disabled\n");
3661
		} else {
3662
			item = janus_config_get_item_drilldown(config, "events", "disable");
3663
			if(item && item->value)
3664
				disabled_eventhandlers = g_strsplit(item->value, ",", -1);
3665
			/* Open the shared objects */
3666
			struct dirent *eventent = NULL;
3667
			char eventpath[1024];
3668
			while((eventent = readdir(dir))) {
3669
				int len = strlen(eventent->d_name);
3670
				if (len < 4) {
3696 3671
					continue;
3697 3672
				}
3698
				/* Are all the mandatory methods and callbacks implemented? */
3699
				if(!janus_eventhandler->init || !janus_eventhandler->destroy ||
3700
						!janus_eventhandler->get_api_compatibility ||
3701
						!janus_eventhandler->get_version ||
3702
						!janus_eventhandler->get_version_string ||
3703
						!janus_eventhandler->get_description ||
3704
						!janus_eventhandler->get_package ||
3705
						!janus_eventhandler->get_name ||
3706
						!janus_eventhandler->incoming_event) {
3707
					JANUS_LOG(LOG_ERR, "\tMissing some mandatory methods/callbacks, skipping this event handler plugin...\n");
3673
				if (strcasecmp(eventent->d_name+len-strlen(SHLIB_EXT), SHLIB_EXT)) {
3708 3674
					continue;
3709 3675
				}
3710
				if(janus_eventhandler->get_api_compatibility() < JANUS_EVENTHANDLER_API_VERSION) {
3711
					JANUS_LOG(LOG_ERR, "The '%s' event handler plugin was compiled against an older version of the API (%d < %d), skipping it: update it to enable it again\n",
3712
						janus_eventhandler->get_package(), janus_eventhandler->get_api_compatibility(), JANUS_EVENTHANDLER_API_VERSION);
3713
					continue;
3676
				/* Check if this event handler has been disabled in the configuration file */
3677
				if(disabled_eventhandlers != NULL) {
3678
					gchar *index = disabled_eventhandlers[0];
3679
					if(index != NULL) {
3680
						int i=0;
3681
						gboolean skip = FALSE;
3682
						while(index != NULL) {
3683
							while(isspace(*index))
3684
								index++;
3685
							if(strlen(index) && !strcmp(index, eventent->d_name)) {
3686
								JANUS_LOG(LOG_WARN, "Event handler plugin '%s' has been disabled, skipping...\n", eventent->d_name);
3687
								skip = TRUE;
3688
								break;
3689
							}
3690
							i++;
3691
							index = disabled_eventhandlers[i];
3692
						}
3693
						if(skip)
3694
							continue;
3695
					}
3714 3696
				}
3715
				janus_eventhandler->init(configs_folder);
3716
				JANUS_LOG(LOG_VERB, "\tVersion: %d (%s)\n", janus_eventhandler->get_version(), janus_eventhandler->get_version_string());
3717
				JANUS_LOG(LOG_VERB, "\t   [%s] %s\n", janus_eventhandler->get_package(), janus_eventhandler->get_name());
3718
				JANUS_LOG(LOG_VERB, "\t   %s\n", janus_eventhandler->get_description());
3719
				JANUS_LOG(LOG_VERB, "\t   Plugin API version: %d\n", janus_eventhandler->get_api_compatibility());
3720
				JANUS_LOG(LOG_VERB, "\t   Subscriptions:");
3721
				if(janus_eventhandler->events_mask == 0) {
3722
					JANUS_LOG(LOG_VERB, " none");
3697
				JANUS_LOG(LOG_INFO, "Loading event handler plugin '%s'...\n", eventent->d_name);
3698
				memset(eventpath, 0, 1024);
3699
				g_snprintf(eventpath, 1024, "%s/%s", path, eventent->d_name);
3700
				void *event = dlopen(eventpath, RTLD_LAZY);
3701
				if (!event) {
3702
					JANUS_LOG(LOG_ERR, "\tCouldn't load event handler plugin '%s': %s\n", eventent->d_name, dlerror());
3723 3703
				} else {
3724
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_SESSION))
3725
						JANUS_LOG(LOG_VERB, " sessions");
3726
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_HANDLE))
3727
						JANUS_LOG(LOG_VERB, " handles");
3728
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_JSEP))
3729
						JANUS_LOG(LOG_VERB, " jsep");
3730
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_WEBRTC))
3731
						JANUS_LOG(LOG_VERB, " webrtc");
3732
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_MEDIA))
3733
						JANUS_LOG(LOG_VERB, " media");
3734
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_PLUGIN))
3735
						JANUS_LOG(LOG_VERB, " plugins");
3736
					if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_TRANSPORT))
3737
						JANUS_LOG(LOG_VERB, " transports");
3704
					create_e *create = (create_e*) dlsym(event, "create");
3705
					const char *dlsym_error = dlerror();
3706
					if (dlsym_error) {
3707
						JANUS_LOG(LOG_ERR, "\tCouldn't load symbol 'create': %s\n", dlsym_error);
3708
						continue;
3709
					}
3710
					janus_eventhandler *janus_eventhandler = create();
3711
					if(!janus_eventhandler) {
3712
						JANUS_LOG(LOG_ERR, "\tCouldn't use function 'create'...\n");
3713
						continue;
3714
					}
3715
					/* Are all the mandatory methods and callbacks implemented? */
3716
					if(!janus_eventhandler->init || !janus_eventhandler->destroy ||
3717
							!janus_eventhandler->get_api_compatibility ||
3718
							!janus_eventhandler->get_version ||
3719
							!janus_eventhandler->get_version_string ||
3720
							!janus_eventhandler->get_description ||
3721
							!janus_eventhandler->get_package ||
3722
							!janus_eventhandler->get_name ||
3723
							!janus_eventhandler->incoming_event) {
3724
						JANUS_LOG(LOG_ERR, "\tMissing some mandatory methods/callbacks, skipping this event handler plugin...\n");
3725
						continue;
3726
					}
3727
					if(janus_eventhandler->get_api_compatibility() < JANUS_EVENTHANDLER_API_VERSION) {
3728
						JANUS_LOG(LOG_ERR, "The '%s' event handler plugin was compiled against an older version of the API (%d < %d), skipping it: update it to enable it again\n",
3729
							janus_eventhandler->get_package(), janus_eventhandler->get_api_compatibility(), JANUS_EVENTHANDLER_API_VERSION);
3730
						continue;
3731
					}
3732
					janus_eventhandler->init(configs_folder);
3733
					JANUS_LOG(LOG_VERB, "\tVersion: %d (%s)\n", janus_eventhandler->get_version(), janus_eventhandler->get_version_string());
3734
					JANUS_LOG(LOG_VERB, "\t   [%s] %s\n", janus_eventhandler->get_package(), janus_eventhandler->get_name());
3735
					JANUS_LOG(LOG_VERB, "\t   %s\n", janus_eventhandler->get_description());
3736
					JANUS_LOG(LOG_VERB, "\t   Plugin API version: %d\n", janus_eventhandler->get_api_compatibility());
3737
					JANUS_LOG(LOG_VERB, "\t   Subscriptions:");
3738
					if(janus_eventhandler->events_mask == 0) {
3739
						JANUS_LOG(LOG_VERB, " none");
3740
					} else {
3741
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_SESSION))
3742
							JANUS_LOG(LOG_VERB, " sessions");
3743
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_HANDLE))
3744
							JANUS_LOG(LOG_VERB, " handles");
3745
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_JSEP))
3746
							JANUS_LOG(LOG_VERB, " jsep");
3747
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_WEBRTC))
3748
							JANUS_LOG(LOG_VERB, " webrtc");
3749
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_MEDIA))
3750
							JANUS_LOG(LOG_VERB, " media");
3751
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_PLUGIN))
3752
							JANUS_LOG(LOG_VERB, " plugins");
3753
						if(janus_flags_is_set(&janus_eventhandler->events_mask, JANUS_EVENT_TYPE_TRANSPORT))
3754
							JANUS_LOG(LOG_VERB, " transports");
3755
					}
3756
					JANUS_LOG(LOG_VERB, "\n");
3757
					if(eventhandlers == NULL)
3758
						eventhandlers = g_hash_table_new(g_str_hash, g_str_equal);
3759
					g_hash_table_insert(eventhandlers, (gpointer)janus_eventhandler->get_package(), janus_eventhandler);
3760
					if(eventhandlers_so == NULL)
3761
						eventhandlers_so = g_hash_table_new(g_str_hash, g_str_equal);
3762
					g_hash_table_insert(eventhandlers_so, (gpointer)janus_eventhandler->get_package(), event);
3738 3763
				}
3739
				JANUS_LOG(LOG_VERB, "\n");
3740
				if(eventhandlers == NULL)
3741
					eventhandlers = g_hash_table_new(g_str_hash, g_str_equal);
3742
				g_hash_table_insert(eventhandlers, (gpointer)janus_eventhandler->get_package(), janus_eventhandler);
3743
				if(eventhandlers_so == NULL)
3744
					eventhandlers_so = g_hash_table_new(g_str_hash, g_str_equal);
3745
				g_hash_table_insert(eventhandlers_so, (gpointer)janus_eventhandler->get_package(), event);
3746 3764
			}
3747 3765
		}
3748 3766
		closedir(dir);
......
3750 3768
			g_strfreev(disabled_eventhandlers);
3751 3769
		disabled_eventhandlers = NULL;
3752 3770
		/* Initialize the event broadcaster */
3753
		janus_events_init(eventhandlers);
3771
		janus_events_init(enable_events, eventhandlers);
3754 3772
	}
3755 3773

  
3756 3774
	/* Load plugins */

Also available in: Unified diff