begin live server support

This commit is contained in:
Brian Beck 2026-03-09 12:38:40 -07:00
parent 0c9ddb476a
commit e4ae265184
368 changed files with 17756 additions and 7738 deletions

View file

@ -0,0 +1,53 @@
import { BsFillLightningChargeFill } from "react-icons/bs";
import { useLiveConnectionOptional } from "./LiveConnection";
import styles from "./JoinServerButton.module.css";
function formatPing(ms: number): string {
return ms >= 1000 ? ms.toLocaleString() + "ms" : ms + "ms";
}
export function JoinServerButton({
onOpenServerBrowser,
}: {
onOpenServerBrowser: () => void;
}) {
const live = useLiveConnectionOptional();
if (!live) return null;
const isLive = live.gameStatus === "connected";
const isConnecting =
live.gameStatus === "connecting" ||
live.gameStatus === "challenging" ||
live.gameStatus === "authenticating";
return (
<button
type="button"
className={styles.Root}
aria-label={isLive ? "Disconnect" : "Join server"}
title={isLive ? "Disconnect" : "Join server"}
onClick={() => {
if (isLive) {
live.disconnectServer();
} else {
onOpenServerBrowser();
}
}}
data-active={isLive ? "true" : undefined}
>
<BsFillLightningChargeFill
className={`${styles.LiveIcon} ${isLive ? styles.Pulsing : ""}`}
/>
{!isLive && (
<span className={styles.TextLabel}>
{isConnecting ? "Connecting..." : "Connect"}
</span>
)}
{isLive && (
<span className={styles.PingLabel}>
{live.ping != null ? formatPing(live.ping) : "Live"}
</span>
)}
</button>
);
}