fix: connect websocket when the component mounts (#5456)
This commit is contained in:
parent
4e2972782f
commit
0e81e0e2a8
1 changed files with 6 additions and 5 deletions
|
|
@ -111,10 +111,7 @@ const NetworkIndicator = ({
|
|||
};
|
||||
|
||||
const handleConnectionChange = ({hasInternet}: ConnectionChangedEvent) => {
|
||||
if (firstRun.current) {
|
||||
firstRun.current = false;
|
||||
handleWebSocket(true);
|
||||
} else {
|
||||
if (!firstRun.current) {
|
||||
if (!hasInternet) {
|
||||
setConnected(false);
|
||||
}
|
||||
|
|
@ -150,6 +147,11 @@ const NetworkIndicator = ({
|
|||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
handleWebSocket(true);
|
||||
firstRun.current = false;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const networkListener = networkConnectionListener(handleConnectionChange);
|
||||
return () => networkListener.removeEventListener();
|
||||
|
|
@ -168,7 +170,6 @@ const NetworkIndicator = ({
|
|||
useEffect(() => {
|
||||
const handleAppStateChange = stateChange(async (appState: AppStateStatus) => {
|
||||
const active = appState === 'active';
|
||||
|
||||
handleWebSocket(active);
|
||||
|
||||
if (active) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue