Revision 1d31e31f

View differences:

conf/janus.cfg.sample.in
165 165
; not. Use the 'disable' directive to prevent Janus from loading one
166 166
; or more event handlers: use a comma separated list of file names
167 167
; to identify the event handlers to disable. By default all available
168
; event handlers are enabled and loaded at startup.
168
; event handlers are enabled and loaded at startup. If you want to
169
; completely disable the broadcasting of events to any event handler,
170
; set broadcast to no.
169 171
[events]
172
; broadcast = no
170 173
; disable = libjanus_sampleevh.so
dtls.c
87 87

  
88 88
/* Helper to notify DTLS state changes to the event handlers */
89 89
static void janus_dtls_notify_state_change(janus_dtls_srtp *dtls) {
90
	if(janus_events_is_enabled())
91
		return;
90 92
	if(dtls == NULL)
91 93
		return;
92 94
	janus_ice_component *component = (janus_ice_component *)dtls->component;
events.c
15 15
#include "events.h"
16 16
#include "utils.h"
17 17

  
18
static gboolean eventsenabled = FALSE;
18 19
static GHashTable *eventhandlers = NULL;
19
void janus_events_init(GHashTable *handlers) {
20
void janus_events_init(gboolean enabled, GHashTable *handlers) {
21
	eventsenabled = enabled;
20 22
	eventhandlers = handlers;
21 23
}
22 24

  
25
gboolean janus_events_is_enabled(void) {
26
	return eventsenabled;
27
}
28

  
23 29
void janus_events_notify_handlers(int type, guint64 session_id, ...) {
24
	if(eventhandlers == NULL || g_hash_table_size(eventhandlers) == 0)
30
	if(!eventsenabled || eventhandlers == NULL || g_hash_table_size(eventhandlers) == 0)
25 31
		return;
26 32

  
27 33
	/* Prepare the event to notify as a Jansson json_t object */
events.h
17 17
#include "events/eventhandler.h"
18 18

  
19 19
/*! \brief Initialize the event handlers broadcaster
20
 * @param[in] eventhandlers Map of all registered event handlers */
21
void janus_events_init(GHashTable *eventhandlers);
20
 * @param[in] enabled Whether broadcasting events should be supported at all
21
 * @param[in] handlers Map of all registered event handlers */
22
void janus_events_init(gboolean enabled, GHashTable *handlers);
23

  
24
/*! \brief Quick method to check whether event handlers are enabled at all or not
25
 * @returns TRUE if they're enabled, FALSE if not */
26
gboolean janus_events_is_enabled(void);
22 27

  
23 28
/*! \brief Notify an event to all interested handlers
24 29
 * @note According to the type of event to notify, different arguments may
ice.c
450 450
	JANUS_LOG(LOG_VERB, "[%"SCNu64"] Sending event to transport...\n", handle->handle_id);
451 451
	janus_session_notify_event(session->session_id, event);
452 452
	/* Notify event handlers as well */
453
	json_t *info = json_object();
454
	json_object_set_new(info, "media", json_string(video ? "video" : "audio"));
455
	json_object_set_new(info, "receiving", json_string(up ? "true" : "false"));
456
	janus_events_notify_handlers(JANUS_EVENT_TYPE_MEDIA, session->session_id, handle->handle_id, info);
453
	if(janus_events_is_enabled()) {
454
		json_t *info = json_object();
455
		json_object_set_new(info, "media", json_string(video ? "video" : "audio"));
456
		json_object_set_new(info, "receiving", json_string(up ? "true" : "false"));
457
		janus_events_notify_handlers(JANUS_EVENT_TYPE_MEDIA, session->session_id, handle->handle_id, info);
458
	}
457 459
}
458 460

  
459 461
void janus_ice_notify_hangup(janus_ice_handle *handle, const char *reason) {
......
474 476
	JANUS_LOG(LOG_VERB, "[%"SCNu64"] Sending event to transport...\n", handle->handle_id);
475 477
	janus_session_notify_event(session->session_id, event);
476 478
	/* Notify event handlers as well */
477
	json_t *info = json_object();
478
	json_object_set_new(info, "connection", json_string("hangup"));
479
	janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
479
	if(janus_events_is_enabled()) {
480
		json_t *info = json_object();
481
		json_object_set_new(info, "connection", json_string("hangup"));
482
		janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
483
	}
480 484
}
481 485

  
482 486

  
......
965 969
	janus_mutex_unlock(&old_plugin_sessions_mutex);
966 970
	janus_mutex_unlock(&session->mutex);
967 971
	/* Notify event handlers */
968
	janus_events_notify_handlers(JANUS_EVENT_TYPE_HANDLE, session->session_id, handle_id, "attached");
972
	if(janus_events_is_enabled())
973
		janus_events_notify_handlers(JANUS_EVENT_TYPE_HANDLE, session->session_id, handle_id, "attached");
969 974
	return 0;
970 975
}
971 976

  
......
1019 1024
	g_hash_table_insert(old_handles, GUINT_TO_POINTER(handle_id), handle);
1020 1025
	janus_mutex_unlock(&old_handles_mutex);
1021 1026
	/* Notify event handlers as well */
1022
	janus_events_notify_handlers(JANUS_EVENT_TYPE_HANDLE, session->session_id, handle_id, "detached");
1027
	if(janus_events_is_enabled())
1028
		janus_events_notify_handlers(JANUS_EVENT_TYPE_HANDLE, session->session_id, handle_id, "detached");
1023 1029
	return error;
1024 1030
}
1025 1031

  
......
1338 1344
	}
1339 1345
	component->state = state;
1340 1346
	/* Notify event handlers */
1341
	janus_session *session = (janus_session *)handle->session;
1342
	json_t *info = json_object();
