Skip to content

Add real-time activity tracking for active game sessions#3272

Draft
gantoine wants to merge 1 commit into
masterfrom
claude/user-game-activity-monitoring-Mqb1v
Draft

Add real-time activity tracking for active game sessions#3272
gantoine wants to merge 1 commit into
masterfrom
claude/user-game-activity-monitoring-Mqb1v

Conversation

@gantoine
Copy link
Copy Markdown
Member

Description

This PR adds comprehensive real-time activity tracking to display which users are currently playing games across the platform. The feature includes:

Backend Changes:

  • New ActivityHandler class that stores ephemeral play session state in Redis with automatic TTL expiration (90 seconds, refreshed by heartbeats)
  • Socket.IO event handlers for activity:start, activity:heartbeat, activity:stop, and disconnect to manage browser-based activity
  • REST endpoints for external devices (muOS, Android, etc.) to report play sessions via /activity/heartbeat and clear activity via DELETE /activity/heartbeat
  • Endpoints to query all active sessions or filter by ROM
  • Automatic cleanup on socket disconnect as a safety net

Frontend Changes:

  • New Activity.vue view displaying all currently active play sessions in a card grid with user avatars, ROM covers, platform info, and elapsed time
  • ActivePlayers.vue component showing live players on individual ROM detail pages
  • ActivityBtn.vue navigation button with badge showing active session count
  • Activity store (activity.ts) managing real-time state via Socket.IO events (activity:update, activity:clear)
  • Integration with the emulator player to emit activity events when games start/stop and periodic heartbeats while playing
  • Activity API service for REST endpoints and Socket.IO communication
  • i18n translations for activity-related UI strings

Key Features:

  • Real-time updates across all connected clients via Socket.IO
  • Automatic session expiration if heartbeats stop (device disconnect, network loss)
  • Support for both browser-based play (web) and external devices (grout, argosy-launcher, etc.)
  • Preserves session start time across heartbeat refreshes
  • Graceful fallback to stored session data if disconnect event lacks payload

The implementation uses Redis for ephemeral storage with automatic cleanup, ensuring no manual session management is required.

https://claude.ai/code/session_01WzWu5XEEYcAc3EJcfteiFd

Add live tracking of which users are actively playing which games, covering
both browser-based EmulatorJS sessions and external devices via a heartbeat
endpoint. Surfaces activity on a dedicated /activity page and as an indicator
on individual game detail pages.

Backend
- New handler/activity_handler.py stores ephemeral "now playing" state in
  Redis with a 90s TTL keyed by (user_id, device_id), plus a per-ROM reverse
  index for fast lookup.
- New endpoints/activity.py exposes GET /api/activity, GET /api/activity/rom/{id},
  and POST /api/activity/heartbeat (for external devices).
- New endpoints/sockets/activity.py handles browser activity:start /
  activity:heartbeat / activity:stop events, broadcasts activity:update /
  activity:clear to all connected clients, and cleans up on socket disconnect.

Frontend
- Pinia activity store syncs via Socket.IO and provides per-ROM getters.
- ActivePlayers component on GameDetails shows who is currently playing a
  title, with avatar tooltips.
- New Activity view lists every live session with game cover, user, platform,
  and elapsed time.
- ActivityBtn in MainAppBar with a live-count badge routes to the page.
- EmulatorJS Player emits start/heartbeat/stop events and tears down the
  heartbeat interval on exit.

No DB migration required; all state is Redis-resident.

https://claude.ai/code/session_01WzWu5XEEYcAc3EJcfteiFd
@github-actions
Copy link
Copy Markdown
Contributor

Test Results (postgresql)

    1 files  ±0      1 suites  ±0   4m 14s ⏱️ +4s
1 271 tests ±0  1 271 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 273 runs  ±0  1 273 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 227ae0f. ± Comparison against base commit faee6ff.

@github-actions
Copy link
Copy Markdown
Contributor

Test Results (mariadb)

    1 files  ±0      1 suites  ±0   4m 11s ⏱️ -2s
1 271 tests ±0  1 271 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 273 runs  ±0  1 273 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 227ae0f. ± Comparison against base commit faee6ff.

@github-actions
Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
16374 11102 68% 0% 🟢

New Files

File Coverage Status
backend/endpoints/activity.py 44% 🟢
backend/endpoints/responses/activity.py 100% 🟢
backend/endpoints/sockets/activity.py 21% 🟢
backend/handler/activity_handler.py 31% 🟢
TOTAL 49% 🟢

Modified Files

File Coverage Status
backend/main.py 96% 🟢
TOTAL 96% 🟢

updated for commit: 227ae0f by action🐍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants