From 5844deac1ab5325d9e14a6c0fb90c1f2be05ff01 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 31 Aug 2020 05:02:25 -0700 Subject: [PATCH] Periodically ping websocket to prevent it from being closed --- src/utils/connection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/connection.js b/src/utils/connection.js index d1c6798..8096d45 100644 --- a/src/utils/connection.js +++ b/src/utils/connection.js @@ -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 (