Handling network switches

#1

Hi guys,

I’ve got an app which is using websockets. When the expo client switches from wifi to 4G, there is a temporary loss of connection (as expected). I’ve put some logic on the client. When the NetInfo (react native api) detects no connection I try to reconnect to the websocket, the expo app reconnects but I end up getting a full app refresh (the splash screen is relaunched etc.). I want to prevent the full app refresh, I just want to reconnect to the websocket. Is this something which is possible as frontend only solution, or do I need to implement something on the backend?
I’ve included something I’ve been reading - I don’t know if this similar to the problem I am facing?

https://smartfoxserver.com/blog/handling-network-switches-on-mobile-devices/

Many thanks

#2

Do you know why the full reload is being triggered? It’s not obvious to me why that would happen unless you put code in place to intentionally do that.
Switching from wifi from 4G definitely shouldn’t automatically restart an app unless you put code in there to explicitly do that.

#3

I’m using the same logic to reconnect to the websocket, that I use to connect to the websocket when I log in initially (including the same redux dispatches etc.), but I can’t see anything in the logic which would relaunch the app. I’ve checked the server, and the websocket is being disconnected, and when i reconnect I get a different sessionID. Do you think the different sessionID is relaunching the app. What are the things that reload the app? Also it’s not the switching from 4g to wifi which is reloading the app. Its when we reconnect to websocket with different sessionID which is doing the reloading of the app (I think).

#4

Hi @kashifceler! If you can follow https://stackoverflow.com/help/mcve it’d be much easier for us to help you out.

closed #5

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.