Ari app deactivation

Hi!

I am using nodejs, and at the end of a call, sometimes, the app I use closed with the websocket connection and sometimes not.
How to force the app deactivation/shut down from the code please? I am using ari-client.

Thanks a lot!

There is a “hangup” function, highlighted in several of the helpful node-ari-client examples, have you tried that ?

If you’re using the ari-client library in Node.js for Asterisk ARI integration and you want to forcibly terminate the application at the end of a call, you can achieve this by handling the appropriate events and then calling the process.exit() method to exit the Node.js process.

Here’s a general outline of how you can implement this:

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

// Connect to Asterisk
ari.connect('http://localhost:8088', 'username', 'password', (err, client) => {
  if (err) {
    console.error('Error connecting to ARI:', err);
    return;
  }

  // Handle StasisEnd event to detect when the call ends
  client.on('StasisEnd', (event, channel) => {
    // Check if this is the call you're interested in
    // For example, check the channel ID or any other relevant information

    // Perform any cleanup or logging operations here

    // Forcefully shut down the application
    process.exit(0);
  });

  // Start your ARI application logic here
});

// Handle process termination to gracefully disconnect from Asterisk
process.on('exit', () => {
  // Disconnect from Asterisk
  ari.disconnect();

  console.log('Application terminated');
});

In this code:

  • We connect to Asterisk using ari.connect() method.
  • We listen for the StasisEnd event, which is emitted when the call ends.
  • Inside the event handler, you can perform any necessary cleanup or logging operations.
  • Finally, we use process.exit(0) to forcibly terminate the Node.js process.

Make sure to replace 'http://localhost:8088', 'username', and 'password' with your actual Asterisk ARI endpoint and credentials.

Best Regard
Danish Hafeez | QA Assistant
ICTInnovations

Hi @penguinpbx

Thanks for your answer. I did not see the notification about it sorry for the late response.
I use the hangup function.
My problem is that at the end of a call I have
Deactivating Stasis app XXX

and when I originate the next call :

Creating Stasis app 'New XXX'
 Shutting down application 'XXX'
 Destroying Stasis app XXX
    -- Remove stasis-XXX/h/1, registrar=res_stasis; con=stasis-XXX(0x7f372400afb0); con->root=0x7f372400b3a0
    -- Remove stasis-XXX/_./1, registrar=res_stasis; con=stasis-XXX(0x7f372400afb0); con->root=0x7f37240

To precise my answer, I am on the same process because the nodejs-code is called from a server.

Hi,

Thanks for your answer.
Unfortunatly, this solution is not possible for me ( I used to work with process.exit() but now I can’t because my code is running on a server to be called from another one.

Thanks a lot

That is very globby dial pattern. It may be matching more than you planned.

Unfortunately, the translation is making it difficult to understand the problem further. Posting some additional verbose logs, dial plan, etc., may help others debug further.

What does it mean?

Thanks

It means “_.”.

Sorry I don’t understand…

_. matches everything that is is isn’t an empty string, so, in particular, it matches h, e, i, and other special extension names.

I’m not sure if it is treated literally, or as a pattern, here.

Thanks!
There is a relation with the fact that the APP is destroyed only when a new call is done? One extension is called in the new APP and destroy the previous one by leaving?

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