node-esl icon indicating copy to clipboard operation
node-esl copied to clipboard

Reconnect esl Connection if connection drops

Open peili opened this issue 10 years ago • 1 comments

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?

peili avatar Jun 06 '14 08:06 peili

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).

englercj avatar Jun 07 '14 23:06 englercj