node-esl
node-esl copied to clipboard
Reconnect esl Connection if connection drops
In case FS gets restarted I also need to create new esl conection on node. Have you implemented a function which tries to reconnect in an interval in case connection to fs drops?
No I haven't, but it should be pretty easy to do with the esl::end
(emitted when connection to fsw is lost) or esl::event::disconnect::notice
(advisory event from fsw) events and a setTimeout
loop that tries to reconnect on an interval.
Something similar to:
var conn = null,
reconnectTimeout = null,
waitTime = 1000; //wait 1 sec between tries
function doConnect() {
//as of today there is no "connect" method, so you have to create a new object.
conn = new Connection();
//if there is an error, wait some time then try again
conn.on('error', function(err) {
//will need to check if this error is a connection error here, otherwise any error will trigger a new connection.
setTimeout(doConnect, waitTime);
});
}
doConnect();
This can be a little cleaner if I move the connection logic to a method that you can just call repeatedly, instead of creating a new object each time. Also it would be nice to have retry built in. I'll mark this as a feature request and get to it sometime if I can (also accepting pull requests).