View counter
This commit is contained in:
35
frontend.css
35
frontend.css
@@ -55,6 +55,10 @@ body {
|
|||||||
.header {
|
.header {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-bottom: 28px;
|
margin-bottom: 28px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
@@ -67,6 +71,37 @@ body {
|
|||||||
width: auto;
|
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 ────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
.arena {
|
.arena {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type RoundState = {
|
|||||||
scoreB?: number;
|
scoreB?: number;
|
||||||
};
|
};
|
||||||
type GameState = { completed: RoundState[]; active: RoundState | null; scores: Record<string, number>; done: boolean };
|
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 ─────────────────────────────────────────────────────
|
// ── Model colors & logos ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -298,6 +298,7 @@ function ConnectingScreen() {
|
|||||||
function App() {
|
function App() {
|
||||||
const [state, setState] = useState<GameState | null>(null);
|
const [state, setState] = useState<GameState | null>(null);
|
||||||
const [totalRounds, setTotalRounds] = useState<number | null>(null);
|
const [totalRounds, setTotalRounds] = useState<number | null>(null);
|
||||||
|
const [viewerCount, setViewerCount] = useState(0);
|
||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -318,6 +319,7 @@ function App() {
|
|||||||
if (msg.type === "state") {
|
if (msg.type === "state") {
|
||||||
setState(msg.data);
|
setState(msg.data);
|
||||||
setTotalRounds(msg.totalRounds);
|
setTotalRounds(msg.totalRounds);
|
||||||
|
setViewerCount(msg.viewerCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -343,6 +345,10 @@ function App() {
|
|||||||
<a href="/" className="logo">
|
<a href="/" className="logo">
|
||||||
<img src="/assets/logo.svg" alt="Qwipslop" />
|
<img src="/assets/logo.svg" alt="Qwipslop" />
|
||||||
</a>
|
</a>
|
||||||
|
<div className="viewer-pill" aria-live="polite">
|
||||||
|
<span className="viewer-pill__dot" />
|
||||||
|
{viewerCount} viewer{viewerCount === 1 ? "" : "s"} watching
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{state.done ? (
|
{state.done ? (
|
||||||
|
|||||||
15
server.ts
15
server.ts
@@ -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 = {
|
const gameState: GameState = {
|
||||||
@@ -52,7 +55,12 @@ const gameState: GameState = {
|
|||||||
const clients = new Set<ServerWebSocket<unknown>>();
|
const clients = new Set<ServerWebSocket<unknown>>();
|
||||||
|
|
||||||
function broadcast() {
|
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) {
|
for (const ws of clients) {
|
||||||
ws.send(msg);
|
ws.send(msg);
|
||||||
}
|
}
|
||||||
@@ -111,13 +119,14 @@ const server = Bun.serve({
|
|||||||
websocket: {
|
websocket: {
|
||||||
open(ws) {
|
open(ws) {
|
||||||
clients.add(ws);
|
clients.add(ws);
|
||||||
ws.send(JSON.stringify({ type: "state", data: gameState, totalRounds: runs }));
|
broadcast();
|
||||||
},
|
},
|
||||||
message(_ws, _message) {
|
message(_ws, _message) {
|
||||||
// Spectator-only, no client messages handled
|
// Spectator-only, no client messages handled
|
||||||
},
|
},
|
||||||
close(ws) {
|
close(ws) {
|
||||||
clients.delete(ws);
|
clients.delete(ws);
|
||||||
|
broadcast();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
development: process.env.NODE_ENV === "production" ? false : {
|
development: process.env.NODE_ENV === "production" ? false : {
|
||||||
|
|||||||
Reference in New Issue
Block a user