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

问题描述

我正在制作一个 Web 应用程序,它应该能够监控我的 Asterisk 服务器上的调用.我可以在 URL ws://(host):8088/ari/events?app=dialer 上使用 Javascript WebSocket 连接到 ARI 并且它可以工作.问题是我只能从通过 ARI 进行的调用中获取事件.从其他客户端(如 Zoiper)发出的呼叫未注册.另一方面,Asterisk 有 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:

默认情况下,Asterisk 中的资源不会将关于自身的事件发送到连接的 ARI 应用程序.为了获取有关资源的事件,必须发生以下三件事之一:

  1. 资源必须是进入 Stasis 拨号方案应用程序的通道.在这种情况下隐式创建订阅.这当频道离开时,订阅被隐式销毁Stasis 拨号方案应用.
  2. 当通道在 Stasis 拨号方案应用程序中时,通道可能与其他资源交互 - 例如桥接器.虽然频道与资源交互,则对该资源进行订阅.当 Stasis 拨号方案应用程序中没有更多通道交互时使用资源,隐式订阅被销毁.
  3. 在任何时候,ARI 应用程序都可以通过应用程序操作订阅 Asterisk 中的资源.虽然那资源存在,ARI 应用程序拥有订阅.

因此,您通过 ARI WebSocket 获取有关通道的事件的原因是它进入了 Stasis 拨号计划应用程序.然而,这并不是获取事件的唯一方法.

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) 获取所有拨号事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 19:26