[Asterisk-code-review] app confbridge: Enable sending events to participants (asterisk[15])

George Joseph asteriskteam at digium.com
Mon Jun 4 15:37:58 CDT 2018


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/9085


Change subject: app_confbridge:  Enable sending events to participants
......................................................................

app_confbridge:  Enable sending events to participants

ConfBridge can now send events to participants via in-dialog MESSAGEs.
All current Confbridge events are supported, such as ConfbridgeJoin,
ConfbridgeLeave, etc.  In addition to those events, a new event
ConfbridgeWelcome has been added that will send a list of all
current participants to a new participant.

For all but the ConfbridgeWelcome event, the JSON message contains
information about the bridge, such as its id and name, and information
about the channel that triggered the event such as channel name,
callerid info, mute status, and the MSID labels for their audio and
video tracks. You can use the labels to correlate callerid and mute
status to specific video elements in a webrtc client.

To control this behavior, the following options have been added to
confbridge.conf:

bridge_profile/enable_events:  This must be enabled on any bridge where
events are desired.

user_profile/send_events:  This must be set for a user profile to send
events.  Different user profiles connected to the same bridge can have
different settings.  This allows admins to get events but not normal
users for instance.

user_profile/echo_events:  In some cases, you might not want the user
triggering the event to get the event sent back to them.  To prevent it,
set this to false.

Change-Id: I26420aa9f101f0b2387dc9e2fd10733197f1318e
---
M CHANGES
M apps/app_confbridge.c
M apps/confbridge/conf_config_parser.c
M apps/confbridge/confbridge_manager.c
M apps/confbridge/include/confbridge.h
M configs/samples/confbridge.conf.sample
M res/res_pjsip_sdp_rtp.c
7 files changed, 439 insertions(+), 21 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/85/9085/1