1343
	json_object_set_new(info, "ice", json_string(janus_get_ice_state_name(state)));
1344
	json_object_set_new(info, "stream_id", json_integer(stream_id));
1345
	json_object_set_new(info, "component_id", json_integer(component_id));
1346
	janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
1347
	if(janus_events_is_enabled()) {
1348
		janus_session *session = (janus_session *)handle->session;
1349
		json_t *info = json_object();
1350
		json_object_set_new(info, "ice", json_string(janus_get_ice_state_name(state)));
1351
		json_object_set_new(info, "stream_id", json_integer(stream_id));
1352
		json_object_set_new(info, "component_id", json_integer(component_id));
1353
		janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
1354
	}
1347 1355
	/* Handle new state */
1348 1356
	if((state == NICE_COMPONENT_STATE_CONNECTED || state == NICE_COMPONENT_STATE_READY)
1349 1357
			&& handle->send_thread == NULL) {
......
1469 1477
#endif
1470 1478
	component->selected_pair = g_strdup(sp);
1471 1479
	/* Notify event handlers */
1472
	janus_session *session = (janus_session *)handle->session;
1473
	json_t *info = json_object();
1474
	json_object_set_new(info, "selected-pair", json_string(sp));
1475
	json_object_set_new(info, "stream_id", json_integer(stream_id));
1476
	json_object_set_new(info, "component_id", json_integer(component_id));
1477
	janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
1480
	if(janus_events_is_enabled()) {
1481
		janus_session *session = (janus_session *)handle->session;
1482
		json_t *info = json_object();
1483
		json_object_set_new(info, "selected-pair", json_string(sp));
1484
		json_object_set_new(info, "stream_id", json_integer(stream_id));
1485
		json_object_set_new(info, "component_id", json_integer(component_id));
1486
		janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
1487
	}
1478 1488
	/* Now we can start the DTLS handshake (FIXME This was on the 'connected' state notification, before) */
1479 1489
	JANUS_LOG(LOG_VERB, "[%"SCNu64"]   Component is ready enough, starting DTLS handshake...\n", handle->handle_id);
1480 1490
	/* Have we been here before? (might happen, when trickling) */
......
3606 3616
	JANUS_LOG(LOG_VERB, "[%"SCNu64"] Sending event to transport...\n", handle->handle_id);
3607 3617
	janus_session_notify_event(session->session_id, event);
3608 3618
	/* Notify event handlers as well */
3609
	json_t *info = json_object();
3610
	json_object_set_new(info, "connection", json_string("webrtcup"));
3611
	janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
3619
	if(janus_events_is_enabled()) {
3620
		json_t *info = json_object();
3621
		json_object_set_new(info, "connection", json_string("webrtcup"));
3622
		janus_events_notify_handlers(JANUS_EVENT_TYPE_WEBRTC, session->session_id, handle->handle_id, info);
3623
	}
3612 3624
}
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 */
plugins/janus_echotest.c
910 910
		g_free(event_text);
911 911
		janus_echotest_message_free(msg);
912 912

  
913
		/* Just to showcase how you can notify handlers, let's update them on our configuration */
914
		json_t *info = json_object();
915
		json_object_set_new(info, "audio_active", json_string(session->audio_active ? "true" : "false"));
916
		json_object_set_new(info, "video_active", json_string(session->video_active ? "true" : "false"));
917
		json_object_set_new(info, "bitrate", json_integer(session->bitrate));
918
		if(session->arc || session->vrc) {
919
			json_t *recording = json_object();
920
			if(session->arc && session->arc->filename)
921
				json_object_set_new(recording, "audio", json_string(session->arc->filename));
922
			if(session->vrc && session->vrc->filename)
923
				json_object_set_new(recording, "video", json_string(session->vrc->filename));
924
			json_object_set_new(info, "recording", recording);
925
		}
926
		gateway->notify_event(session->handle, info);
913
		//~ if(gateway->events_is_enabled()) {
914
			/* Just to showcase how you can notify handlers, let's update them on our configuration */
915
			json_t *info = json_object();
916
			json_object_set_new(info, "audio_active", json_string(session->audio_active ? "true" : "false"));
917
			json_object_set_new(info, "video_active", json_string(session->video_active ? "true" : "false"));
918
			json_object_set_new(info, "bitrate", json_integer(session->bitrate));
919
			if(session->arc || session->vrc) {
920
				json_t *recording = json_object();
921
				if(session->arc && session->arc->filename)
922
					json_object_set_new(recording, "audio", json_string(session->arc->filename));
923
				if(session->vrc && session->vrc->filename)
924
					json_object_set_new(recording, "video", json_string(session->vrc->filename));
925
				json_object_set_new(info, "recording", recording);
926
			}
927
			gateway->notify_event(session->handle, info);
928
		//~ }
927 929

  
928 930
		/* Done, on to the next request */
929 931
		continue;
plugins/plugin.h
154 154
#include <unistd.h>
155 155
#include <inttypes.h>
156 156

  
157
#include <glib.h>
157 158
#include <jansson.h>
158 159

  
159 160

  
......
364 365
	 * @param[in] handle The plugin/gateway session to get rid of */
365 366
	void (* const end_session)(janus_plugin_session *handle);
366 367

  
368
	/*! \brief Callback to check whether the event handlers mechanism is enabled
369
	 * @returns TRUE if it is, FALSE if it isn't (which means notify_event should NOT be called) */
370
	gboolean (* const events_is_enabled)(void);
367 371
	/*! \brief Callback to notify an event to the registered and subscribed event handlers
368 372
	 * \note Don't unref the event object, the core will do that for you
369 373
	 * @param[in] handle The plugin/gateway session originating the event

Also available in: Unified diff