text stringlengths 0 152 |
|---|
to the Digium folks for it. |
As an example of what this is good for, select the endpoints:Endpoint resources |
item, press the GET button beside /endpoints, and you will see the screen shown in |
Figure 19-3. |
Figure 19-3. Get endpoints |
Well, go ahead—press the “Try it out!” button. |
Note the "id" of the channel in the wscat session, which you’ll want to copy for use |
in the Swagger UI (you’ll see several lines of JSON output relating to the call). |
Perform the following actions on the channel using the Swagger UI interface: POST: |
Answer (answer the channel), POST: hold (place the call on hold), DELETE: hold |
(take the call off hold). Note what happens to the channel in each case. |
Use of this Swagger UI is also documented over at the Asterisk wiki. |
336 |
| |
Chapter 19: Asterisk REST Interface |
This will greatly simplify your development and testing process. |
OK, that’s the quick start. Let’s dive in deeper to ARI. |
The Building Blocks of ARI |
There are three components that work together to deliver ARI: |
• The RESTful interface, through which the external application communicates |
with Asterisk. |
• A WebSocket that passes information back to the external application from |
Asterisk (in JSON format). |
• The Stasis() dialplan application, which connects control of a channel to the |
external application. |
REST |
The term RESTful stems from Representational State Transfer (REST), which is an |
architectural model for web services (as opposed to, say, a protocol). The term REST‐ |
ful has commonly come to refer to any API that provides interaction through URLs, |
with data represented in JSON format.4 So, anything that is “RESTful” is supposed to |
adhere to the constraints of REST, but in practice may be implemented as a looser |
interpretation (which, if it gets the job done, may indeed be good enough). |
WebSocket |
The WebSocket connection is the mechanism that performs the communication |
between the internals of Asterisk and the RESTful interface. In Asterisk, events may |
happen that the client did not initiate, and the WebSocket allows Asterisk to signal |
those changes to the client. |
Asterisk’s built-in HTTP server potentially provides other services across a web inter‐ |
face. For example, WebRTC also connects through the web server. If you are making |
changes or adding new services, make sure you not only test the item you’re working |
on, but also other services running through the same server, to ensure you haven’t |
inadvertently misconfigured something else. |
4 Strictly speaking, REST is far more than that, but as a practical matter, these days it seems not uncommon to |
assume that a REST API will be URL and JSON-based, simply because so many such services are presented in |
those formats. |
The Building Blocks of ARI |
| |
337 |
Stasis |
The Stasis Message Bus allows the core of Asterisk to communicate events with other |
modules and components. It is mostly internal to Asterisk; however, in the case of |
ARI, a dialplan application named Stasis() allows the dialplan to pass call control to |
your external ARI application. |
The Stasis() application itself is required in order to signal to the dialplan that call |
control is to be passed to the external program via ARI. |
As of Asterisk 16, it is no longer necessary to write dialplan code to define a connec‐ |
tion from an incoming channel to your ARI client application. Many developers in |
the Asterisk community write all their call control logic in external applications, and |
having to code up a few lines of dialplan just to pass channels to their app was seen as |
kludgy and confusing. They requested (and developed) a mechanism whereby Aster‐ |
isk will create automatic dialplan to handle this function. |
When the API is instantiated, the application reference in the URL—for example, our |
app zarniwoop—will trigger the automatic creation of a dialplan context named |
according to the app name (in this case, [stasis-zarniwoop]), including an exten‐ |
sion that pattern matches everything. This extension will then pass all calls arriving in |
that context to Stasis(zarniwoop). You will need to associate your channels with the |
correct context (context=stasis-zarniwoop) in your PJSIP (or other channel) con‐ |
figuration tables, at which point calls to those channels will automatically be connec‐ |
ted through Stasis() to the client application. |
If all this seems confusing, there’s no reason you need to stop using actual dialplan to |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.