diff --git a/CHANGES b/CHANGES
index 8e460a4..945bc86 100644
--- a/CHANGES
+++ b/CHANGES
@@ -28,6 +28,14 @@
     Content-Type of a message.  Since you can now set Content-Type, other
     text/* content types are now valid.
 
+app_confbridge
+------------------
+    ConfBridge can now send events to participants via in-dialog MESSAGEs.
+    All current Confbridge events are supported, such as ConfbridgeJoin,
+    ConfbridgeLeave, etc.  In addition to those events, a new event
+    ConfbridgeWelcome has been added that will send a list of all
+    current participants to a new participant.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 15.3.0 to Asterisk 15.4.0 ------------
 ------------------------------------------------------------------------------
diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index f3f0fdf..434bd5b 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -71,6 +71,8 @@
 #include "asterisk/json.h"
 #include "asterisk/format_cache.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/stream.h"
+#include "asterisk/message.h"
 
 /*** DOCUMENTATION
 	<application name="ConfBridge" language="en_US">
@@ -540,6 +542,274 @@
 	return "";
 }
 
+
+static struct ast_json *channel_to_json(struct ast_channel_snapshot *channel_snapshot,
+	struct ast_json *conf_blob, struct ast_json *labels_blob)
+{
+	struct ast_json *json_channel = ast_channel_snapshot_to_json(channel_snapshot, NULL);
+
+	if (!json_channel) {
+		return NULL;
+	}
+
+	ast_json_object_del(json_channel, "dialplan");
+	ast_json_object_del(json_channel, "connected");
+	ast_json_object_del(json_channel, "accountcode");
+	if (conf_blob) {
+		struct ast_json *conf_copy = ast_json_copy(conf_blob);
+
+		if (!conf_copy) {
+			ast_json_unref(json_channel);
+			return NULL;
+		}
+		ast_json_object_del(conf_copy, "conference");
+		ast_json_object_update(json_channel, conf_copy);
+		ast_json_unref(conf_copy);
+	}
+	if (labels_blob) {
+		ast_json_object_update(json_channel, labels_blob);
+	}
+
+	return json_channel;
+}
+
+static struct ast_json *bridge_to_json(struct ast_bridge_snapshot *bridge_snapshot)
+{
+	struct ast_json *json_bridge = ast_bridge_snapshot_to_json(bridge_snapshot, NULL);
+
+	if (!json_bridge) {
+		return NULL;
+	}
+
+	ast_json_object_del(json_bridge, "technology");
+	ast_json_object_del(json_bridge, "bridge_type");
+	ast_json_object_del(json_bridge, "bridge_class");
+	ast_json_object_del(json_bridge, "creator");
+	ast_json_object_del(json_bridge, "channels");
+
+	return json_bridge;
+}
+
+static struct ast_json *pack_bridge_and_channels(
+	struct ast_json *json_bridge, struct ast_json *json_channels,
+	struct stasis_message * msg)
+{
+	const struct timeval *tv = stasis_message_timestamp(msg);
+	const char *msg_name = confbridge_event_type_to_string(stasis_message_type(msg));
+	const char *fmt = ast_json_typeof(json_channels) == AST_JSON_ARRAY ?
+		"{s: s, s: o, s: o, s: o }" : "{s: s, s: o, s: o, s: [ o ] }";
+
+	return ast_json_pack(fmt,
+		"type", msg_name,
+		"timestamp", ast_json_timeval(*tv, NULL),
+		"bridge", json_bridge,
+		"channels", json_channels);
+}
+
+static struct ast_json *pack_snapshots(	struct ast_bridge_snapshot *bridge_snapshot,
+	struct ast_channel_snapshot *channel_snapshot, 	struct ast_json *conf_blob,
+	struct ast_json *labels_blob, struct stasis_message * msg)
+{
+	struct ast_json *json_bridge;
+	struct ast_json *json_channel;
+
+	json_bridge = bridge_to_json(bridge_snapshot);
+	json_channel = channel_to_json(channel_snapshot, conf_blob, labels_blob);
+
+	return pack_bridge_and_channels(json_bridge, json_channel, msg);
+}
+
+enum label_direction {
+	LABEL_DIRECTION_SRC,
+	LABEL_DIRECTION_DEST,
+};
+
+static struct ast_json *get_media_labels(struct confbridge_conference *conference,
+	struct ast_channel *src_chan, struct ast_channel *dest_chan, enum label_direction dir)
+{
+	struct ast_stream_topology *topology;
+	struct ast_stream *stream;
+	const char *curr_a_label;
+	const char *a_label = NULL;
+	const char *v_label = NULL;
+
+	topology = ast_channel_get_stream_topology(dir == LABEL_DIRECTION_SRC ? src_chan : dest_chan);
+	stream = ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_AUDIO);
+	curr_a_label = stream ? ast_stream_get_metadata(stream, "MSID:LABEL") : NULL;
+	a_label = curr_a_label ?: conference->bridge->uniqueid;
+
+	topology = ast_channel_get_stream_topology(dir == LABEL_DIRECTION_SRC ? dest_chan : src_chan);
+	stream = ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_VIDEO);
+	v_label = stream ? ast_stream_get_metadata(stream, "MSID:LABEL") : NULL;
+
+	return ast_json_pack("{s: [ s*, s* ] }", "media_source_track_labels",
+		a_label, v_label);
+}
+
+static void send_message(char *conf_name, struct ast_json *json_object,
+	struct ast_channel *chan)
+{
+	struct ast_msg_data *data_msg;
+	struct ast_msg_data_attribute attrs[] = {
+		{ .type = AST_MSG_DATA_ATTR_FROM, conf_name },
+		{ .type = AST_MSG_DATA_ATTR_CONTENT_TYPE, .value = "application/x-asterisk-confbridge-event+json"},
+		{ .type = AST_MSG_DATA_ATTR_BODY, },
+	};
+	char *msg_name = ast_strdupa(ast_json_string_get(ast_json_object_get(json_object, "type")));
+	char *json = ast_json_dump_string_format(json_object, AST_JSON_PRETTY);
+	int rc = 0;
+
+	ast_json_unref(json_object);
+	if (!json) {
+		ast_log(LOG_ERROR, "Unable to convert json_object for %s message to string\n", msg_name);
+		return;
+	}
+	attrs[2].value = json;
+
+	data_msg = ast_msg_data_alloc(AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, attrs, ARRAY_LEN(attrs));
+	if (!data_msg) {
+		ast_log(LOG_ERROR, "Unable to create %s message for channel '%s'\n", msg_name,
+			ast_channel_name(chan));
+		ast_json_free(json);
+		return;
+	}
+
+	rc = ast_sendtext_data(chan, data_msg);
+	ast_free(data_msg);
+	if (rc != 0) {
+		/* Don't complain if we can't send a leave message. The channel is probably gone. */
+		if (strcmp(confbridge_event_type_to_string(confbridge_leave_type()), msg_name) != 0) {
+			ast_log(LOG_ERROR, "Failed to queue %s message to '%s'\n%s\n", msg_name,
+				ast_channel_name(chan), json);
+		}
+		ast_json_free(json);
+		return;
+	}
+
+	ast_debug(3, "Queued %s message to '%s'\n%s\n", msg_name, ast_channel_name(chan), json);
+	ast_json_free(json);
+}
+
+static void send_event_to_participants(struct confbridge_conference *conference,
+	struct ast_channel *chan, struct stasis_message * msg)
+{
+	struct ast_bridge_blob *obj = stasis_message_data(msg);
+	struct ast_json *extras = obj->blob;
+	struct user_profile u_profile = {0};
+	int source_send_events = 0;
+	int source_echo_events = 0;
+	struct ast_json* json_channels = NULL;
+	struct confbridge_user *user;
+	const char *msg_name = confbridge_event_type_to_string(stasis_message_type(msg));
+
+	ast_debug(3, "Distributing %s event to participants\n", msg_name);
+
+	/* This could be a channel level event or a bridge level event */
+	if (chan) {
+		if (!conf_find_user_profile(chan, NULL, &u_profile)) {
+			ast_log(LOG_ERROR, "Unable to retrieve user profile for channel '%s'\n",
+				ast_channel_name(chan));
+			return;
+		}
+		source_send_events = ast_test_flag(&u_profile, USER_OPT_SEND_EVENTS);
+		source_echo_events = ast_test_flag(&u_profile, USER_OPT_ECHO_EVENTS);
+		ast_debug(3, "send_events: %d  echo_events: %d for profile %s\n",
+			source_send_events, source_echo_events, u_profile.name);
+	}
+
+	/* Now send a message to the participants with the json string. */
+	ao2_lock(conference);
+	AST_LIST_TRAVERSE(&conference->active_list, user, list) {
+		struct ast_json *json_object;
+		struct ast_json* source_json_labels = NULL;
+
+		/*
+		 * If the msg type is join, we need to capture all targets channel info so we can
+		 * send a welcome message to the source channel with all current participants.
+		 */
+		if (source_send_events && stasis_message_type(msg) == confbridge_join_type()) {
+			struct ast_channel_snapshot *target_snapshot;
+			struct ast_json *target_json_channel;
+			struct ast_json *target_json_labels;
+
+			target_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(user->chan));
+			if (!target_snapshot) {
+				ast_log(LOG_ERROR, "Unable to get a channel snapshot for '%s'\n",
+					ast_channel_name(user->chan));
+				continue;
+			}
+
+			target_json_labels = get_media_labels(conference, chan, user->chan, LABEL_DIRECTION_SRC);
+			target_json_channel = channel_to_json(target_snapshot, extras, target_json_labels);
+			ao2_ref(target_snapshot, -1);
+			ast_json_unref(target_json_labels);
+
+			if (!json_channels) {
+				json_channels = ast_json_array_create();
+				if (!json_channels) {
+					ast_log(LOG_ERROR, "Unable to allocate json array\n");
+					ast_json_unref(target_json_channel);
+					ast_json_unref(target_json_labels);
+					return;
+				}
+			}
+
+			ast_json_array_append(json_channels, target_json_channel);
+		}
+
+		/* Don't send a message to the user that triggered the event. */
+		if (!source_echo_events && user->chan == chan) {
+			ast_debug(3, "Skipping queueing %s message to '%s'. Same channel.\n", msg_name,
+				ast_channel_name(user->chan));
+			continue;
+		}
+
+		/* Don't send a message to users in profiles not sending events. */
+		if (!ast_test_flag(&user->u_profile, USER_OPT_SEND_EVENTS)) {
+			ast_debug(3, "Skipping queueing %s message to '%s'. Not receiving events.\n", msg_name,
+				ast_channel_name(user->chan));
+			continue;
+		}
+
+		source_json_labels = get_media_labels(conference, chan, user->chan, LABEL_DIRECTION_DEST);
+		ast_json_object_update(extras, source_json_labels);
+
+		json_object = pack_snapshots(obj->bridge, obj->channel, extras, source_json_labels, msg);
+		ast_json_unref(source_json_labels);
+
+		if (!json_object) {
+			ast_log(LOG_ERROR, "Unable to convert %s message to json\n", msg_name);
+			continue;
+		}
+
+		send_message(conference->name, json_object, user->chan);
+		ast_json_unref(json_object);
+	}
+	ao2_unlock(conference);
+
+	/*
+	 * If this is a join event, send the welcome message to just the joining user
+	 * if it's not audio-only or otherwise restricted.
+	 */
+	if (source_send_events && json_channels
+		&& stasis_message_type(msg) == confbridge_join_type()) {
+		struct ast_json *json_object;
+		struct ast_json *json_bridge;
+
+		json_bridge = bridge_to_json(obj->bridge);
+		json_object = pack_bridge_and_channels(json_bridge, json_channels, msg);
+		if (!json_object) {
+			ast_log(LOG_ERROR, "Unable to convert ConfbridgeWelcome message to json\n");
+			return;
+		}
+		ast_json_string_set(ast_json_object_get(json_object, "type"),
+			confbridge_event_type_to_string(confbridge_welcome_type()));
+
+		send_message(conference->name, json_object, chan);
+		ast_json_unref(json_object);
+	}
+}
+
 static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan,
 	struct stasis_message_type *type, struct ast_json *extras, int channel_topic)
 {
@@ -566,6 +836,10 @@
 		return;
 	}
 
+	if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_ENABLE_EVENTS)) {
+		send_event_to_participants(conference, chan, msg);
+	}
+
 	if (channel_topic) {
 		stasis_publish(ast_channel_topic(chan), msg);
 	} else {
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index 8738319..9e56b36 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -68,6 +68,23 @@
 				<configOption name="admin">
 					<synopsis>Sets if the user is an admin or not</synopsis>
 				</configOption>
+				<configOption name="send_events" default="no">
+					<synopsis>Sets if events are send to the user</synopsis>
+					<description><para>If events are enabled for this bridge and this option is
+					set, users will receive events like join, leave, talking, etc. via text
+					messages.  For users accessing the bridge via chan_pjsip, this means
+					in-dialog MESSAGE messages.  This is most useful for WebRTC participants
+					where the browser application can use the messages to alter the user
+					interface.</para></description>
+				</configOption>
+				<configOption name="echo_events" default="yes">
+					<synopsis>Sets if events are echoed back to the user that
+					triggered them</synopsis>
+					<description><para>If events are enabled for this user and this option
+					is set, the user will receive events they trigger, talking, mute, etc.
+					If not set, they will not receive their own events.
+					</para></description>
+				</configOption>
 				<configOption name="marked">
 					<synopsis>Sets if this is a marked user or not</synopsis>
 				</configOption>
@@ -489,6 +506,17 @@
 								<para>The highest estimated maximum bitrate is forwarded to the sender.</para>
 							</enum>
 						</enumlist>
+					</description>
+				</configOption>
+				<configOption name="enable_events" default="no">
+					<synopsis>Enables events for this bridge</synopsis>
+					<description><para>
+						If enabled, recipients who joined the bridge via a channel driver
+						that supports Enhanced Messaging (currently only chan_pjsip) will
+						receive in-dialog messages containing a JSON body describing the
+						event.  The Content-Type header will be
+						<literal>text/x-ast-confbridge-event</literal>.
+						This feature must also be enabled in user profiles.</para>
 					</description>
 				</configOption>
 				<configOption name="template">
@@ -1478,6 +1506,12 @@
 	ast_cli(a->fd,"Admin:                   %s\n",
 		u_profile.flags & USER_OPT_ADMIN ?
 		"true" : "false");
+	ast_cli(a->fd,"Send Events:             %s\n",
+		u_profile.flags & USER_OPT_SEND_EVENTS ?
+		"true" : "false");
+	ast_cli(a->fd,"Echo Events:             %s\n",
+		u_profile.flags & USER_OPT_ECHO_EVENTS ?
+		"true" : "false");
 	ast_cli(a->fd,"Marked User:             %s\n",
 		u_profile.flags & USER_OPT_MARKEDUSER ?
 		"true" : "false");
@@ -1717,6 +1751,10 @@
 		ast_assert(0);
 		break;
 	}
+
+	ast_cli(a->fd,"Enable Events:             %s\n",
+		b_profile.flags & BRIDGE_OPT_ENABLE_EVENTS ?
+		"yes" : "no");
 
 	ast_cli(a->fd,"sound_only_person:    %s\n", conf_get_sound(CONF_SOUND_ONLY_PERSON, b_profile.sounds));
 	ast_cli(a->fd,"sound_only_one:       %s\n", conf_get_sound(CONF_SOUND_ONLY_ONE, b_profile.sounds));
@@ -2265,6 +2303,8 @@
 	/* User options */
 	aco_option_register(&cfg_info, "type", ACO_EXACT, user_types, NULL, OPT_NOOP_T, 0, 0);
 	aco_option_register(&cfg_info, "admin", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ADMIN);
+	aco_option_register(&cfg_info, "send_events", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_SEND_EVENTS);
+	aco_option_register(&cfg_info, "echo_events", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ECHO_EVENTS);
 	aco_option_register(&cfg_info, "marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MARKEDUSER);
 	aco_option_register(&cfg_info, "startmuted", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_STARTMUTED);
 	aco_option_register(&cfg_info, "music_on_hold_when_empty", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MUSICONHOLD);
@@ -2288,6 +2328,7 @@
 	aco_option_register(&cfg_info, "dsp_talking_threshold", ACO_EXACT, user_types, __stringify(DEFAULT_TALKING_THRESHOLD), OPT_UINT_T, 0, FLDSET(struct user_profile, talking_threshold));
 	aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_JITTERBUFFER);
 	aco_option_register(&cfg_info, "timeout", ACO_EXACT, user_types, "0", OPT_UINT_T, 0, FLDSET(struct user_profile, timeout));
