mirror of
https://github.com/dergigi/boris.git
synced 2025-12-31 13:34:30 +01:00
Change relay status polling from 5s (default) and 2s (Settings/Indicator) to 20s across the board to reduce CPU usage and network requests
38 lines
900 B
TypeScript
38 lines
900 B
TypeScript
import { useState, useEffect } from 'react'
|
|
import { RelayPool } from 'applesauce-relay'
|
|
import { RelayStatus, updateAndGetRelayStatuses } from '../services/relayStatusService'
|
|
|
|
interface UseRelayStatusParams {
|
|
relayPool: RelayPool | null
|
|
pollingInterval?: number // in milliseconds
|
|
}
|
|
|
|
export function useRelayStatus({
|
|
relayPool,
|
|
pollingInterval = 20000
|
|
}: UseRelayStatusParams) {
|
|
const [relayStatuses, setRelayStatuses] = useState<RelayStatus[]>([])
|
|
|
|
useEffect(() => {
|
|
if (!relayPool) return
|
|
|
|
const updateStatuses = () => {
|
|
const statuses = updateAndGetRelayStatuses(relayPool)
|
|
setRelayStatuses(statuses)
|
|
}
|
|
|
|
// Initial update
|
|
updateStatuses()
|
|
|
|
// Poll for updates
|
|
const interval = setInterval(updateStatuses, pollingInterval)
|
|
|
|
return () => {
|
|
clearInterval(interval)
|
|
}
|
|
}, [relayPool, pollingInterval])
|
|
|
|
return relayStatuses
|
|
}
|
|
|