Periodically ping websocket to prevent it from being closed

This commit is contained in:
Gary Wang 2020-08-31 05:02:25 -07:00
parent b92ffc7bad
commit 5844deac1a
1 changed files with 8 additions and 0 deletions

View File

@ -39,6 +39,14 @@ export function ConnectionProvider({ children }) {
return () => connection.removeAccountChangeListener(id);
}, [connection]);
useEffect(() => {
const id = setInterval(
() => connection._rpcWebSocket.call('ping').catch(() => {}),
2000,
);
return () => clearInterval(id);
}, [connection]);
return (
<ConnectionContext.Provider
value={{ endpoint, setEndpoint, connection, sendConnection }}