View counter

This commit is contained in:
Theo Browne
2026-02-22 00:11:20 -08:00
parent 8519be7cf4
commit 1ab21883fb
3 changed files with 54 additions and 4 deletions

View File

@@ -55,6 +55,10 @@ body {
.header {
flex-shrink: 0;
margin-bottom: 28px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.logo {
@@ -67,6 +71,37 @@ body {
width: auto;
}
.viewer-pill {
display: inline-flex;
align-items: center;
gap: 8px;
font-family: var(--mono);
font-size: 11px;
letter-spacing: 0.4px;
text-transform: uppercase;
color: var(--text-dim);
border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.02);
border-radius: 999px;
padding: 6px 10px;
white-space: nowrap;
}
.viewer-pill__dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #22c55e;
box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
animation: viewer-pulse 1.8s ease-out infinite;
}
@keyframes viewer-pulse {
0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
/* ── Arena ────────────────────────────────────────────────────── */
.arena {

View File

@@ -20,7 +20,7 @@ type RoundState = {
scoreB?: number;
};
type GameState = { completed: RoundState[]; active: RoundState | null; scores: Record<string, number>; done: boolean };
type ServerMessage = { type: "state"; data: GameState; totalRounds: number };
type ServerMessage = { type: "state"; data: GameState; totalRounds: number; viewerCount: number };
// ── Model colors & logos ─────────────────────────────────────────────────────
@@ -298,6 +298,7 @@ function ConnectingScreen() {
function App() {
const [state, setState] = useState<GameState | null>(null);
const [totalRounds, setTotalRounds] = useState<number | null>(null);
const [viewerCount, setViewerCount] = useState(0);
const [connected, setConnected] = useState(false);
useEffect(() => {
@@ -318,6 +319,7 @@ function App() {
if (msg.type === "state") {
setState(msg.data);
setTotalRounds(msg.totalRounds);
setViewerCount(msg.viewerCount);
}
};
}
@@ -343,6 +345,10 @@ function App() {
<a href="/" className="logo">
<img src="/assets/logo.svg" alt="Qwipslop" />
</a>
<div className="viewer-pill" aria-live="polite">
<span className="viewer-pill__dot" />
{viewerCount} viewer{viewerCount === 1 ? "" : "s"} watching
</div>
</header>
{state.done ? (

View File

@@ -36,7 +36,10 @@ if (allRounds.length > 0) {
}
}
}
initialCompleted = [allRounds[allRounds.length - 1]];
const lastRound = allRounds[allRounds.length - 1];
if (lastRound) {
initialCompleted = [lastRound];
}
}
const gameState: GameState = {
@@ -52,7 +55,12 @@ const gameState: GameState = {
const clients = new Set<ServerWebSocket<unknown>>();
function broadcast() {
const msg = JSON.stringify({ type: "state", data: gameState, totalRounds: runs });
const msg = JSON.stringify({
type: "state",
data: gameState,
totalRounds: runs,
viewerCount: clients.size,
});
for (const ws of clients) {
ws.send(msg);
}
@@ -111,13 +119,14 @@ const server = Bun.serve({
websocket: {
open(ws) {
clients.add(ws);
ws.send(JSON.stringify({ type: "state", data: gameState, totalRounds: runs }));
broadcast();
},
message(_ws, _message) {
// Spectator-only, no client messages handled
},
close(ws) {
clients.delete(ws);
broadcast();
},
},
development: process.env.NODE_ENV === "production" ? false : {