Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventEmitter(catch like 'StasisStart') #157

Open
LabelMinsk opened this issue May 13, 2023 · 1 comment
Open

EventEmitter(catch like 'StasisStart') #157

LabelMinsk opened this issue May 13, 2023 · 1 comment

Comments

@LabelMinsk
Copy link

LabelMinsk commented May 13, 2023

I have trying fetching data from Asterisk (ARI) and can`t catch events. When nodemon started i can get some data(what i want like channels ari.channels.list(()=>...)), but if call is incoming i cant catch data realtime and i need reload server for grab data(like phone number). Thank you so much! P.s. stackoverflow dont work on this question...

  • Asterisk version - 13
  • Node version - 18.15
  • ARI client version - 2.2.0

Simple code:

server.js
Screenshot_2

`const http = require('http');
const app = require('./app');

const PORT = process.env.PORT || 3008;

http.createServer(app)
.listen(PORT, 'localhost', () => {
console.log(PORT)
})`

and second with logic app.js:
Screenshot_1

`const express = require('express');
const util = require('util');
require('dotenv').config();

const app = express();

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

const config = {
host: process.env.ARI_HOST,
user: process.env.ARI_USER,
pass: process.env.ARI_PASS
}

client.connect(config.host, config.user, config.pass, client_loaded);

function client_loaded (err, ari) {
if (err) {
throw err; // program will crash if it fails to connect
}

//GRAB phone number
ari.channels.list((err, channels) => {
channels.forEach(channel => {
console.log(channel.caller.number)
})
})

//Events doesn`t work
ari.on('StasisStart', ()=> console.log('work pls;)'));

///.......
ari.start('hello');
}`

@dorlanpabon
Copy link

Good morning @LabelMinsk , for get events, you have edit config in dialplan of asterisk an execute Stasis application
https://docs.asterisk.org/Asterisk_20_Documentation/API_Documentation/Dialplan_Applications/Stasis/

example

exten => _X.,n,Stasis(YOUR_NAME_APP_ARI , props);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants