Add WebSocket support for real-time payment confirmation #2

Open
opened 2026-03-18 22:00:59 +00:00 by hermes · 0 comments
Collaborator

Context

Currently payment confirmation is polling-based — client calls GET /jobs/:id
repeatedly until state changes. For the Three.js Workshop, we need instant feedback.

Requirements

  • Add a WebSocket endpoint (e.g. ws://host/api/ws)
  • When a Lightning invoice is paid, push state change to connected clients
  • Support both Job (Mode 1) and Session (Mode 2) payment events
  • Client subscribes by job ID or session ID
  • Use ws npm package (lightweight, no socket.io overhead)

Events to push

{"type": "payment_confirmed", "jobId": "...", "state": "evaluating"}
{"type": "eval_complete", "jobId": "...", "state": "awaiting_work_payment", "workInvoice": {...}}
{"type": "work_started", "jobId": "...", "state": "executing"}
{"type": "work_complete", "jobId": "...", "state": "complete", "result": "..."}
{"type": "session_active", "sessionId": "...", "balanceSats": 1000}
{"type": "session_debited", "sessionId": "...", "debitedSats": 45, "balanceAfter": 955}

Acceptance Criteria

  • WebSocket server starts alongside Express
  • Client can subscribe to job or session updates
  • Payment confirmation pushes within 1s of LNBits confirming
  • Graceful reconnection handling
  • Stub mode works (dev/stub/pay triggers WS push)
  • Tests updated

References

  • Parent epic: #{epic_num}
## Context Currently payment confirmation is polling-based — client calls `GET /jobs/:id` repeatedly until state changes. For the Three.js Workshop, we need instant feedback. ## Requirements - Add a WebSocket endpoint (e.g. `ws://host/api/ws`) - When a Lightning invoice is paid, push state change to connected clients - Support both Job (Mode 1) and Session (Mode 2) payment events - Client subscribes by job ID or session ID - Use `ws` npm package (lightweight, no socket.io overhead) ## Events to push ```json {"type": "payment_confirmed", "jobId": "...", "state": "evaluating"} {"type": "eval_complete", "jobId": "...", "state": "awaiting_work_payment", "workInvoice": {...}} {"type": "work_started", "jobId": "...", "state": "executing"} {"type": "work_complete", "jobId": "...", "state": "complete", "result": "..."} {"type": "session_active", "sessionId": "...", "balanceSats": 1000} {"type": "session_debited", "sessionId": "...", "debitedSats": 45, "balanceAfter": 955} ``` ## Acceptance Criteria - [ ] WebSocket server starts alongside Express - [ ] Client can subscribe to job or session updates - [ ] Payment confirmation pushes within 1s of LNBits confirming - [ ] Graceful reconnection handling - [ ] Stub mode works (dev/stub/pay triggers WS push) - [ ] Tests updated ## References - Parent epic: #{epic_num}
hermes added the apienhancementreplit labels 2026-03-18 22:00:59 +00:00
replit self-assigned this 2026-03-18 22:02:21 +00:00
This repo is archived. You cannot comment on issues.