Revision 84c1291c

View differences:

conf/janus.eventhandler.sampleevh.cfg.sample
7 7
enabled = no	; By default the module is not enabled
8 8
events = all	; Comma separated list of the events mask you're interested
9 9
				; in. Valid values are none, sessions, handles, jsep, webrtc,
10
				; media, plugins, transports and all. By default we
10
				; media, plugins, transports, core and all. By default we
11 11
				; subscribe to everything (all)
12 12
grouping = no	; Whether events should be sent individually (one per
13 13
				; HTTP POST, JSON object), or if it's ok to group them
events.c
60 60
	json_t *event = json_object();
61 61
	json_object_set_new(event, "type", json_integer(type));
62 62
	json_object_set_new(event, "timestamp", json_integer(janus_get_monotonic_time()));
63
	json_object_set_new(event, "session_id", json_integer(session_id));
63
	if(type != JANUS_EVENT_TYPE_CORE)	/* Core events don't have a session ID */
64
		json_object_set_new(event, "session_id", json_integer(session_id));
64 65
	json_t *body = NULL;
65
	if(type != JANUS_EVENT_TYPE_WEBRTC)
66
	if(type != JANUS_EVENT_TYPE_WEBRTC && type != JANUS_EVENT_TYPE_CORE)
66 67
		body = json_object();
67 68

  
68 69
	/* Each type may require different arguments */
......
120 121
			json_object_set(body, "data", data);
121 122
			break;
122 123
		}
124
		case JANUS_EVENT_TYPE_CORE: {
125
			/* For core-related events, there's a json_t object with info on what happened */
126
			body = va_arg(args, json_t *);
127
			break;
128
		}
123 129
		default:
124 130
			JANUS_LOG(LOG_WARN, "Unknown event type '%d'\n", type);
125 131
			json_decref(event);
events/eventhandler.h
141 141
#define JANUS_EVENT_TYPE_PLUGIN			(1 << 6)
142 142
/*! \brief Events originated by transports (at the moment, all of them, no way to pick) */
143 143
#define JANUS_EVENT_TYPE_TRANSPORT		(1 << 7)
144
/*! \brief Events originated by the core for its own events (e.g., Janus starting/shutting down) */
145
#define JANUS_EVENT_TYPE_CORE			(1 << 8)
144 146
	/* TODO Others? */
145 147
/*! \brief Mask with all events enabled (shortcut when you want to subscribe to everything) */
146 148
#define JANUS_EVENT_TYPE_ALL		(0xffffffff)
events/janus_sampleevh.c
161 161
											janus_flags_set(&janus_sampleevh.events_mask, JANUS_EVENT_TYPE_PLUGIN);
162 162
										} else if(!strcasecmp(index, "transports")) {
163 163
											janus_flags_set(&janus_sampleevh.events_mask, JANUS_EVENT_TYPE_TRANSPORT);
164
										} else if(!strcasecmp(index, "core")) {
165
											janus_flags_set(&janus_sampleevh.events_mask, JANUS_EVENT_TYPE_CORE);
164 166
										} else {
165 167
											JANUS_LOG(LOG_WARN, "Unknown event type '%s'\n", index);
166 168
										}
......
465 467
					 * above, with a "transport" property instead of "plugin"
466 468
					 * to contain the transport package name. */
467 469
					break;
470
				case JANUS_EVENT_TYPE_CORE:
471
					/* This is a core related event. This can contain different
472
					 * information about the health of the Janus instance, or
473
					 * more generically on some events in the Janus life cycle
474
					 * (e.g., when it's just been started or when a shutdown
475
					 * has been requested). Considering the heterogeneous nature
476
					 * of the information being reported, the content is always
477
					 * a JSON object (event). Core events are the only ones
478
					 * missing a session_id. Here's an example:
479
						{
480
						   "type": 256,
481
						   "timestamp": 28381185382,
482
						   "event": {
483
							  "status": "started"
484
						   }
485
						}
486
					*/
487
					break;
468 488
				default:
469 489
					JANUS_LOG(LOG_WARN, "Unknown type of event '%d'\n", type);
470 490
					break;
janus.c
144 144
	public_ip = g_strdup(ip);
145 145
}
146 146
static volatile gint stop = 0;
147
static gint stop_signal = 0;
147 148
gint janus_is_stopping(void) {
148 149
	return g_atomic_int_get(&stop);
149 150
}
......
270 271

  
271 272
/*! \brief Signal handler (just used to intercept CTRL+C and SIGTERM) */
272 273
static void janus_handle_signal(int signum) {
274
	stop_signal = signum;
273 275
	switch(g_atomic_int_get(&stop)) {
274 276
		case 0:
275 277
			JANUS_PRINT("Stopping gateway, please wait...\n");
......
4043 4045
		} while(res == -1 && errno == EINTR);
4044 4046
	}
4045 4047

  
4048
	/* If the Event Handlers mechanism is enabled, notify handlers that Janus just started */
4049
	if(janus_events_is_enabled()) {
4050
		json_t *info = json_object();
4051
		json_object_set_new(info, "status", json_string("started"));
4052
		janus_events_notify_handlers(JANUS_EVENT_TYPE_CORE, 0, info);
4053
	}
4054

  
4046 4055
	while(!g_atomic_int_get(&stop)) {
4047 4056
		/* Loop until we have to stop */
4048 4057
		usleep(250000); /* A signal will cancel usleep() but not g_usleep() */
4049 4058
	}
4050 4059

  
4060
	/* If the Event Handlers mechanism is enabled, notify handlers that Janus is hanging up */
4061
	if(janus_events_is_enabled()) {
4062
		json_t *info = json_object();
4063
		json_object_set_new(info, "status", json_string("shutdown"));
4064
		json_object_set_new(info, "signum", json_integer(stop_signal));
4065
		janus_events_notify_handlers(JANUS_EVENT_TYPE_CORE, 0, info);
4066
	}
4067

  
4051 4068
	/* Done */
4052 4069
	JANUS_LOG(LOG_INFO, "Ending watchdog mainloop...\n");
4053 4070
	g_main_loop_quit(watchdog_loop);

Also available in: Unified diff