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 ability to check connectivity regularly #32

Conversation

adrienthiery
Copy link
Contributor

Hi there @rauliyohmc !

Thanks for the awesome lib. Super helpful.

I noticed an issue in my case, though.
It is that is check the connectivity only at startup, so I added an option so it checks regularly for connection and by default, it keeps the exact same behaviour that you had.

What do you think ? 🙂

@rgommezz
Copy link
Owner

Hi @adrienthiery, thanks for the PR.

I am trying to understand the use case. Since the listener will trigger any time the connection changes, what's the point on checking connectivity regularly? Could you maybe elaborate better with an example?

@adrienthiery
Copy link
Contributor Author

Hi @rauliyohmc,

My main use-case is when I use a custom pingUrl for it to ping my server.
For example, if my server is down for some reason (maintenance, etc.), I'd like for the clients to act as if they were offline, instead of handling it as an error.

@adrienthiery
Copy link
Contributor Author

It also means it does an effective check if connectivity to my server so if the connection is bad but I'm still on the network, then my app shows up as offline. That's the behaviour that I want

@rgommezz
Copy link
Owner

rgommezz commented Aug 26, 2017

If you server is down for some reason and you'd like the clients to act as if they were offline, I think you can easily do that (assuming you are using redux).

Just import the internal action creator, catch the server error and dispatch yourself the action to state offline mode. Something along these lines:

import { offlineActionTypes } from 'react-native-offline';
...
fetch(`${YOUR_SERVER_ENDPOINT}`)
  .then(response => // do something)
  .catch(error => dispatch({ type: offlineActionTypes.CONNECTION_CHANGE, payload: false }))

Would that suffice your main use-case?

@adrienthiery
Copy link
Contributor Author

@rauliyohmc I could do that, but then I would need to recreate the same structure you have in redux-offline to get a singleton of an interval checking regularly the connectivity, and I thought some other people might want this feature as well, it's really awesome to have my app bound to the "state" of my server almost instantly.

@rgommezz
Copy link
Owner

rgommezz commented Sep 2, 2017

I saw you are a speaker of the React Native EU conference coming next week. I'll be there giving a workshop and attending the talks as well, so we can discuss further in person :)

I would like to prioritise this PR first (see both comments), mainly to decouple the redux part from the higher order component and create an event emitter/subscriber system that will work for all cases.

I am also thinking we could add support for websockets if you use a custom server. That way we can move from polling to server push notifications.

@adrienthiery
Copy link
Contributor Author

Sounds good! 🙂

@raduflp
Copy link

raduflp commented Oct 6, 2017

I would love to see this merged.
Another argument would be that sometimes it takes a while for the underlying OS to update the internet connection status, so regular checks would make the app more responsive.

@kraffslol
Copy link

I agree with @raduflp. I have some issues on android devices where they can't pick up internet connection fast enough. The fetch call in checkInternetAccess.js instantly throws and returns false. This would be great if it needs to retry.

@rgommezz
Copy link
Owner

rgommezz commented Oct 30, 2017

Hey @adrienthiery, since this people would find this useful and it's opt-in feature, let's merge it :)

Could you please rebase and address the conflicts first?

@ValentinBlokhin
Copy link

Have the same issue. When I connected to wifi but no internet, there is no way to handle connection change when connection online after some time.

@adrienthiery
Copy link
Contributor Author

Hi @rauliyohmc,

Will do during the day!

@TyshkevichSergey
Copy link

Would be great to see this feature merged. Will be very helpful for a lot of people.

@adrienthiery adrienthiery force-pushed the feature/add-ability-to-recheck-connectivity-regularly branch from de55584 to ec1a11c Compare October 31, 2017 22:10
@adrienthiery adrienthiery force-pushed the feature/add-ability-to-recheck-connectivity-regularly branch from ec1a11c to 77984fe Compare October 31, 2017 22:13
@adrienthiery
Copy link
Contributor Author

@rauliyohmc : There you go 😄

@rgommezz rgommezz merged commit 7374c2b into rgommezz:master Nov 1, 2017
markvl91 pushed a commit to markvl91/react-native-offline that referenced this pull request Nov 7, 2017
markvl91 pushed a commit to markvl91/react-native-offline that referenced this pull request Nov 7, 2017
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.

6 participants