+
 	/* This option should only be used with the CONFBRIDGE dialplan function */
 	aco_option_register_custom(&cfg_info, "template", ACO_EXACT, user_types, NULL, user_template_handler, 0);
 
@@ -2313,6 +2354,7 @@
 	aco_option_register(&cfg_info, "video_update_discard", ACO_EXACT, bridge_types, "2000", OPT_UINT_T, 0, FLDSET(struct bridge_profile, video_update_discard));
 	aco_option_register(&cfg_info, "remb_send_interval", ACO_EXACT, bridge_types, "0", OPT_UINT_T, 0, FLDSET(struct bridge_profile, remb_send_interval));
 	aco_option_register_custom(&cfg_info, "remb_behavior", ACO_EXACT, bridge_types, "average", remb_behavior_handler, 0);
+	aco_option_register(&cfg_info, "enable_events", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_ENABLE_EVENTS);
 	/* This option should only be used with the CONFBRIDGE dialplan function */
 	aco_option_register_custom(&cfg_info, "template", ACO_EXACT, bridge_types, NULL, bridge_template_handler, 0);
 
diff --git a/apps/confbridge/confbridge_manager.c b/apps/confbridge/confbridge_manager.c
index 0f3c7fb..823e69a 100644
--- a/apps/confbridge/confbridge_manager.c
+++ b/apps/confbridge/confbridge_manager.c
@@ -227,12 +227,56 @@
 static struct stasis_message_router *bridge_state_router;
 static struct stasis_message_router *channel_state_router;
 
