Fix SSE architecture for reliable connections #13

Merged
ryan merged 9 commits from fix/sse-architecture into main 2026-03-03 23:33:14 +00:00

9 Commits

Author SHA1 Message Date
Ryan Hamamura
c826981b4d feat: tick live clock every second via SSE heartbeat
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
2026-03-03 13:28:59 -10:00
Ryan Hamamura
9a8fe4534d feat: add hashfs for static asset cache busting and live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 32s
CI / Deploy / lint (pull_request) Successful in 42s
CI / Deploy / deploy (pull_request) Has been skipped
- Add assets package with dev/prod build tags
- Dev: serve from filesystem with Cache-Control: no-store
- Prod: use hashfs for cache-busting URLs
- Add LiveClock component to show SSE connection status
- Update templates to use StaticPath for asset URLs
2026-03-03 13:26:52 -10:00
Ryan Hamamura
e0f5d555fb feat: add status indicator dot to live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 26s
CI / Deploy / deploy (pull_request) Has been skipped
2026-03-03 12:53:46 -10:00
Ryan Hamamura
155ac2c71a feat: replace connection indicator with live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
A ticking clock serves as an implicit connection indicator - if it
stops updating, users know the connection is stale. Simpler and more
useful than a status dot.
2026-03-03 12:52:39 -10:00
Ryan Hamamura
1109dccdd8 fix: remove broken connection indicator
All checks were successful
CI / Deploy / test (pull_request) Successful in 15s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
The ConnectionIndicator component caused PatchElementsNoTargetsFound
errors due to complex nested IDs. Removing it for now - we can design
a better solution later if needed.
2026-03-03 12:47:28 -10:00
Ryan Hamamura
cedcadfe3c feat: re-enable connection indicator for SSE status
All checks were successful
CI / Deploy / test (pull_request) Successful in 15s
CI / Deploy / lint (pull_request) Successful in 24s
CI / Deploy / deploy (pull_request) Has been skipped
Add ConnectionIndicator to Connect 4 game page (Snake already had it).
Both games now patch the indicator on initial connect and every 10s
heartbeat, giving users visual feedback that SSE is connected.
2026-03-03 12:34:13 -10:00
Ryan Hamamura
de78ba6d39 refactor: extract GameService for Snake NATS/chat handling
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 24s
CI / Deploy / deploy (pull_request) Has been skipped
Apply the same service pattern from Connect 4 to Snake game.
Handlers now receive the service and call its methods instead of
managing NATS connections directly. Also aligns heartbeat to 10s
and removes ConnectionIndicator patching (matching C4 changes).
2026-03-03 12:25:25 -10:00
Ryan Hamamura
8536f8e948 refactor: extract GameService for Connect 4 NATS/chat handling
All checks were successful
CI / Deploy / test (pull_request) Successful in 16s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
Move NATS subscription and chat room management into a dedicated
GameService, following the portigo service pattern. Handlers now
receive the service and call its methods instead of managing
NATS connections directly.
2026-03-03 12:23:25 -10:00
Ryan Hamamura
b2b06a062b fix: align SSE architecture with portigo for reliable connections
All checks were successful
CI / Deploy / test (pull_request) Successful in 35s
CI / Deploy / lint (pull_request) Successful in 45s
CI / Deploy / deploy (pull_request) Has been skipped
- Reorder HandleGameEvents to create NATS subscriptions before SSE
- Use chi's middleware.NewWrapResponseWriter for proper http.Flusher support
- Add slog-zerolog adapter for unified logging
- Add ErrorLog to HTTP server for better error visibility
- Change session Cookie.Secure to false for HTTP support
- Change heartbeat from 15s to 10s
- Remove ConnectionIndicator patching (was causing PatchElementsNoTargetsFound)

The key fix was using chi's response writer wrapper which properly
implements http.Flusher, allowing SSE data to be flushed immediately
instead of being buffered.
2026-03-03 11:57:58 -10:00