pipobscure / NodeJS-AsteriskManager

NodeJS Asterisk Manager API
Other
246 stars 102 forks source link

reconnect #29

Closed celevra closed 9 years ago

celevra commented 9 years ago

Hi,

thank you very much for this library. I've wasted half a live with a php library... but is there something like a disconnect event or a reconnect mechanism?

regards

celevra

igorescobar commented 9 years ago

There is a connect() & disconnect() method that you could use on your AMI instance.

celevra commented 9 years ago

yes but how do i know when i got disconnected? is there an event?

igorescobar commented 9 years ago

Are you having problems to keep the connection alive?

celevra commented 9 years ago

we are starting and stopping asterisk very often because it is our development system. If we do so, the node application gets disconnected and doesn't reconnect automaticly, i'm searching for a way to reconnect automaticly or ifinitly

igorescobar commented 9 years ago

So it's the perfect timing for you test the improvement I'm doing: https://github.com/pipobscure/NodeJS-AsteriskManager/issues/30

igorescobar commented 9 years ago

Make sure to call AMIInstance.keepConnected();

celevra commented 9 years ago
var ami = new require('asterisk-manager')('5038','127.0.0.1','admin','xxx', true);
ami.keepConnected();

ami.on('confbridgejoin', function(evt) {
        console.log('NEW JOIN');
        console.log(evt.conference+', '+evt.calleridnum);
});

ami.on('confbridgeleave', function(evt) {
        console.log('NEW LEAVE');
        console.log(evt.conference+', '+evt.calleridnum);
});

ami.on('confbridgetalking', function(evt) {
        console.log('TALKÍNG');
        console.log(evt);
});

when i do service asterisk restart

i get the following error:

Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect as oncomplete

before all that i've done a git clone in the node_modules folder

igorescobar commented 9 years ago

Yes, the error will be logged but the important thing is that your code is still running correctly. is it?

celevra commented 9 years ago

no it isn't, sorry

igorescobar commented 9 years ago

What stopped working?

Everything works fine before the restart and after it stops ?

I've tested those scenarios and everything works fine... :/

[]'s Igor

On 02/12/2014, at 18:47, celevra notifications@github.com wrote:

no it isn't, sorry

— Reply to this email directly or view it on GitHub.

celevra commented 9 years ago

i start the mentioned code with node asterisk.js

then i restart asterisk and after it's stopped it drops the error and exits

is there something else i can provide?

igorescobar commented 9 years ago

Yeah, this is happening because you're not handling the exception: http://nodejs.org/docs/latest/api/process.html#process_event_uncaughtexception

process.on('uncaughtException', function(err) {
  console.log('Caught exception: ' + err);
});

Try absorbing this exception and test it again.

igorescobar commented 9 years ago

I think that my tests are working fine because I am handling those exceptions.

igorescobar commented 9 years ago

@celevra Did it work?

celevra commented 9 years ago

works like a charm! Thank you very much!