reconnecting-websocket icon indicating copy to clipboard operation
reconnecting-websocket copied to clipboard

reconnect attempts only when ...

Open mschipperheyn opened this issue 9 years ago • 5 comments

In a mobile scenario, often the internet connection is not available. In that case it doesn't seem to make sense, and I wouldn't be surprised if it was detrimental to battery life, to keep trying to reconnect.

It might be interesting to add a function reference that returns a boolean on whether to attempt a reconnect at all. This function could in a mobile scenario return true if connected and false if offline.

mschipperheyn avatar Jun 10 '16 13:06 mschipperheyn

One of the interesting ways to do this is to have a variable timer. Start with 2s, if it doesnt reconnect go to 4, then 8 etc. Have an option to have a max time (E.g 3-5 mins). Once reconnected, the next reconnect timer (if disconnected) would start again at 2s. This should reduce drain on battery (it would be 20 polls at max time of 3 mins, as opposed to 1800 polls at a max time of 2s).

Looks like the author added "reconnectDecay", which should let you do this.

aparmar avatar Aug 24 '16 06:08 aparmar

I have implemented this based on an adapted version of a reconnection library. I can send this if ibterestibg. Only thing g I still need to do is deal with expired server sessions against a websocket that is still alive.

mschipperheyn avatar Aug 25 '16 20:08 mschipperheyn

robust-websocket allows you to fully configure when to reconnect via a function callback

nathanboktae avatar Oct 14 '16 05:10 nathanboktae

@nathanboktae I like the premise of where you are going with robust-websocket. However, can I suggest that we improve reconnecting-websocket to include tests and other things that you deem are missing? This project already has 1k+ followers. So rather than fork the userbase, I suggest adding to and improving this project.

-Amar

aparmar avatar Oct 14 '16 18:10 aparmar

I considered that @aparmar but there's too many issues with this library on fundamental levels that I started a new project fresh, especially with 0 tests. I have no idea how the library truly works without tests and contracts being validated constantly, and evidence to the users of that package that they are. Also, the maintainer seems not so active these days.

nathanboktae avatar Oct 14 '16 20:10 nathanboktae