Skip to content

feat(web): Implement WebSocket Broadcaster#98

Merged
kimit0310 merged 10 commits into
devfrom
feature/websocket-broadcaster
Feb 12, 2026
Merged

feat(web): Implement WebSocket Broadcaster#98
kimit0310 merged 10 commits into
devfrom
feature/websocket-broadcaster

Conversation

@kimit0310
Copy link
Copy Markdown
Collaborator

@kimit0310 kimit0310 commented Jan 13, 2026

Task

Create the Broadcaster class for real-time data streaming to browser clients. This core component reads data from the presenter and broadcasts it as JSON frames to all connected WebSocket clients.

Description

This PR introduces the Broadcaster class as the foundation for web-based visualization. It implements:

  • A background thread running a continuous poll-broadcast loop
  • Thread-safe client set management for WebSocket connections
  • JSON frame formatting for stream data delivery
  • Graceful handling of disconnected clients with automatic cleanup

Changes

  • Added __init__.py for the web submodule
  • Added broadcaster.pycontaining the Broadcaster class with:
    • start() / stop() lifecycle methods
    • add_client() / remove_client() for connection management
    • format_frame() for JSON serialization
    • _run() broadcast loop with presenter polling
    • _broadcast_to_clients() with async-to-sync bridge for WebSocket sends
  • Modified pyproject.toml to add websockets>=14.0 dependency

Related Issues

#86

… Implemented client management with add/remove methods that are thread-safe, JSON formatting for stream data.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@3a631a1). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev      #98   +/-   ##
======================================
  Coverage       ?   87.76%           
======================================
  Files          ?        7           
  Lines          ?      237           
  Branches       ?        0           
======================================
  Hits           ?      208           
  Misses         ?       29           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

broadcast_interval: Time between broadcasts in seconds.
"""

CLIENT_SEND_TIMEOUT: float = 1.0
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will move to config if we decide to keep it and if we want to make it tunable for users. Used in _broadcast_to_clients() and stop() timeout calculations, currently set as 1.0, which is pretty conservative.

that were pinned to 3.25.0. Using 'latest' for future-proofing. Use $(brew --prefix)/lib to support both Intel (/usr/local) and
Apple Silicon (/opt/homebrew) architectures. This resolves pylsl
failing to find liblsl binary due to macOS SIP stripping DYLD_*
variables during subprocess propagation.
@kimit0310
Copy link
Copy Markdown
Collaborator Author

CI was failing on macOS because Homebrew’s lsl formula now installs LSL.framework (not liblsl.dylib), so pylsl couldn’t locate the native library during test collection. The setup action now detects the framework binary and exports PYLSL_LIB (with a liblsl.dylib fallback) so discovery is explicit and SIP/DYLD quirks don’t matter.

Windows CI was slow and brittle because it built liblsl from source (CMake/toolchain churn). The setup action now downloads the prebuilt release zip and sets PYLSL_LIB + PATH after verifying lsl.dll exists.

@kimit0310 kimit0310 requested a review from Asanto32 January 13, 2026 19:20
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments, add unit tests for the first few functions, remove _run _broadcast_to_clients for separate/later PRs

Comment thread src/MoBI_View/web/broadcaster.py Outdated
Comment thread src/MoBI_View/web/broadcaster.py Outdated
Comment thread src/MoBI_View/web/broadcaster.py Outdated
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment thread tests/unit/test_broadcaster.py
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kimit0310 kimit0310 merged commit d58e40a into dev Feb 12, 2026
23 checks passed
@kimit0310 kimit0310 deleted the feature/websocket-broadcaster branch March 18, 2026 16:48
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