-
Notifications
You must be signed in to change notification settings - Fork 270
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
Added ability to check connectivity regularly #32
Conversation
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? |
Hi @rauliyohmc, My main use-case is when I use a custom pingUrl for it to ping my server. |
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 |
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 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? |
@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. |
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. |
Sounds good! 🙂 |
I would love to see this merged. |
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. |
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? |
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. |
Hi @rauliyohmc, Will do during the day! |
Would be great to see this feature merged. Will be very helpful for a lot of people. |
de55584
to
ec1a11c
Compare
ec1a11c
to
77984fe
Compare
@rauliyohmc : There you go 😄 |
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 ? 🙂