Can't connect Asterisk server using node module

Hello.

As I was trying to connect the node.js app to the Asterisk server, I met a problem.
I could follow this “Hello world” guide before I tried the node.js app. (Hello World - Asterisk Documentation)

I tried to connect the node app to the Asterisk server. Here is my code:

const client = require("ari-client");

const ENDPOINT = "PJSIP/100";

client.connect(
  "http://my_local_ip:5060",
  "username",
  "password",
  function (err, ari) {
    console.log("Connecting to Asterisk Package!");
    if (err) {
      console.log("Asterisk Error : ", err);
      return;
    }
  }
)

Here is an error I got:

Error: connect ECONNREFUSED 192.168.65.128:5060
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.65.128',
  port: 5060,
  name: 'HostIsNotReachable'
}

Any idea? How can I solve this problem?
Thank you.

If you’re trying to connect on a non-loopback address, it can be helpful to ensure that Asterisk is listening on that address. Otherwise stick to localhost or 127.0.0.1.

Thank you for your reply.
I tried it, but it doesn’t also work for localhost or 127.0.0.1

Are you doing this on the same machine where Asterisk is running?

You can check for listening ports with “ss -nlt” (new-style, iproute2) or “netstat -nlt” (old-style).

Yes, I am doing this on the same machine where Asterisk is running.

Would have been better to copy and paste the text rather than post a useless cropped screenshot.

Asterisk by default should be listening on port 5038. Is it there?

It’s not 5060?
And it’s not a useless cropped screenshot. It’s a full screenshot of the terminal. There are no more ports.

Here is an account configuration in Zoiper 5.
Domain: 192.168.65.128
Username: 6001
Password: *****

It could be connected to the Asterisk server.
But I can’t connect the node server to Asterisk.

Ah, OK, you are trying to make a SIP connection, not an Asterisk API connection. Yes, port 5060 should be it. But that’s not in your list of listening ports either.

Hmm, Asterisk API connection? I may misunderstand them (SIP con, Asterisk API).
How can I proceed with this? Kindly let me know step by step.
I need to add 5060 port to that list first?

On Tuesday 27 February 2024 at 05:16:12, Seymen2023 via Asterisk Community
wrote:

Hmm, Asterisk API connection? I may misunderstand them (SIP con, Asterisk
API). How can I proceed with this? Kindly let me know step by step.
I need to add 5060 port to that list first?

If you are trying to connect to the Asterisk Management Interface (AMI) then
that should be listening on TCP port 5038, and that is the port number your
application needs to connect to.

If instead you are trying to talk to Asterisk using SIP, then unless you have
told Asterisk otherwise, it will be listening on UDP port 5060, and that is
what your application needs to connect to. Trying to connect to TCP port 5060
will not work unless you tell Asterisk to listen for TCP SIP connections
(which is possible, but uncommon).

Maybe it would help if you were to explain what you want your application to
be able to do once it has connected to Asterisk.

Antony.


I bought a book on memory techniques, but I’ve forgotten where I put it.

                                               Please reply to the list;
                                                     please *don't* CC me.

I get what you mean basically, but I am not sure how can I proceed with this work step by step.
Kindly let me know the guidelines.

On Tuesday 27 February 2024 at 12:10:16, Seymen2023 via Asterisk Community
wrote:

I get what you mean basically, but I am not sure how can I proceed with
this work step by step. Kindly let me know the guidelines.

What are you trying to achieve?

What is your application, which talks to Asterisk, supposed to do?

Antony.


“The future is already here. It’s just not evenly distributed yet.”

  • William Gibson

                                                Please reply to the list;
                                                      please *don't* CC me.
    

I want to build my own VOIP system.
I will make some users and extensions and assign them to the users.
They will register their user accounts to Zoiper 5 and make calls through my website.
My website is connected to the node server and the node server uses the ari-client node module (Asterisk server). So I want to connect the node server to Asterisk in the node server first.

On Tuesday 27 February 2024 at 12:36:51, Seymen2023 via Asterisk Community
wrote:

I want to build my own VOIP system.
I will make some users and extensions and assign them to the users.
They will register their user accounts to Zoiper 5 and make calls through
my website. My website is connected to the node server and the node server
uses the ari-client node module (Asterisk server). So I want to connect
the node server to Asterisk in the node server first.

Thanks for that explanation. I shall now defer to someone who knows about
ARI, which I have never used.

Antony.


“640 kilobytes (of RAM) should be enough for anybody.”

  • Bill Gates

                                                Please reply to the list;
                                                      please *don't* CC me.
    

On Wednesday 28 February 2024 at 02:34:57, Seymen2023 via Asterisk Community
wrote:

When can I get reply from him?

I have no idea who “him” is.

I don’t know about ARI, so I can’t answer your question further. I hope that
someone else here can.

Antony.


I want to build a machine that will be proud of me.

  • Danny Hillis, creator of The Connection Machine

                                                Please reply to the list;
                                                      please *don't* CC me.
    

Hello,
If you have experience in ARI, please help me.
I need your help for ARI connection in node js server.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.