节点ARI客户端| Connect方法没有触发回调?

时间:2016-04-15 16:12:49

标签: javascript node.js asterisk asterisk-ari

所以,我开始玩Asterisk Restful Interface(ARI)。

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

我有一个正确配置的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!!');
});
...

问题是,anon回调永远不会被解雇。我从未见过'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 <dlee@digium.com>",
  "_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问题?!

1 个答案:

答案 0 :(得分:2)

您的连接失败(由于下面列出的原因),并且由于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

可能有几个原因导致无法使用此功能,但最有可能的问题是身份验证。您提到在访问您的网址时,提示您输入用户名和密码&#34;。如果您的JSON模式(或任何其他需要在没有凭据的情况下访问的文件)落后于身份验证,您将需要重新考虑您的应用程序结构。

目前,如果在 Swagger加载JSON架构之前连接失败node-ari-client将无提示失败。有Pull Request等待解决此问题并记录错误,但在此期间您应该解决阻止连接的潜在问题。

如果您可以成功访问resources.json,则访问资源可能存在其他问题。您描述的网址是通过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访问/连接您的服务。这有什么不同吗?