Node Client ARI | Connect a method without bypassing the callback?

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

For this, I created a separate express application.

I have a properly configured launch instance of Asterisk 13. I know this because when I go to https://192.168.46.122:8088/ari/sounds in my browser, I am asked to enter a username and password, which when I enter it returns return JSON object with 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 app.js 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 problem is that anon callback never starts. I never see "HELLLLLOOOOOO !!"

Can someone shed some light on why / under what circumstances this can happen? Are there any known errors with the module that may be causing this?

Please let me know if you need more information about configuration, environment, etc.

Thanks guys,

UPDATE

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

There is no error and no "HELLLLLOOOOOO !!" at any point: - (

UPDATE 2

Just visited /ari/api-docs/resources.json and got the following answer ... so that it looks like it is present.

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

Now I think it could be an SSL problem ?!

+5
source share
1 answer

Your connection does not work (for the reasons indicated below), and due to a problem / upcoming function in the node-ari-client failed connection is not registered.

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

So the first thing to check is whether this is / is available in your application:

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

There may be several reasons why this will not be available, but most likely the problem is authentication. You mentioned that when you visit your URL, you "request a username and password." If your JSON scheme (or any other files that you need to access without credentials) is behind authentication, you will need to rethink your application structure.

Currently, if a connection fails before Swagger loads the JSON schema, node-ari-client will fail. There is a Pull Request that fixes this problem and logs an error, but at the same time you have to fix the main problems that prevent the connection,

If you can successfully access resources.json , other problems with accessing resources.json may occur. The URL you described accesses your service through https , but your resources.json file tells Swagger to access it through regular http. To handle this, you can try:

Changing basePath in your Swagger scheme to use https :

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

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

Https removal
This is probably a good option to find out if the reason https causing the connection problem. Just save the Swagger scheme exactly as it is, and try accessing your services via http . Does it matter?

+1
source

Source: https://habr.com/ru/post/1247227/


All Articles