因此,我开始使用Asterisk Restful Interface(ARI)。

我创建了一个单独的 express 应用程序来执行此操作。

我有一个正确配置的Asterisk 13实例正在运行。我知道这是因为,当我在浏览器中转到https://192.168.46.122:8088/ari/sounds时,系统会提示我输入用户名和密码,输入该用户名和密码后,会返回一个带有预期数据的有效JSON对象...

[
  {
    "id": "conf-now-unmuted",
    "text": "The conference is now unmuted.",
    "formats": [
      {
        "language": "en",
        "format": "gsm"
      }
    ]
  },
  {
    "id": "vm-nomore",
    "text": "No more messages.",
    "formats": [
      {
        "language": "en",
        "format": "gsm"
      }
    ]
  },
  {
    "id": "vm-review",
    "text": "press 1 to accept this recording press 2 to listen to it press 3 to rerecord your message",
    "formats": [
      {
        "language": "en",
        "format": "gsm"
      }
    ]
  },
  {
    "id": "demo-echodone",
    "text": "The echo test has been completed.",
    "formats": [
      {
        "language": "en",
        "format": "gsm"
      }
    ]
  },
  {
    "id": "confbridge-rest-talk-vol-out",
    "text": "...to reset your speaking volume to the default level.",
    "formats": [
      {
        "language": "en",
        "format": "gsm"
      }
    ]
  }, ...... etc etc

在我的app.js文件中,我包含以下代码...
...
var logger = require('morgan');
var client = require('ari-client');
var url = 'https://192.168.46.122:8088/ari/sounds';
var username = 'correct_username';
var password = 'correct_password';

client.connect(url, username, password, function (err, ari) {
  console.log('HELLLLLLOOOOO!!');
});
...

问题是,永远不会触发匿名回调。我从没看过'HELLLLLLOOOOO !!'

谁能阐明为什么/在什么情况下会发生这种情况?该模块是否存在任何已知的错误可能导致此错误?

如果您需要有关配置,环境等的更多信息,请告诉我。

谢谢你们

更新

在下面的评论中...我尝试了以下操作:
client.connect(url, username, password)
.then(function(ari) {
  console.log('HELLLLLLOOOOO!!');
})
.catch(function(err){
  console.log('ERR: ' + err);
});


client.connect(url, username, password, function (err, ari) {
  if(err) console.log(err);

  console.log('HELLLLLLOOOOO!!');
});

没有错误,也没有“HELLLLLOOOOOO !!”在任何时候:-(

更新2

刚刚访问了/ari/api-docs/resources.json并收到了以下响应...所以它看起来像是存在的。
{
  "_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
  "_author": "David M. Lee, II <[email protected]>",
  "_svn_revision": "$Revision: 430337 $",
  "apiVersion": "1.7.0",
  "swaggerVersion": "1.1",
  "basePath": "http://192.168.46.122:8088/ari",
  "apis": [
    {
      "path": "/api-docs/asterisk.{format}",
      "description": "Asterisk resources"
    },
    {
      "path": "/api-docs/endpoints.{format}",
      "description": "Endpoint resources"
    },
    {
      "path": "/api-docs/channels.{format}",
      "description": "Channel resources"
    },
    {
      "path": "/api-docs/bridges.{format}",
      "description": "Bridge resources"
    },
    {
      "path": "/api-docs/recordings.{format}",
      "description": "Recording resources"
    },
    {
      "path": "/api-docs/sounds.{format}",
      "description": "Sound resources"
    },
    {
      "path": "/api-docs/playbacks.{format}",
      "description": "Playback control resources"
    },
    {
      "path": "/api-docs/deviceStates.{format}",
      "description": "Device state resources"
    },
    {
      "path": "/api-docs/mailboxes.{format}",
      "description": "Mailboxes resources"
    },
    {
      "path": "/api-docs/events.{format}",
      "description": "WebSocket resource"
    },
    {
      "path": "/api-docs/applications.{format}",
      "description": "Stasis application resources"
    }
  ]
}

我现在正在考虑这可能是SSL问题?!

最佳答案

您的连接失败(由于下面概述的原因),并且由于node-ari-client中的问题/即将出现的功能,因此不会记录失败的连接。
node-ari-client模块使用Swagger,它希望加载描述API的JSON模式。在node-ari-client实现中,Swagger希望在%s//%s/ari/api-docs/resources.json处找到此JSON模式。

因此,首先要检查的是它是否存在/是否可以在您的应用程序中访问:
https://192.168.46.122:8088/ari/api-docs/resources.json
有几种原因导致此功能不可用,但最有可能的问题是身份验证。您提到在访问URL时,“提示您输入用户名和密码”。如果您的JSON模式(或需要在没有凭据的情况下访问的任何其他文件)落后于身份验证,则需要重新考虑您的应用程序结构。

当前,如果在Swagger加载JSON模式之前出现连接故障,则node-ari-client将静默失败。等待Pull Request可以解决此问题并记录错误,但是与此同时,您应该解决阻止连接的潜在问题。

如果您可以成功访问resources.json,则访问资源可能还有其他问题。您描述的URL通过https访问您的服务,但是您的resources.json文件告诉Swagger通过常规http访问它。要解决此问题,您可以尝试:

将Swagger模式中的basePath更改为使用https :
"basePath": "https://192.168.46.122:8088/ari",
向Swagger模式添加protocols字段:"protocols":["http", "https"]
删除https
为了发现https是否是造成连接问题的原因,这可能是一个不错的选择。只需完全保持Swagger模式不变,然后尝试通过http访问/连接到您的服务即可。这有什么不同吗?

09-28 05:39