feat: add AppState-aware WebSocket reconnect on mobile foreground
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s

When the app returns from background, check if the WebSocket is still
open. If not, close the stale socket and reconnect with reset backoff.
Proactively close the WS when backgrounding to save battery and avoid
OS killing it mid-frame. Add "reconnecting" connection status with
amber pulsing badge so users see the app is re-establishing connection.

Fixes #33

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alexander Whitestone
2026-03-22 21:50:40 -04:00
parent 4c747aa331
commit b9a9d44da6
2 changed files with 52 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ const STATUS_CONFIG: Record<ConnectionStatus, { color: string; label: string }>
connecting: { color: "#F59E0B", label: "Connecting" },
connected: { color: "#10B981", label: "Live" },
disconnected: { color: "#6B7280", label: "Offline" },
reconnecting: { color: "#F59E0B", label: "Reconnecting" },
error: { color: "#EF4444", label: "Error" },
};
@@ -18,7 +19,7 @@ export function ConnectionBadge({ status }: { status: ConnectionStatus }) {
const pulseAnim = useRef(new Animated.Value(1)).current;
useEffect(() => {
if (status === "connecting") {
if (status === "connecting" || status === "reconnecting") {
const pulse = Animated.loop(
Animated.sequence([
Animated.timing(pulseAnim, { toValue: 0.3, duration: 600, useNativeDriver: true }),