Repository navigation
feat(desktop): implement upload speed test and health check for instant mode #2433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+922
−0
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ea1e876
feat(desktop): implement upload speed test and health check for insta…
gilnett 58fccf2
fix(desktop): address review feedback on effect api, tauri http, and …
gilnett 623cd88
fix(web): harden health endpoint against DoS with payload limits and …
gilnett 0f73df4
fix(desktop): eliminate latency distortion in speed test and restore …
gilnett cc14a31
fix(desktop): prevent stale health checks from overwriting recovery a…
gilnett 1d50783
fix(desktop): add stopped guard to health monitoring, fix test mock r…
gilnett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
apps/desktop/src/components/network-health-indicator.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import { cx } from "cva"; | ||
| import { Show } from "solid-js"; | ||
| import Tooltip from "~/components/Tooltip"; | ||
| import { | ||
| isRecordingInProgress, | ||
| networkHealth, | ||
| runSpeedTest, | ||
| runUploadHealthCheck, | ||
| speedTest, | ||
| } from "~/utils/network-health"; | ||
| import IconLucideAlertTriangle from "~icons/lucide/alert-triangle"; | ||
| import IconLucideRefreshCw from "~icons/lucide/refresh-cw"; | ||
| import IconLucideWifi from "~icons/lucide/wifi"; | ||
|
|
||
| interface NetworkHealthIndicatorProps { | ||
| class?: string; | ||
| } | ||
|
|
||
| export default function NetworkHealthIndicator( | ||
| props: NetworkHealthIndicatorProps, | ||
| ) { | ||
| const isUnhealthy = () => networkHealth().status === "unhealthy"; | ||
| const isChecking = () => | ||
| networkHealth().status === "checking" || speedTest().status === "running"; | ||
| const isRecording = isRecordingInProgress; | ||
|
|
||
| const handleRefresh = async (e: MouseEvent) => { | ||
| e.stopPropagation(); | ||
| if (isRecording() || isChecking()) return; | ||
| await runUploadHealthCheck(); | ||
| await runSpeedTest(); | ||
| }; | ||
|
|
||
| const speedLabel = () => { | ||
| if (speedTest().status === "running") return "Testing..."; | ||
| if (speedTest().status === "error" && speedTest().speedMbps === null) | ||
| return "Failed"; | ||
| if (speedTest().speedMbps !== null) return `${speedTest().speedMbps} Mbps`; | ||
| if (networkHealth().status === "checking") return "Checking..."; | ||
| if (isUnhealthy()) return "Offline"; | ||
| return "Ready"; | ||
| }; | ||
|
|
||
| const qualityLabel = () => { | ||
| const label = speedTest().recommendedLabel; | ||
| return label ? `${label}` : "1080p"; | ||
| }; | ||
|
|
||
| const dotColor = () => { | ||
| if (isUnhealthy()) return "bg-red-9"; | ||
| if (speedTest().status === "running") return "bg-blue-9 animate-pulse"; | ||
| if (speedTest().status === "error" && speedTest().speedMbps === null) | ||
| return "bg-red-9"; | ||
| const speed = speedTest().speedMbps; | ||
| if (speed === null) return "bg-gray-8"; | ||
| if (speed >= 15) return "bg-green-9"; | ||
| if (speed >= 5) return "bg-blue-9"; | ||
| return "bg-amber-9"; | ||
| }; | ||
|
|
||
| const tooltipContent = () => ( | ||
| <div class="flex flex-col gap-1 p-1 text-left text-xs min-w-44"> | ||
| <div class="flex items-center justify-between font-semibold"> | ||
| <span>Network Health</span> | ||
| <span | ||
| class={cx( | ||
| "text-[10px] uppercase font-bold", | ||
| isUnhealthy() || speedTest().status === "error" | ||
| ? "text-red-10" | ||
| : "text-green-10", | ||
| )} | ||
| > | ||
| {isUnhealthy() || | ||
| (speedTest().status === "error" && speedTest().speedMbps === null) | ||
| ? "Error" | ||
| : "Operational"} | ||
| </span> | ||
| </div> | ||
| <div class="flex items-center justify-between text-gray-11"> | ||
| <span>Upload Speed:</span> | ||
| <span class="font-medium text-gray-12">{speedLabel()}</span> | ||
| </div> | ||
| <div class="flex items-center justify-between text-gray-11"> | ||
| <span>Recommended Quality:</span> | ||
| <span class="font-medium text-gray-12">{qualityLabel()}</span> | ||
| </div> | ||
| <Show when={networkHealth().error || speedTest().error}> | ||
| <div class="mt-1 rounded bg-red-3 p-1.5 text-[11px] text-red-11 border border-red-6"> | ||
| {networkHealth().error ?? speedTest().error} | ||
| </div> | ||
| </Show> | ||
| <div class="mt-1 pt-1 border-t border-gray-6 flex justify-end"> | ||
| <button | ||
| type="button" | ||
| onClick={handleRefresh} | ||
| disabled={isRecording() || isChecking()} | ||
| class="flex items-center gap-1 text-[11px] text-gray-11 hover:text-gray-12 disabled:opacity-50" | ||
| > | ||
| <IconLucideRefreshCw | ||
| class={cx("size-3", isChecking() && "animate-spin")} | ||
| /> | ||
| <span>Retest Speed</span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| return ( | ||
| <div | ||
| class={cx("inline-flex items-center gap-1.5 select-none", props.class)} | ||
| > | ||
| <Tooltip content={tooltipContent()}> | ||
| <button | ||
| type="button" | ||
| onClick={handleRefresh} | ||
| disabled={isRecording()} | ||
| aria-label="Network health and speed indicator" | ||
| class={cx( | ||
| "flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[11px] transition-colors border", | ||
| isUnhealthy() || | ||
| (speedTest().status === "error" && speedTest().speedMbps === null) | ||
| ? "bg-red-3 text-red-11 border-red-6 hover:bg-red-4" | ||
| : "bg-gray-2 text-gray-11 border-gray-6 hover:bg-gray-3 hover:text-gray-12", | ||
| )} | ||
| > | ||
| <Show | ||
| when={ | ||
| !isUnhealthy() && | ||
| !( | ||
| speedTest().status === "error" && speedTest().speedMbps === null | ||
| ) | ||
| } | ||
| fallback={<IconLucideAlertTriangle class="size-3 text-red-9" />} | ||
| > | ||
| <span class={cx("size-1.5 rounded-full shrink-0", dotColor())} /> | ||
| <IconLucideWifi class="size-3 shrink-0" /> | ||
| </Show> | ||
| <span class="font-medium truncate max-w-20"> | ||
| {isUnhealthy() ? "Upload Error" : speedLabel()} | ||
| </span> | ||
| </button> | ||
| </Tooltip> | ||
| </div> | ||
| ); | ||
| } | ||
| export { NetworkHealthIndicator }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new file
NetworkHealthIndicator.tsxuses a PascalCase filename. The repository guide requires kebab-case filenames while keeping component names PascalCase. Rename the file tonetwork-health-indicator.tsxand update its import. This repository requirement must be satisfied before merging.Context Used: AGENTS.md (source)
Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!