[asterisk-app-dev] Basic questions about Stasis, ari-py

Nick Horelik nhorelik at MIT.EDU
Mon Jun 30 10:22:52 CDT 2014


Thank you so much for your help.  I think I mostly understand now, I just
want to confirm that I'm thinking of this properly.  Basically, in the
dialplan you can pass an arbitrary string to Stasis, which serves as the
application name and handle by which a websocket client refers to that
application.  I need to dial that extension to get a channel into it from a
phone or e.g. something like,

client.channels.originate(endpoint="Local/hello-world at default",
extension="hello-world", context="default")

using ari-py from anywhere if I have the extension you mentioned.  I also
noticed that I need an active websocket at
/ari/events?app=<appname>&api_key=<user:password> in order for the channel
to remain open (for example, leaving open the wscat example in the getting
started guide), otherwise it hangs up immediately.

I think one thing that led me astray before was that when I ran
originate_example.py I got the no-json error indicated in this air-py
github issue [1] and immediately assumed that I was just doing something
wrong.  In fact, that example shouldn't raise an exception regardless of
the appname - it just won't do anything until a phone dials an extension
that triggers a Stasis command with that appname.

Does all this sound correct?  If so it sounds like I should try to debug
ari-py or look into other abstraction layers.

Thanks again,

Nick

[1] https://github.com/asterisk/ari-py/issues/3



On Sun, Jun 29, 2014 at 10:56 PM, Matthew Jordan <mjordan at digium.com> wrote:

>
> On Sun, Jun 29, 2014 at 9:27 PM, Nick Horelik <nhorelik at mit.edu> 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 at lists.digium.com
> http://lists.digium.com/cgi-bin/mailman/listinfo/asterisk-app-dev
>
>


-- 
774.208.2168
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-app-dev/attachments/20140630/53550f71/attachment-0001.html>


More information about the asterisk-app-dev mailing list