<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9085">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit

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

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I26420aa9f101f0b2387dc9e2fd10733197f1318e </div>
<div style="display:none"> Gerrit-Change-Number: 9085 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>