Re: Basic questions about Stasis, ari-py

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Sun, Jun 29, 2014 at 9:27 PM, Nick Horelik <nhorelik@xxxxxxx> wrote:
> Hello,
>
> I am a bit new to Asterisk in general, so I apologize if this is a very
> basic question.  After scouring the internet for a few days I seem to be
> unable to find a good description of what an 'external Stasis application'
> is at a high level.  The 'Getting Started with ARI' article has been very
> helpful getting me going on ARI in general, but beyond mentioning that 'my
> application' needs to be connected with Stasis there isn't much guidance on
> where I should look next for how to write that application and where I would
> install it.
>
> In particular I'm hoping to use ari-py [1], which has been useful in helping
> me learn.  However, all the provided examples still try to point to the same
> 'hello' app mentioned in the getting started guide, which of course will
> fail for me since I don't know how to create or where to put this 'hello'
> app.
>
> I can successfully use ari-py to do things like:
>
> client.channels.originate(endpoint="PJSIP/<mynumber>@mytrunk",extension="hello-world",
> context="default")
>
> to call my cell phone and play a message hardcoded into a hello-world
> extension, for instance, but I'm not sure how to do anything more
> complicated than that. The next thing I would like to learn how to do is use
> ARI to specify an audio file to play (perhaps using
> /channel/{channelID}/play), but it's my understanding at this point that I
> need my channels inside a stasis application before I can do that.
>
> Again, I'm sorry if my confusion arises from a failure to understand
> something basic about Asterisk in general.  I would greatly appreciate any
> hints for where I should be looking for references that can help me learn
> more.
>
> Thanks,
>
> Nick Horelik

Hi Nick -

ARI is all about controlling things in the context of a dialplan application. Just as, say, the 'Queue' dialplan application has multiple channels that go into it (and under the hood, has bridges, and device state, and all sorts of other things), channels need to be passed into something in the dialplan to hand it off to a connected ARI client. While you can do some things outside of that - such as originating a channel to another location in the dialplan - things are a lot more interesting when you have them in a dialplan application that you control externally.

That dialplan application  is the "Stasis" dialplan application [1]. Using your originate example, you could do something like the following:

exten => hello-world,1,NoOp()
 same => n,Stasis(hello-world)
 same => n,Hangup()

When the channel enters into the dialplan application Stasis, that's Asterisk's signal that it is handing control of the channel off to a connected ARI client. In this case, your WebSocket establishes the connection for your ARI application, and informs Asterisk which Stasis dialplan application it wants to control [2]. In this case, the Stasis dialplan application was passed the name 'hello-world' as the name of the application - so a WebSocket that had connected to that application would see that a channel had entered into it.

When a channel does enter into the Stasis dialplan application, the connected WebSocket gets a 'StasisStart' event [3]. That's the application's sign that it can now freely manipulate the channel - such as issuing a play operation through the ARI channels resource. When the channel leaves, the WebSocket gets a 'StasisEnd' event [4]. That's the applications sign that it no longer has control over the channel, and will stop receiving information about it.

If the application wants to continue seeing information about the channel, it can subscribe to the channel via the applications resource [5].

Hope this helps - if you run into an issue, please don't hesitate to contact this list.

Matt

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Application_Stasis
[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
[3] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisStart
[4] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+REST+Data+Models#Asterisk12RESTDataModels-StasisEnd
[5] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe

--
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org
_______________________________________________
asterisk-app-dev mailing list
asterisk-app-dev@xxxxxxxxxxxxxxxx
http://lists.digium.com/cgi-bin/mailman/listinfo/asterisk-app-dev

[Index of Archives]     [Asterisk SS7]     [Asterisk Announcements]     [Asterisk Users]     [PJ SIP]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Linux API]

  Powered by Linux