Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a reconnect option #2

Merged
merged 4 commits into from May 14, 2016
Merged

Conversation

chrisDeFouRire
Copy link

Hi ! I've added a "reconnect" option to the Websocket component.

How it's used :
<Websocket reconnect={10} debug={true} url='ws://localhost:8080/' onMessage={this.handleData}/>

If disconnected, the component will wait between 0 and 10 seconds before attempting a reconnection. The randomness avoids a storm of reconnections in case of server restart.

I've tried using ws.resume() instead of recreating the websocket entirely but it fails to work sometimes. Recreating the ws from scratch shows no ill effect.

If reconnection fails, it will attempt a new reconnection later, and so on...

I tried to stick to your code conventions...

@chrisDeFouRire
Copy link
Author

I've added a test to prevent reconnection after the WebSocket component is unmounted

@pimvoeten pimvoeten merged commit e6dd97d into mehmetkose:master May 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants