Skip to content

feat: add websocket event stream support with sse fallback - #3

Draft
sabbirba wants to merge 1 commit into
hitblast:masterfrom
sabbirba:feat/websocket-stream
Draft

feat: add websocket event stream support with sse fallback#3
sabbirba wants to merge 1 commit into
hitblast:masterfrom
sabbirba:feat/websocket-stream

Conversation

@sabbirba

@sabbirba sabbirba commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds primary WebSocket streaming via /printer/ws using tungstenite with native TLS.
  • Preserves 100% of existing handle(job), claim_job(), and is_online() logic.
  • Maintains automatic fallback to HTTP SSE streaming if WebSocket connection fails.
  • Fixes clippy lint in create_lpr_sock.

Verification

  • cargo fmt --check passed.
  • cargo clippy --all-targets --all-features -- -D warnings passed (0 warnings).
  • cargo test passed.
  • cargo build --release succeeded.

Copilot AI lite review requested due to automatic review settings September 1, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The WebSocket URL/Host header construction in stream() can generate incorrect endpoints and invalid/mismatched Host headers (notably when BASE_URL includes a path prefix or explicit port).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an event-streaming upgrade path to prefer WebSocket delivery for printer jobs, while retaining the existing HTTP SSE stream as a fallback.

Changes:

  • Introduces a WebSocket-based stream in stream() that reads Job messages and dispatches them to the existing handle(job) logic.
  • Keeps the existing SSE /printer stream path as the fallback when WebSocket connect fails.
  • Adds tungstenite (rustls + native roots) and applies a small clippy-driven cleanup in create_lpr_sock.
File summaries
File Description
src/socket.rs Minor control-flow cleanup in socket creation error return.
src/main.rs Adds WebSocket streaming path ahead of the existing SSE stream logic.
Cargo.toml Adds tungstenite dependency with rustls TLS configuration.
Cargo.lock Locks new transitive dependencies introduced by tungstenite.
Review details
  • Files reviewed: 3/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main.rs
Comment on lines +296 to +312
let mut ws_url = BASE_URL.clone();
let _ = ws_url.set_scheme(if BASE_URL.scheme() == "https" {
"wss"
} else {
"ws"
});
ws_url.set_path("printer/ws");

let host = ws_url.host_str().unwrap_or_default();

let req = tungstenite::http::Request::builder()
.uri(ws_url.as_str())
.header("x-worker-key", WORKER_KEY.as_str())
.header("x-worker-ident", WORKER_IDENT.as_str())
.header("user-agent", AGENT.as_str())
.header("Host", host)
.header("Connection", "Upgrade")
@hitblast hitblast closed this Sep 2, 2026
@hitblast hitblast reopened this Sep 2, 2026
@hitblast
hitblast marked this pull request as draft September 2, 2026 04:08
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