forked from Shiloh/remnantchat
fix: expire network status checks
This commit is contained in:
parent
3977a82224
commit
a4b7c8e9ce
@ -11,6 +11,8 @@ export interface ConnectionTestResults {
|
|||||||
hasRelay: boolean
|
hasRelay: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pollInterval = 20 * 1000
|
||||||
|
|
||||||
export const useConnectionTest = () => {
|
export const useConnectionTest = () => {
|
||||||
const [hasHost, setHasHost] = useState(false)
|
const [hasHost, setHasHost] = useState(false)
|
||||||
const [hasRelay, setHasRelay] = useState(false)
|
const [hasRelay, setHasRelay] = useState(false)
|
||||||
@ -51,6 +53,17 @@ export const useConnectionTest = () => {
|
|||||||
handleHasRelayChanged
|
handleHasRelayChanged
|
||||||
)
|
)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
connectionTest.removeEventListener(
|
||||||
|
ConnectionTestEvents.HAS_HOST_CHANGED,
|
||||||
|
handleHasHostChanged
|
||||||
|
)
|
||||||
|
connectionTest.removeEventListener(
|
||||||
|
ConnectionTestEvents.HAS_RELAY_CHANGED,
|
||||||
|
handleHasRelayChanged
|
||||||
|
)
|
||||||
|
}, pollInterval)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await connectionTest.runRtcPeerConnectionTest()
|
await connectionTest.runRtcPeerConnectionTest()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -63,7 +76,7 @@ export const useConnectionTest = () => {
|
|||||||
;(async () => {
|
;(async () => {
|
||||||
while (true) {
|
while (true) {
|
||||||
await checkConnection()
|
await checkConnection()
|
||||||
await sleep(20 * 1000)
|
await sleep(pollInterval)
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}, [])
|
}, [])
|
||||||
|
Loading…
Reference in New Issue
Block a user