From a4b7c8e9ceb21a3b3288e5a29a9d817298341b5c Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Tue, 28 Mar 2023 07:46:43 -0500 Subject: [PATCH] fix: expire network status checks --- src/components/Shell/useConnectionTest.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/Shell/useConnectionTest.ts b/src/components/Shell/useConnectionTest.ts index 30867c5..024791d 100644 --- a/src/components/Shell/useConnectionTest.ts +++ b/src/components/Shell/useConnectionTest.ts @@ -11,6 +11,8 @@ export interface ConnectionTestResults { hasRelay: boolean } +const pollInterval = 20 * 1000 + export const useConnectionTest = () => { const [hasHost, setHasHost] = useState(false) const [hasRelay, setHasRelay] = useState(false) @@ -51,6 +53,17 @@ export const useConnectionTest = () => { handleHasRelayChanged ) + setTimeout(() => { + connectionTest.removeEventListener( + ConnectionTestEvents.HAS_HOST_CHANGED, + handleHasHostChanged + ) + connectionTest.removeEventListener( + ConnectionTestEvents.HAS_RELAY_CHANGED, + handleHasRelayChanged + ) + }, pollInterval) + try { await connectionTest.runRtcPeerConnectionTest() } catch (e) { @@ -63,7 +76,7 @@ export const useConnectionTest = () => { ;(async () => { while (true) { await checkConnection() - await sleep(20 * 1000) + await sleep(pollInterval) } })() }, [])