+STASIS_MESSAGE_TYPE_DEFN(confbridge_start_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_end_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_join_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_leave_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_start_record_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_stop_record_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_mute_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_unmute_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_talking_type);
+/*
+ * The welcome message is defined here but is only sent
+ * to participants and only when events are enabled.
+ * At the current time, no actual stasis or AMI events
+ * are generated for this type.
+ */
+STASIS_MESSAGE_TYPE_DEFN(confbridge_welcome_type);
+
+const char *confbridge_event_type_to_string(struct stasis_message_type *event_type)
+{
+	if (event_type == confbridge_start_type()) {
+		return "ConfbridgeStart";
+	} else if (event_type == confbridge_end_type()) {
+		return "ConfbridgeEnd";
+	} else if (event_type == confbridge_join_type()) {
+		return "ConfbridgeJoin";
+	} else if (event_type == confbridge_leave_type()) {
+		return "ConfbridgeLeave";
+	} else if (event_type == confbridge_start_record_type()) {
+		return "ConfbridgeRecord";
+	} else if (event_type == confbridge_stop_record_type()) {
+		return "ConfbridgeStopRecord";
+	} else if (event_type == confbridge_mute_type()) {
+		return "ConfbridgeMute";
+	} else if (event_type == confbridge_unmute_type()) {
+		return "ConfbridgeUnmute";
+	} else if (event_type == confbridge_talking_type()) {
+		return "ConfbridgeTalking";
+	} else if (event_type == confbridge_welcome_type()) {
+		return "ConfbridgeWelcome";
+	} else {
+		return "unknown";
+	}
+}
+
 static void confbridge_publish_manager_event(
 	struct stasis_message *message,
-	const char *event,
 	struct ast_str *extra_text)
 {
 	struct ast_bridge_blob *blob = stasis_message_data(message);
+	const char *event = confbridge_event_type_to_string(stasis_message_type(message));
 	const char *conference_name;
 	RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
 	RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
@@ -291,13 +335,13 @@
 static void confbridge_start_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
-	confbridge_publish_manager_event(message, "ConfbridgeStart", NULL);
+	confbridge_publish_manager_event(message, NULL);
 }
 
 static void confbridge_end_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
-	confbridge_publish_manager_event(message, "ConfbridgeEnd", NULL);
+	confbridge_publish_manager_event(message, NULL);
 }
 
 static void confbridge_leave_cb(void *data, struct stasis_subscription *sub,
@@ -306,7 +350,7 @@
 	struct ast_str *extra_text = NULL;
 
 	if (!get_admin_header(&extra_text, message)) {
-		confbridge_publish_manager_event(message, "ConfbridgeLeave", extra_text);
+		confbridge_publish_manager_event(message, extra_text);
 	}
 	ast_free(extra_text);
 }
@@ -318,7 +362,7 @@
 
 	if (!get_admin_header(&extra_text, message)
 		&& !get_muted_header(&extra_text, message)) {
-		confbridge_publish_manager_event(message, "ConfbridgeJoin", extra_text);
+		confbridge_publish_manager_event(message, extra_text);
 	}
 	ast_free(extra_text);
 }
@@ -326,13 +370,13 @@
 static void confbridge_start_record_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
-	confbridge_publish_manager_event(message, "ConfbridgeRecord", NULL);
+	confbridge_publish_manager_event(message, NULL);
 }
 
 static void confbridge_stop_record_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
-	confbridge_publish_manager_event(message, "ConfbridgeStopRecord", NULL);
+	confbridge_publish_manager_event(message, NULL);
 }
 
 static void confbridge_mute_cb(void *data, struct stasis_subscription *sub,
@@ -341,7 +385,7 @@
 	struct ast_str *extra_text = NULL;
 
 	if (!get_admin_header(&extra_text, message)) {
-		confbridge_publish_manager_event(message, "ConfbridgeMute", extra_text);
+		confbridge_publish_manager_event(message, extra_text);
 	}
 	ast_free(extra_text);
 }
