Node ARI Client | Connect method not firing callback?
Asked Answered
D

1

6

So, I've started playing with the Asterisk Restful Interface (ARI).

I have created a separate express app to do this.

I have a correctly configured instance of Asterisk 13 running. I know this because When I go to https://192.168.46.122:8088/ari/sounds in my browser, I am prompted for a username and password, which when entered, returns a valid JSON object back with the expected data...

[
  {
    "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

In my app.js file I have included the following code...

...
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!!');
});
...

The issue, is that the anon callback is never fired. I never see 'HELLLLLLOOOOO!!'

Can anyone shed any light on why/under what circumstances this could happen? Are there any known bugs with the module that could be causing this?

Please let me know if you need further information about config, environment etc.

Thanks guys

UPDATE

Following comments below... I have tried the following:

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

AND

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

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

No error and no 'HELLLLLOOOOOO!!' at any point :-(

UPDATE 2

Have just visited /ari/api-docs/resources.json and got the following response... so it looks like it is present.

{
  "_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"
    }
  ]
}

I'm now thinking it may be an SSL issue?!

Downwards answered 15/4, 2016 at 16:12 Comment(4)
can you try this client.connect(url, username, password).then(function (ari) {}).catch(function (err) {console.log(err);}); it will help to see what is the errorFrankfrankalmoign
In line with Khaled here, can you see if you're getting an error in the callback. Above the console.log, write if (err) console.error(err);Comrade
This could also be the issue you're experiencing: github.com/asterisk/node-ari-client/issues/35Comrade
Thanks guys but see update on question....Downwards
E
2

Your connection is failing (for reasons outlined below), and because of an issue / upcoming-feature in node-ari-client, the failed connection is not logged.

The node-ari-client module uses Swagger, which expects to load a JSON schema describing an API. In the node-ari-client implementation, Swagger expects to find this JSON schema at %s//%s/ari/api-docs/resources.json.

So, the first thing to check is whether or not this exists / is accessible in your application:

https://192.168.46.122:8088/ari/api-docs/resources.json

There could be several reasons why this would not be available, but most likely the problem is authentication. You mention that when visiting your URL you are "prompted for a username and password". If your JSON schema (or any other files that need to be accessed without credentials) are behind authentication, you are going to need to rethink your application structure.

Currently, if there is a connection failure before Swagger has loaded the JSON schema, node-ari-client will fail silently. There is a Pull Request waiting which addresses this issue and would log the error, but in the meantime you should address the underlying issues which are preventing the connection.

If you can successfully access resources.json, there may be other issues with accessing resources. The URL you describe is accessing your service over https, but your resources.json file is telling Swagger to access it over regular http. To handle this, you could try:

Changing the basePath in your Swagger schema to use https:

"basePath": "https://192.168.46.122:8088/ari",

Adding a protocols field to your Swagger schema:
"protocols":["http", "https"]

Removing https
This is probably a good option in order to discover if https is the cause of the connection issue. Simply keep the Swagger schema exactly as is and try accessing / connecting to your services over http. Does this make a difference?

Enamour answered 19/4, 2016 at 9:23 Comment(3)
Thanks for looking into this, greatly appreciated :) See 'Update 2' in my original post. ThanksDownwards
Nice work mate!! It's an SSL issue... the 100 rep is all yours ;-)Downwards
Side question: where can I find the Swagger schema? I haven't got Swagger installed as separate node module, I think it was just dragged in when I installed the ari-client?Downwards

© 2022 - 2024 — McMap. All rights reserved.