gpt4 book ai didi

javascript - 使用 ARI 监视与桥梁相关的事件

转载 作者:行者123 更新时间:2023-11-30 16:22:26 26 4
gpt4 key购买 nike

我正在尝试使用 Asterisk ARI 来监视与桥相关的事件。我正在使用 Asterisk 13.6.0。

具体来说,我想知道桥何时创建或销毁,以及用户( channel )何时加入或离开桥。在我的服务器上,桥是在有人拨入时动态创建的,并在最后一个成员离开桥时自动销毁。

使用 node-ari-client来自 Asterisk 项目的库,并遵循他们的一些示例代码,这就是我目前所拥有的。

var client = require("ari-client");
var util = require("util");

client.connect("http://localhost:8088", "username", "password")

.then(function (ari) {

ari.once("StatisStart", channelJoined);

function channelJoined (event, incoming) {

incoming.on("BridgeCreated", function(event, bridge) {
console.log(util.format("Bridge created: %s", bridge.id));
});

incoming.on("BridgeDestroyed", function(event, bridge) {
console.log(util.format("Bridge destroyed: %s", bridge.id));
});

incoming.on("ChannelEnteredBridge", function(event, channel) {
console.log(util.format("Bridge was joined by: %s", channel.id));
});

incoming.on("ChannelLeftBridge", function(event, channel) {
console.log(util.format("Bridge was joined by: %s", channel.id));
});
}

ari.start("bridge-watcher");
})

.done();

我预计 .on() 处理程序会在各种事件发生时打印到控制台。然而,调用一座桥,离开一座桥,没有任何东西被打印到控制台。

如果重要的话,这里是 npm ls 的输出,显示了我正在使用的版本。 Node 是 v0.10.36。

├─┬ ari-client@0.5.0
│ ├── backoff-func@0.1.2
│ ├── bluebird@2.9.34
│ ├── node-uuid@1.4.1
│ ├─┬ swagger-client@2.0.26
│ │ ├── btoa@1.1.1
│ │ └─┬ shred@0.8.10
│ │ ├── ax@0.1.8
│ │ ├── cookiejar@1.3.1
│ │ ├── iconv-lite@0.2.11
│ │ └── sprintf@0.1.1
│ ├── underscore@1.6.0
│ └─┬ ws@0.4.31
│ ├── commander@0.6.1
│ ├── nan@0.3.2
│ ├── options@0.0.5
│ └── tinycolor@0.0.1
├── bluebird@3.1.1
└─┬ util@0.10.3
└── inherits@2.0.1

最佳答案

Specifically, I want to know when a bridge has been created or destroyed, and when a user (channel) has joined or left the bridge. On my server, bridges are created dynamically when someone dials in, and destroyed automatically when the last member leaves the bridge.

请记住:ARI 的主要目的是 build your own dialplan applications , 而不是监控整个 Asterisk。因此,默认情况下,您的外部应用程序不会订阅 Asterisk 中的资源。作为Channels in a Stasis Application部分解释:

Resources in Asterisk do not, by default, send events about themselves to a connected ARI application. In order to get events about resources, one of three things must occur:

  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.

如果您希望在 Asterisk 中自动获取 channel 在 bridge-watcher 应用程序之外使用的资源的事件,除非您执行以下两种操作之一,否则您将无法获取它们:

  1. 使用 applications resource 显式订阅资源.这适用于相对静态和/或长期存在的资源,例如端点、静态桥(例如用于 session 的桥)、邮箱和设备状态。它不适用于临时资源。

  2. 在 Asterisk 13.6.0 及更高版本中,您现在可以在连接 WebSocket 时订阅所有事件源。在 node-ari-client 中,您将执行以下操作:

    ari.start(bridge-watcher, true);

但是您应该注意,即使您订阅了所有资源,您也不会明确地拥有它们。您只能自动观看它们。所有权的概念在 ARI 中非常重要,特别是因为它涉及您可以和不能对 channel 做什么以及何时。我链接的 wiki 页面提供了一些关于其工作原理的合理文档。

关于javascript - 使用 ARI 监视与桥梁相关的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34551454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com