@@ -352,7 +396,7 @@
 	struct ast_str *extra_text = NULL;
 
 	if (!get_admin_header(&extra_text, message)) {
-		confbridge_publish_manager_event(message, "ConfbridgeUnmute", extra_text);
+		confbridge_publish_manager_event(message, extra_text);
 	}
 	ast_free(extra_text);
 }
@@ -373,19 +417,9 @@
 	}
 
 	if (!get_admin_header(&extra_text, message)) {
-		confbridge_publish_manager_event(message, "ConfbridgeTalking", extra_text);
+		confbridge_publish_manager_event(message, extra_text);
 	}
 }
-
-STASIS_MESSAGE_TYPE_DEFN(confbridge_start_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_end_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_join_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_leave_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_start_record_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_stop_record_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_mute_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_unmute_type);
-STASIS_MESSAGE_TYPE_DEFN(confbridge_talking_type);
 
 void manager_confbridge_shutdown(void) {
 	STASIS_MESSAGE_TYPE_CLEANUP(confbridge_start_type);
@@ -397,6 +431,7 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(confbridge_mute_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(confbridge_unmute_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(confbridge_talking_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(confbridge_welcome_type);
 
 	if (bridge_state_router) {
 		stasis_message_router_unsubscribe(bridge_state_router);
@@ -420,6 +455,7 @@
 	STASIS_MESSAGE_TYPE_INIT(confbridge_mute_type);
 	STASIS_MESSAGE_TYPE_INIT(confbridge_unmute_type);
 	STASIS_MESSAGE_TYPE_INIT(confbridge_talking_type);
+	STASIS_MESSAGE_TYPE_INIT(confbridge_welcome_type);
 
 	bridge_state_router = stasis_message_router_create(
 		ast_bridge_topic_all_cached());
@@ -564,5 +600,7 @@
 		return -1;
 	}
 
+	/* FYI: confbridge_welcome_type is never routed */
+
 	return 0;
 }
diff --git a/apps/confbridge/include/confbridge.h b/apps/confbridge/include/confbridge.h
index 0a0a571..2750d93 100644
--- a/apps/confbridge/include/confbridge.h
+++ b/apps/confbridge/include/confbridge.h
@@ -65,6 +65,8 @@
 	USER_OPT_ANNOUNCEUSERCOUNTALL = (1 << 14), /*!< Sets if the number of users should be announced to everyone. */
 	USER_OPT_JITTERBUFFER =  (1 << 15), /*!< Places a jitterbuffer on the user. */
 	USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW = (1 << 16), /*!< modifies ANNOUNCE_JOIN_LEAVE - user reviews the recording before continuing */
+	USER_OPT_SEND_EVENTS = (1 << 17), /*!< Send text message events to users */
+	USER_OPT_ECHO_EVENTS = (1 << 18), /*!< Send events only to the admin(s) */
 };
 
 enum bridge_profile_flags {
@@ -79,6 +81,7 @@
 	BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE = (1 << 8), /*!< The average of all REMB reports is sent to the sender */
 	BRIDGE_OPT_REMB_BEHAVIOR_LOWEST = (1 << 9), /*!< The lowest estimated maximum bitrate is sent to the sender */
 	BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST = (1 << 10), /*!< The highest estimated maximum bitrate is sent to the sender */
+	BRIDGE_OPT_ENABLE_EVENTS = (1 << 11), /*!< Enable sending events to participants */
 };
 
 enum conf_menu_action_id {
@@ -625,6 +628,26 @@
 struct stasis_message_type *confbridge_talking_type(void);
 
 /*!
+ * \since 15.5
+ * \brief get the confbridge welcome stasis message type
+ *
+ * \retval stasis message type for confbridge welcome messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_welcome_type(void);
+
+/*!
+ * \since 15.5
+ * \brief Get the string representation of a confbridge stasis message type
+ *
+ * \param event_type The confbridge event type such as 'confbridge_welcome_type()'
+ *
+ * \retval The string representation of the message type
+ * \retval "unknown" if not found
+ */
+const char *confbridge_event_type_to_string(struct stasis_message_type *event_type);
+
+/*!
  * \since 12.0
  * \brief register stasis message routers to handle manager events for confbridge messages
  *
diff --git a/configs/samples/confbridge.conf.sample b/configs/samples/confbridge.conf.sample
index 8b276cd..a214f34 100644
--- a/configs/samples/confbridge.conf.sample
+++ b/configs/samples/confbridge.conf.sample
@@ -18,6 +18,18 @@
 [default_user]
 type=user
 ;admin=yes     ; Sets if the user is an admin or not. Off by default.
+
+;send_events=no  ; If events are enabled for this bridge and this option is
+                 ; set, users will receive events like join, leave, talking,
+                 ; etc. via text messages.  For users accessing the bridge
+                 ; via chan_pjsip, this means in-dialog MESSAGE messages.
+                 ; This is most useful for WebRTC participants where the
+                 ; browser application can use the messages to alter the user
+                 ; interface.
+;echo_events=yes ; If events are enabled for this user and this option is set,
+                 ; the user will receive events they trigger, talking, mute, etc.
+                 ; If not set, they will not receive their own events.
+
 ;marked=yes    ; Sets if this is a marked user or not. Off by default.
 ;startmuted=yes; Sets if all users should start out muted. Off by default
 ;music_on_hold_when_empty=yes  ; Sets whether MOH should be played when only
@@ -244,6 +256,13 @@
                            ; set to "lowest" the lowest maximum bitrate is forwarded to the sender. If set to "highest"
                            ; the highest maximum bitrate is forwarded to the sender. This defaults to "average".
 
+;enable_events=no          ; If enabled, recipients who joined the bridge via a channel driver
+                           ; that supports Enhanced Messaging (currently only chan_pjsip) will
+                           ; receive in-dialog messages containing a JSON body describing the
+                           ; event.  The Content-Type header will be
+                           ; "text/x-ast-confbridge-event".
+                           ; This feature must also be enabled in user profiles.
+
 ; All sounds in the conference are customizable using the bridge profile options below.
 ; Simply state the option followed by the filename or full path of the filename after
 ; the option.  Example: sound_had_joined=conf-hasjoin  This will play the conf-hasjoin
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 0cc2de9..c9c0f17 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1119,10 +1119,24 @@
 	}
 
 	if (ast_strlen_zero(session_media->label)) {
-		ast_uuid_generate_str(session_media->label, sizeof(session_media->label));
+		/*
+		 * If this stream has already been assigned a label, use it.
+		 * This will ensure that a confbridge participant is known by
+		 * the same label by all other participants.
+		 */
+		const char *stream_label = ast_stream_get_metadata(stream, "MSID:LABEL");
+
+		if (!ast_strlen_zero(stream_label)) {
+			ast_copy_string(session_media->label, stream_label, sizeof(session_media->label));
+		} else {
+			ast_uuid_generate_str(session_media->label, sizeof(session_media->label));
+			ast_stream_set_metadata(stream, "MSID:LABEL", session_media->label);
+		}
 	}
 
 	snprintf(msid, sizeof(msid), "%s %s", session_media->mslabel, session_media->label);
+	ast_debug(3, "Stream msid: %p %s %s\n", stream,
+		ast_codec_media_type2str(ast_stream_get_type(stream)), msid);
 	attr = pjmedia_sdp_attr_create(pool, "msid", pj_cstr(&stmp, msid));
 	pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);
 }

-- 
To view, visit https://gerrit.asterisk.org/9085
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I26420aa9f101f0b2387dc9e2fd10733197f1318e
Gerrit-Change-Number: 9085
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180604/5918aed2/attachment-0001.html>


More information about the asterisk-code-review mailing list