本文介绍了如何从Asterisk REST API(ARI)获取所有拨号程序事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Web应用程序,该应用程序应该能够监视我的Asterisk服务器上的呼叫.我可以使用URL ws://(host):8088/ari/events?app=dialer上的Javascript WebSocket连接到ARI,并且可以正常工作.问题是,我仅从通过ARI进行的调用中获取事件.从其他客户(如Zoiper)发出的呼叫未注册.另一方面,Asterisk具有AJAM,该AJAM在http://(host):8088/rawman?action=waitevent上使用长时间轮询,并注册来自所有客户端(ARI,Zoiper和其他客户端)的呼叫,但是只有正在呼叫(呼叫者)的信息,不是(被呼叫者).

I'm making a web application which should be able to monitor calls on my Asterisk server. I can connect to ARI with Javascript WebSocket on URL ws://(host):8088/ari/events?app=dialer and it works. The problem is that I only get events from calls that are made over ARI. Calls made from other clients like Zoiper are not registered. On the other hand, Asterisk has AJAM which uses long polling on http://(host):8088/rawman?action=waitevent and it registers calls from all the clients, (ARI, Zoiper and others) but there's only information who is calling (caller), not whom (callee).

所以,我的问题是,如何才能从所有客户端(最好)使用WebSockets获得实时呼叫事件,以显示谁在呼叫谁.谢谢.

So, my question is, how can I get real time call events that show who is calling who, from all the clients, (preferably) with WebSockets. Thanks.

推荐答案

ARI使用基于订阅的事件模型.引用 Wiki 上的文档:

ARI uses a subscription based model for events. Quoting from the documentation on the wiki:

  1. 资源必须是进入Stasis Dialplan应用程序的渠道.在这种情况下,将隐式创建一个预订.这 当频道离开频道时,订阅会被隐式破坏 Stasis Dialplan应用程序.
  2. 虽然频道在Stasis Dialplan应用程序中,但该频道可能会与其他资源(例如网桥)进行交互.虽然频道 与资源交互时,将对该资源进行预订. 当Stasis Dialplan应用程序中没有其他频道正在交互时 使用该资源,隐式订阅将被破坏.
  3. 任何时候,ARI应用程序都可以通过应用程序操作来订阅Asterisk中的资源.虽然那 资源存在,则ARI应用程序拥有订阅.
  1. The resource must be a channel that entered into a Stasis dialplan application. A subscription is implicitly created in this case. The subscription is implicitly destroyed when the channel leaves the Stasis dialplan application.
  2. While a channel is in a Stasis dialplan application, the channel may interact with other resources - such as a bridge. While channels interact with the resource, a subscription is made to that resource. When no more channels in a Stasis dialplan application are interacting with the resource, the implicit subscription is destroyed.
  3. At any time, an ARI application may make a subscription to a resource in Asterisk through application operations. While that resource exists, the ARI application owns the subscription.

因此,您在ARI WebSocket上收到有关某个通道的事件的原因是,该通道进入了Stasis Dialplan应用程序.但是,这并不是获取事件的唯一方法.

So, the reason you get events about a channel over your ARI WebSocket is because it went into the Stasis dialplan application. That isn't, however, the only way to get events.

如果您对其他事件来源的事件感兴趣,则可以使用应用程序资源.例如,如果我想接收与PJSIP端点"Alice"有关的所有事件,则可以使用以下命令进行订阅:

If you're interested in events from other event sources, you can subscribe to those resources using the applications resource. For example, if I wanted to receive all events that were in relation to PJSIP endpoint "Alice", I would subscribe using the following:

POST https://localhost:8080/ari/applications/my_app/subscription?eventSource=endpoint:PJSIP%2FAlice

请注意,对端点的预订隐式地使您预订为该端点创建的所有通道.如果要订阅特定技术的所有端点,则还可以订阅资源本身:

Note that subscriptions to endpoints implicitly subscribe you to all channels that are created for that endpoint. If you want to subscribe to all endpoints of a particular technology, you can also subscribe to the resource itself:

POST https://localhost:8080/ari/applications/my_app/subscription?eventSource=endpoint:PJSIP

这篇关于如何从Asterisk REST API(ARI)获取所有拨号程序事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 19:09