Search the Asterisk Blog

Enrich Your Conference App with Asterisk Enhanced Messaging – Part 2

By George Joseph

In “Enrich Your Conference App with Asterisk Enhanced Messaging – Part 1” I demonstrated how you could include chat or other messaging features in your conference app.  In Part 2, I’ll show you how to include information about the conference bridge itself and the participants.

What data is available?

If you’re familiar with the AMI events generated by app_confbridge then you’ve got a leg up on the data available.  If not, take a quick look at the Confbridge events on the Asterisk 16 AMI Events page of the Asterisk Wiki.  AMI events are typically sent only to trusted parties so not all of the information in each event is available via Enhanced Messaging.  Conversely, there is data available via Enhanced Messaging that is useful for a conference app but not included in the AMI events.  One of the most useful of these is a ConfbridgeWelcome event that participants receive when they join a conference.  It contains a list of all the other participants currently in the conference.

What can I do with the data?

Let’s see…

  • For your chat app, show a list of all the current conference participants.
  • Overlay participant nicknames on their video windows.
  • Add mute/unmute indicators.
  • Highlight the video element of the current speaker.

These are just a few examples.  I’m sure you can think of more uses for your own app.

Exactly what data do I get?

Let’s take a look at the ConfbridgeJoin event.  It’s sent to all participants when someone joins the conference.  In this case, Bob is joining.

Since this is an event related to a specific participant, the “channels” array just has Bob’s channel in it.  Now let’s take a look at the ConfbridgeWelcome event that Bob also received when he joined:

In the ConfbridgeWelcome event, the “channels” arrays contains all of the channels currently in the bridge, including Bob himself.  In this case, Alice was already in the conference when Bob joined.

Most of the other Confbridge events have the same contents.  They are ConfbridgeJoin, ConfbridgeLeave, ConfbridgeRecord, ConfbridgeStopRecord, ConfbridgeMute, ConfbridgeUnmute, ConfbridgeWelcome.   If your bridge has the “talk_detection_events” set to “yes”, participants will also receive ConfbridgeTalking events containing a “talking_status” indicator in place of the “muted” parameter appearing in most of the other events.

If you’re familiar with the Confbridge AMI events, you’ll notice that the ConfbridgeStart and ConfbridgeEnd events are missing.  That’s because they don’t make much sense in this context.  At the time they’re generated, there are no participants to receive them!

OK, How do I get the events in my web app?

In Asterisk:

Start by adding a few parameters to your user and bridge profiles in confbridge.conf:

Of course, your configuration will be different but those are the parameters that need to be set.  One note of warning though, if a user connects to the bridge via a DAHDI channel or some other non-SIP based channel, they may receive messages in another format, like SMS, which is probably not a good idea.  To prevent this, you may want to use two different user profiles, one with events enabled and one without.  You could then do some simple dialplan logic to look at the incoming channel technology and call Confbridge() with the appropriate user profile.

In the browser:

You use the same mechanism as shown in Part 1 of this blog series.  The only difference will be that the message Content-Type will be “application/x-asterisk-confbridge-event+json”.  The message bodies will be JSON events shown above.

Putting it all together

One of the possible uses for the events I mentioned above was overlaying a participant’s nickname on their video window so here’s a hint on how you could do that.

If you look at the events you’ll notice that every channel specifies an “id” field which is the Asterisk channel’s unique id.  When you receive ConfbridgeJoin or ConfbridgeWelcome events, save the event in a hashmap keyed by that id.  When you receive a new video stream, which you can intercept by adding an “sdp” handler to your JsSip RTCSession, look at the sdp and look for the “a:label=” and “a:msid” attributes in each video stream.  The “a:label” will be the participant’s channel id as specified in the events and the “a:msid” will be available in the video element WebRTC creates.  Now, just create another hashmap that cross references the two and when you draw your video elements, you can grab the msid from it and then get the corresponding participant from the hashmaps.

Wrap up

Hopefully you’ve now got a good idea of what Enhanced Messaging can do for your conference app.  Feel free to ask questions here, on the asterisk-dev mailing list or in the #asterisk-dev freenode IRC channel.

If you’re coming to AstriCon or AstriDevCon in October, we’ll be there and would love to hear your feedback!

No Comments Yet

Get the conversation started!

Add to the Discussion

Your email address will not be published. Required fields are marked *

About the Author

George Joseph

See All of George's Articles