Skip to content

Commit

Permalink
feat(proxy): single proxy node latency testing state indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Sep 24, 2023
1 parent 8f8a54a commit 0052ce4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
11 changes: 9 additions & 2 deletions src/components/ProxyNodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ProxyNodeCard = (props: {
isSelected?: boolean
onClick?: () => void
}) => {
const { proxyLatencyTest } = useProxies()
const { proxyLatencyTest, proxyLatencyTestingMap } = useProxies()
const { proxyName, isSelected, onClick } = props
const { proxyNodeMap } = useProxies()
const proxyNode = createMemo(() => proxyNodeMap()[proxyName])
Expand Down Expand Up @@ -38,7 +38,14 @@ export const ProxyNodeCard = (props: {

<Button
class="btn-circle btn-ghost btn-sm"
icon={<IconBrandSpeedtest />}
icon={
<IconBrandSpeedtest
class={twMerge(
proxyLatencyTestingMap()[proxyName] &&
'animate-pulse text-success',
)}
/>
}
onClick={(e) => {
e.stopPropagation()

Expand Down
19 changes: 12 additions & 7 deletions src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export default () => {
proxyProviderLatencyTest,
collapsedMap,
setCollapsedMap,
latencyTestingMap,
healthCheckingMap,
proxyGroupLatencyTestingMap,
proxyProviderLatencyTestingMap,
isAllProviderUpdating,
updatingMap,
} = useProxies()
Expand Down Expand Up @@ -170,14 +170,16 @@ export default () => {

<Button
class="btn-circle btn-sm"
disabled={latencyTestingMap()[proxyGroup.name]}
disabled={
proxyGroupLatencyTestingMap()[proxyGroup.name]
}
onClick={(e) =>
onProxyGroupLatencyTestClick(e, proxyGroup.name)
}
icon={
<IconBrandSpeedtest
class={twMerge(
latencyTestingMap()[proxyGroup.name] &&
proxyGroupLatencyTestingMap()[proxyGroup.name] &&
'animate-pulse text-success',
)}
/>
Expand Down Expand Up @@ -264,7 +266,9 @@ export default () => {

<Button
class="btn btn-circle btn-sm"
disabled={healthCheckingMap()[proxyProvider.name]}
disabled={
proxyProviderLatencyTestingMap()[proxyProvider.name]
}
onClick={(e) =>
onProxyProviderLatencyTestClick(
e,
Expand All @@ -274,8 +278,9 @@ export default () => {
icon={
<IconBrandSpeedtest
class={twMerge(
healthCheckingMap()[proxyProvider.name] &&
'animate-pulse text-success',
proxyProviderLatencyTestingMap()[
proxyProvider.name
] && 'animate-pulse text-success',
)}
/>
}
Expand Down
52 changes: 31 additions & 21 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ type ProxyInfo = {
}

const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap()
const { map: latencyTestingMap, setWithCallback: setLatencyTestingMap } =
useStringBooleanMap()
const { map: healthCheckingMap, setWithCallback: setHealthCheckingMap } =
useStringBooleanMap()
const {
map: proxyLatencyTestingMap,
setWithCallback: setProxyLatencyTestingMap,
} = useStringBooleanMap()
const {
map: proxyGroupLatencyTestingMap,
setWithCallback: setProxyGroupLatencyTestingMap,
} = useStringBooleanMap()
const {
map: proxyProviderLatencyTestingMap,
setWithCallback: setProxyProviderLatencyTestingMap,
} = useStringBooleanMap()
const { map: updatingMap, setWithCallback: setUpdatingMap } =
useStringBooleanMap()
const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false)
Expand Down Expand Up @@ -123,21 +131,22 @@ export const useProxies = () => {
}
}

const proxyLatencyTest = async (proxyName: string) => {
const { delay } = await proxyLatencyTestAPI(
proxyName,
urlForLatencyTest(),
latencyTestTimeoutDuration(),
)
const proxyLatencyTest = (proxyName: string) =>
setProxyLatencyTestingMap(proxyName, async () => {
const { delay } = await proxyLatencyTestAPI(
proxyName,
urlForLatencyTest(),
latencyTestTimeoutDuration(),
)

setLatencyMap((latencyMap) => ({
...latencyMap,
[proxyName]: delay,
}))
}
setLatencyMap((latencyMap) => ({
...latencyMap,
[proxyName]: delay,
}))
})

const proxyGroupLatencyTest = async (proxyGroupName: string) =>
setLatencyTestingMap(proxyGroupName, async () => {
const proxyGroupLatencyTest = (proxyGroupName: string) =>
setProxyGroupLatencyTestingMap(proxyGroupName, async () => {
const newLatencyMap = await proxyGroupLatencyTestAPI(
proxyGroupName,
urlForLatencyTest(),
Expand All @@ -152,7 +161,7 @@ export const useProxies = () => {
await fetchProxies()
})

const updateProviderByProviderName = async (providerName: string) =>
const updateProviderByProviderName = (providerName: string) =>
setUpdatingMap(providerName, async () => {
try {
await updateProxyProviderAPI(providerName)
Expand All @@ -175,16 +184,17 @@ export const useProxies = () => {
}

const proxyProviderLatencyTest = (providerName: string) =>
setHealthCheckingMap(providerName, async () => {
setProxyProviderLatencyTestingMap(providerName, async () => {
await proxyProviderLatencyTest(providerName)
await fetchProxies()
})

return {
collapsedMap,
setCollapsedMap,
latencyTestingMap,
healthCheckingMap,
proxyLatencyTestingMap,
proxyGroupLatencyTestingMap,
proxyProviderLatencyTestingMap,
updatingMap,
isAllProviderUpdating,
proxies,
Expand Down

0 comments on commit 0052ce4

Please sign in to comment.