refactor: introduce pause method to socket service to preserve event listeners during idle disconnects

This commit is contained in:
pradeepkumar
2026-04-08 22:04:20 +05:30
parent 308bbf90fd
commit 65787bc34c
2 changed files with 35 additions and 10 deletions

View File

@@ -44,7 +44,11 @@ export function PresenceProvider({ children }: { children: React.ReactNode }) {
const disconnectForIdle = useCallback(() => {
if (!isConnectedRef.current) return;
isIdleRef.current = true;
socketService.disconnect();
// Use pause() instead of disconnect() so subscriber handlers
// (useMessaging listeners) survive the reconnect. Otherwise the
// user would have to refresh the page after returning from idle
// to see new messages in real time again.
socketService.pause();
}, []);
// Track socket connection state