Show live online-players count on the home screen
- OnlineService.getOnlineCount(); mock random-walks a believable number, SignalrService reads GET /api/stats/online (server tracks hub connections) - Home screen badge with pulsing dot, polls every 8s, localized digits Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -262,6 +262,19 @@ export class SignalrService implements OnlineService {
|
||||
markRead(id: string) { return this.mock.markRead(id); }
|
||||
onChat(cb: (id: string, m: ChatMessage[]) => void) { return this.mock.onChat(cb); }
|
||||
|
||||
async getOnlineCount(): Promise<number> {
|
||||
try {
|
||||
const res = await fetch(`${SERVER}/api/stats/online`);
|
||||
if (res.ok) {
|
||||
const j = (await res.json()) as { online: number };
|
||||
return j.online ?? 0;
|
||||
}
|
||||
} catch {
|
||||
/* fall through */
|
||||
}
|
||||
return this.mock.getOnlineCount();
|
||||
}
|
||||
|
||||
getLeaderboard(): Promise<LeaderboardEntry[]> { return this.mock.getLeaderboard(); }
|
||||
getShopItems(): Promise<ShopItem[]> { return this.mock.getShopItems(); }
|
||||
buyItem(id: string) { return this.mock.buyItem(id); }
|
||||
|
||||
Reference in New Issue
Block a user