Closed ivahaev closed 10 years ago
Share your code with us my friend.
Sent from my iPhone
On 25/09/2014, at 18:03, ivahaev notifications@github.com wrote:
Hi, I have an issue. Everything work good, but one thing I don't understand. How can I start app when asterisk is not available? When it happens, application finished with error:
Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect as oncomplete
I have tried to wrap initialization into try-catch, but it didn't help.
— Reply to this email directly or view it on GitHub.
Very simple code:
var config = require('../config'),
AsteriskManager = require("asterisk-manager"),
ami;
asteriskReconnect();
console.log("end file");
function asteriskConnect() {
ami = new AsteriskManager(
config.get('asterisk:port') || 5038,
config.get('asterisk:host'),
config.get('asterisk:username'),
config.get('asterisk:secret'),
true
);
ami.on('managerevent', allEventsListener);
ami.on('close', function () {
console.log('Connection with asterisk closed!');
asteriskReconnect();
});
}
function asteriskReconnect() {
setTimeout(asteriskConnect(), 500);
}
function allEventsListener(evt) {
console.log(evt);
}
And I try to change asteriskConnect function:
try {
ami = new AsteriskManager(
config.get('asterisk:port') || 5038,
config.get('asterisk:host'),
config.get('asterisk:username'),
config.get('asterisk:secret'),
true
);
} catch (e) {
console.log(e);
}
It usually means that the port you're trying to use its already taken. Try to use a different port... or... Try to connect via telnet in yout config.get('asterisk:host') 5038 and see what happens.
AMI works with no problem. When asterisk is running, application connects well, but when I manually shutdown the asterisk, application falls with error. That is the problem. Application can't start when asterisk is not running. I think, it needs an extra argument when creating instance of asterisk-manager - callback function with possible connection error.
It is because you are not handling the exception. Every node app crashes when a no handled exception occurs.
[]'s Igor
On 28/09/2014, at 04:06, ivahaev notifications@github.com wrote:
AMI works with no problem. When asterisk is running, application connects well, but when I manually shutdown the asterisk, application falls with error. That is the problem. Application can't start when asterisk is not running;
— Reply to this email directly or view it on GitHub.
And I try to change asteriskConnect function:
try {
ami = new AsteriskManager(
config.get('asterisk:port') || 5038,
config.get('asterisk:host'),
config.get('asterisk:username'),
config.get('asterisk:secret'),
true
);
} catch (e) {
console.log(e);
}
But app still crashes with error.
Yeah but I don't think that is going to work. Google a little bit more about more about the subject.
[]'s Igor
On 28/09/2014, at 11:05, ivahaev notifications@github.com wrote:
And I try to change asteriskConnect function:
try { ami = new AsteriskManager( config.get('asterisk:port') || 5038, config.get('asterisk:host'), config.get('asterisk:username'), config.get('asterisk:secret'), true ); } catch (e) { console.log(e); }
But app still crashes with error.— Reply to this email directly or view it on GitHub.
@ivahaev It's because try-catch cannot catch exceptions from asynchronous operations, which new Asteriskmanager() is performing. We have to use: process.on('uncaughtException', function (err) { console.error(err); });
Hi, I have an issue. Everything work good, but one thing I don't understand. How can I start app when asterisk is not available? When it happens, application finished with error:
Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect as oncomplete
I have tried to wrap initialization into try-catch, but it didn't help.