Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Stream connectivity status #36

Merged
merged 31 commits into from
Jan 22, 2025
Merged

Conversation

kevinszuchet
Copy link
Contributor

@kevinszuchet kevinszuchet commented Jan 21, 2025

Friend Status Updates Implementation

This PR implements real-time friend status updates by tracking peer connectivity through NATS and notifying connected friends about status changes.

Context

Currently, users can't see their friends' online/offline status in real-time. This implementation adds this functionality by:

  1. Tracking peer connectivity events (connect/disconnect/heartbeat) via NATS
  2. Publishing status updates to Redis PubSub
  3. Notifying connected friends through their respective WebSocket connections
  4. Maintaining online peers state through Archipelago Stats

Changes

  • Added peer tracking component to subscribe to NATS peer events
  • Implemented friend status updates through Redis PubSub channel
  • Added database query to check friendships only against connected users
  • Integrated with existing RPC server subscription system
  • Leveraged Archipelago Stats for initial online peers state
  • Added Redis caching layer for online peers status

Technical Details

  • Uses NATS for peer connectivity events (peer.*.connect, peer.*.disconnect, peer.*.heartbeat)
  • Redis PubSub channel FRIEND_STATUS_UPDATES_CHANNEL for distributing updates
  • Optimized database query that only checks friendships against currently connected users
  • Leverages existing emitter system for real-time updates to clients
  • Archipelago Stats provides initial online peers state when users subscribe
  • Redis cache maintains online peers status with configurable TTL

Online Status Flow

  1. When a user subscribes to friend updates:
    • Gets initial online friends from Archipelago Stats
    • Creates subscription for real-time updates
    • Receives subsequent updates through WebSocket
  2. When a peer's status changes:
    • NATS publishes connectivity event
    • Status update is published to Redis PubSub
    • Connected friends receive real-time update
    • Redis cache is updated with new status

@coveralls
Copy link

coveralls commented Jan 21, 2025

Pull Request Test Coverage Report for Build 12910352087

Details

  • 152 of 196 (77.55%) changed or added relevant lines in 18 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+8.6%) to 70.203%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/adapters/archipelago-stats.ts 13 14 92.86%
src/adapters/peer-tracking.ts 21 22 95.45%
src/adapters/db.ts 21 23 91.3%
src/adapters/pubsub.ts 6 8 75.0%
src/adapters/rpc-server/services/subscribe-to-friendship-updates.ts 1 3 33.33%
src/controllers/handlers/ws-handler.ts 0 2 0.0%
src/adapters/rpc-server/services/subscribe-to-friend-updates.ts 15 24 62.5%
src/components.ts 0 11 0.0%
src/adapters/rpc-server/rpc-server.ts 10 24 41.67%
Files with Coverage Reduction New Missed Lines %
src/components.ts 1 0.0%
Totals Coverage Status
Change from base Build 12835982560: 8.6%
Covered Lines: 475
Relevant Lines: 672

💛 - Coveralls

@kevinszuchet kevinszuchet merged commit 19b23c0 into main Jan 22, 2025
3 of 4 checks passed
@kevinszuchet kevinszuchet deleted the feat/stream-connectivity-status branch January 22, 2025 19:57
@kevinszuchet kevinszuchet restored the feat/stream-connectivity-status branch January 22, 2025 20:09
@kevinszuchet kevinszuchet deleted the feat/stream-connectivity-status branch January 22, 2025 20:20
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.

3 participants