pusher / pusher-websocket-react-native

React Native official Pusher SDK
MIT License
61 stars 52 forks source link

Randomly not working #129

Open fabiendeborde opened 8 months ago

fabiendeborde commented 8 months ago

Hello, I finally got it to work by using a single file as a hook at the top of my app. I am monitoring the connection status as some people said it was randomly disconnecting, using the onConnectionStateChange method in pusher.init, and so far it didn't disconnect...but, after some time it stops receiving events.

My app is a one screen, always awake dashboard. After about 30 minutes (i feel like the duration is pretty random), the app stops receiving events, but the onConnectionStateChange didn't change at all. I am logging the following:

Am I missing something during initialization ? (I used to use the previous pusher-js/react-native and this never happened)

benw-pusher commented 8 months ago

Is the app open and active during this time? If the app is closed/backgrounded then it could be that the connection is terminated at the OS level, but the app is not active or permitted to run the necessary code to detect the connection state change, which is why there is no logging present.

fabiendeborde commented 8 months ago

Thanks for your answer @benw-pusher ! The app is open and active all day, but I close it during the night. I will try to see if I can find a way to resume the connection when the app is active again.

I have no idea why, but today the connection seems to stay active a lot longer than usual (about 5h for now) I'll try to give more information tomorrow if I can.

benw-pusher commented 7 months ago

Hi @fabiendeborde did you see the improved behaviour persist?

fabiendeborde commented 7 months ago

Hey @benw-pusher , sorry I was extra busy at work...

Sometimes when the app comes back from device sleep the connection is still active, sometimes it is not. I am not doing much mobile app so I can't say for sure but seems like it's coming from the OS will... :)

To be sure I made a status badge (which is quite accurate), and a button next to it to reconnect when needed.

I don't remember having to handle reconnection in the previous package, but the app was made about 2~3 years ago, so it might be OS related and not a problem from this library.

I hope the feedback helped.