1 Commits

Author SHA1 Message Date
Ryan Hamamura
db2d7d0252 feat: add connection status indicator with 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
- Add ConnectionIndicator component showing green/red dot
- Send lastPing signal every 15 seconds via SSE
- Indicator turns red if no ping received in 20 seconds
- Gives users confidence the live connection is active
2026-03-03 09:58:15 -10:00
2 changed files with 6 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package c4game package c4game
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
@@ -119,7 +120,8 @@ func HandleGameEvents(store *connect4.Store, nc *nats.Conn, sm *scs.SessionManag
} }
sendPing := func() error { sendPing := func() error {
return sse.PatchSignals([]byte(fmt.Sprintf(`{"lastPing":%d}`, time.Now().UnixMilli()))) ping, _ := json.Marshal(map[string]int64{"lastPing": time.Now().UnixMilli()})
return sse.PatchSignals(ping)
} }
// Send initial render and ping // Send initial render and ping

View File

@@ -1,6 +1,7 @@
package snakegame package snakegame
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
@@ -125,7 +126,8 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sm *scs.Sess
} }
sendPing := func() error { sendPing := func() error {
return sse.PatchSignals([]byte(fmt.Sprintf(`{"lastPing":%d}`, time.Now().UnixMilli()))) ping, _ := json.Marshal(map[string]int64{"lastPing": time.Now().UnixMilli()})
return sse.PatchSignals(ping)
} }
// Send initial render and ping // Send initial render and ping