Skip to content

feat: stream compilation output to browser via SSE (#49) - #50

Merged
zackees merged 1 commit into
mainfrom
feat/sse-build-streaming
Apr 12, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/sse-build-streaming

Conversation

@zackees

@zackees zackees commented Apr 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Browser loading page now shows live compilation output in real time via Server-Sent Events (SSE)
  • Each line of Python subprocess stdout/stderr is teed to both the terminal and the browser
  • Loading page uses EventSource to subscribe to /build-stream, with polling fallback

What changed

Rust server (server.rs)

  • New /build-stream SSE endpoint backed by tokio::sync::broadcast
  • AppState gains optional broadcast::Sender<String> for SSE fan-out
  • start_server() accepts optional broadcast sender (None for --serve-dir mode)
  • Loading page rewritten: uses EventSource for real-time log streaming, falls back to polling

CLI (main.rs)

  • compile_and_serve() creates a broadcast channel and passes it to the server
  • New run_python_compile_streaming() captures subprocess output via Stdio::piped(), reads line-by-line with BufReader, tees to terminal + SSE broadcast
  • Status events (compiling/success/error) sent through both build-status.json and SSE

Dependencies

  • Added tokio-stream (with sync feature) for BroadcastStream

Test plan

  • cargo test -p fastled-cli — 58 tests pass (3 new SSE tests)
  • bash lint — all checks pass
  • bash test — 119 Python tests pass
  • CI passes

Add Server-Sent Events (SSE) endpoint to the Rust HTTP server so the
browser loading page shows live compilation output instead of just a
spinner.

Rust server (server.rs):
- Add /build-stream SSE endpoint backed by tokio::sync::broadcast
- AppState gains optional broadcast::Sender<String> for SSE fan-out
- start_server() accepts optional broadcast sender (None for --serve-dir)
- Loading page now uses EventSource for real-time log streaming, with
  polling fallback for older browsers

CLI (main.rs):
- Create broadcast channel in compile_and_serve()
- New run_python_compile_streaming() captures Python subprocess output
  line-by-line via piped stdout/stderr, tees each line to both the
  terminal and the SSE broadcast channel
- Status events (compiling/success/error) sent through SSE

Tests:
- test_sse_endpoint_streams_events: verifies SSE data arrives correctly
- test_sse_returns_404_without_broadcast: verifies --serve-dir mode
- test_loading_page_contains_eventsource: verifies loading page JS
@zackees
zackees merged commit 385b489 into main Apr 12, 2026
25 checks passed
@zackees
zackees deleted the feat/sse-build-streaming branch April 12, 2026 13:30
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.

1 participant