Skip to content

[P1] Implement WebSocket subscription tracking in websocket router #105

Description

@frankbria

Overview

The WebSocket router has a TODO for tracking client subscriptions to project events.

Current State

File: codeframe/ui/routers/websocket.py lines 70-72

project_id = message.get("project_id")
# TODO: Track subscriptions
await websocket.send_json({"type": "subscribed", "project_id": project_id})

Expected Behavior

  • Maintain in-memory mapping of websocket → subscribed projects
  • Support subscribing to multiple projects per connection
  • Support unsubscribe messages
  • Broadcast events only to subscribed clients
  • Clean up subscriptions on disconnect

Implementation Requirements

  1. Create WebSocketSubscriptionManager class
  2. Store subscriptions in dict: {websocket_id: set(project_ids)}
  3. Implement subscribe/unsubscribe message handlers
  4. Filter broadcasts by subscription list
  5. Clean up on connection close

Data Structure

class WebSocketSubscriptionManager:
    subscriptions: Dict[str, Set[int]] = {}  # websocket_id -> project_ids
    
    def subscribe(self, websocket_id: str, project_id: int)
    def unsubscribe(self, websocket_id: str, project_id: int)
    def get_subscribers(self, project_id: int) -> List[str]
    def cleanup(self, websocket_id: str)

Acceptance Criteria

  • Clients can subscribe to specific projects
  • Clients can unsubscribe from projects
  • Events broadcast only to subscribed clients
  • Subscriptions cleaned up on disconnect
  • Multiple subscriptions per client supported

Priority

P1 - Critical: Required for real-time dashboard updates.

References

  • Issues Analysis: CODEFRAME_ISSUES_ANALYSIS.md lines 68-73
  • User Documentation: CODEFRAME_USER_DOCUMENTATION.md lines 37-39

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions