Mobile: App-state aware WebSocket reconnect on foreground #33
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When the app is backgrounded on iOS or Android, the WebSocket connection to the API server is silently dropped by the OS. When the user returns to the app, the feed shows stale data and the ConnectionBadge shows "connected" incorrectly, because the WS disconnect event may have been swallowed.
What to build
In
TimmyContext(or wherever the WebSocket is managed), add areact-nativeAppStatelistener:change → active: check if the WS is still open. If not (or ifreadyState !== OPEN), close the old socket and reconnect with exponential backoff (start at 1s, cap at 30s).change → background: optionally close the WS proactively to avoid the OS killing it mid-frame (saves battery).Update
ConnectionBadgeto accurately reflect the reconnecting state (amber / pulsing) so the user knows the app is re-establishing the connection.Acceptance criteria
PR created: http://143.198.27.163:3000/replit/timmy-tower/pulls/77
Added AppState-aware WebSocket reconnect in TimmyProvider. On foreground return, the app checks if the WS is still open and reconnects immediately if not. On background, the WS is proactively closed to save battery. A new "reconnecting" status with amber pulsing badge was added to ConnectionBadge. All acceptance criteria addressed — no duplicate connections, backoff reset on foreground, works on iOS and Android.