Exchanging media between Asterisk and apps has just gotten easier!

Exchanging media between Asterisk and external apps has fairly involved for a few reasons, the main one being that RTP, the primary protocol for exchanging media, has some specific requirements that are particularly problematic for languages like Python and Javascript. It has a binary packet header with things like timestamps, sequence numbers, source identifiers, etc. and it requires that packets be sent with specific lengths and at a very specific interval, usually 20ms. All in all, not very friendly. The increased popularity of using AI as customer service agents has presented us some additional challenges that required us to re-think how the media exchange process works.

Users of Asterisk’s ARI interface are no strangers to using WebSockets to receive call processing events. Additionally, there have been recent enhancements that allow ARI application developers to use the same WebSocket they receive events on to make REST calls. This can eliminate the need to use HTTP for making call control requests. We’ve now taken WebSocket capabilities one step further by allowing media to be exchanged via WebSockets as well using a new channel module “chan_websocket”.

Features of chan_websocket:

  • The channel driver is codec agnostic for the most part. The most popular codecs are fully supported. This means that you won’t have to do any transcoding between Asterisk and your AI engine.
  • Secure connections are supported.
  • You can send bulk data to Asterisk, like a file or a response from an AI agent, and the channel driver will take care of breaking that audio up into appropriately sized frames.
  • Along with breaking the audio up into correctly sized frames, the channel driver will also time them appropriately so you don’t have to do it yourself. Additionally, the channel driver will automatically insert silence to maintain the timing if your app doesn’t send any audio.
  • There’s a control path available on the websocket that allows you to issue commands like “ANSWER”, “HANGUP” and “PAUSE_MEDIA”.
  • You can receive media related events over the control path like being told that a large chunk of audio you sent to Asterisk has been fully played to a caller.
  • The channel driver can accept incoming websocket connections from your app as well as make outgoing connections to your app. This can help overcome NAT issued and can enable better failover opportunities.
  • Although the driver is targeted at ARI ExternalMedia users, it’s not tied to ARI and can be used directly from the Dial dialplan app.

More info:

Full information is available on the Asterisk Documentation website and there are code samples in the GitHub asterisk/asterisk-websocket-examples repository.

Availability:

The new channel driver is currently available in the master, 20, 21, 22 and 23 branches on GitHub and will be included in the next set of regular Asterisk releases.

About the Author

What can we help you find?