pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Option to not reconnect when server closes connection #78

Closed masad-frost closed 5 years ago

masad-frost commented 6 years ago

In the initial release of v4 close events coming from server did not trigger a reconnect. Which meant I was able to reconnect conditionally. My use case is that if a disconnect happens for a specific reason I don't want the client to retry. I can handle reconnection myself by calling reconnect.

pladaria commented 5 years ago

Hi,

Thanks for reporting. You can do that using latest version of the lib:

rws.addEventListener('close', e => {
    if (e.code === SOME_CODE) { // you could also check the reason
        rws.close(); // this keep closed and stop trying to reconnect
    }
});

Please, reopen this issue if that doesn't work for you