Skip to content

Conversation

@xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Sep 30, 2025

Submit a pull request

Fixes: FLU-279

Description of the pull request

This PR introduces several improvements to the WebSocket connection management and application lifecycle handling:

WebSocket Engine:

  • Ensures that any existing WebSocket connection is closed before opening a new one.
  • Improved handling of the onDone event for WebSocket streams, ensuring proper cleanup and notification.
  • Refined the close method to handle cases where the WebSocket is not open and to notify listeners appropriately.

WebSocket Client:

  • Updated error handling during the connection opening process to use recover instead of onFailure for better resilience.
  • Simplified error handling in onError by directly calling disconnect.

Network and Lifecycle State:

  • Renamed AppLifecycleStateProvider to LifecycleStateProvider and AppLifecycleState to LifecycleState for clarity and broader applicability.
  • Added an unknown state to both NetworkState and LifecycleState to represent initial or indeterminate states.
  • Introduced a keepConnectionAliveInBackground option in ConnectionRecoveryHandler to allow maintaining the WebSocket connection even when the app is in the background.
  • ConnectionRecoveryHandler now considers the unknown state for both network and lifecycle, taking no action in these cases.
  • ConnectionRecoveryHandler logic for _onAppLifecycleStateChanged updated to respect keepConnectionAliveInBackground.

General Changes:

  • Updated imports and type aliases to reflect the renaming of lifecycle state components.

… handling

This commit introduces several improvements to the WebSocket connection management and application lifecycle handling:

**WebSocket Engine:**
- Ensures that any existing WebSocket connection is closed before opening a new one.
- Improved handling of the `onDone` event for WebSocket streams, ensuring proper cleanup and notification.
- Refined the `close` method to handle cases where the WebSocket is not open and to notify listeners appropriately.

**WebSocket Client:**
- Updated error handling during the connection opening process to use `recover` instead of `onFailure` for better resilience.
- Simplified error handling in `onError` by directly calling `disconnect`.

**Network and Lifecycle State:**
- Renamed `AppLifecycleStateProvider` to `LifecycleStateProvider` and `AppLifecycleState` to `LifecycleState` for clarity and broader applicability.
- Added an `unknown` state to both `NetworkState` and `LifecycleState` to represent initial or indeterminate states.
- Introduced a `keepConnectionAliveInBackground` option in `ConnectionRecoveryHandler` to allow maintaining the WebSocket connection even when the app is in the background.
- `ConnectionRecoveryHandler` now considers the `unknown` state for both network and lifecycle, taking no action in these cases.
- `ConnectionRecoveryHandler` logic for `_onAppLifecycleStateChanged` updated to respect `keepConnectionAliveInBackground`.

**General Changes:**
- Updated imports and type aliases to reflect the renaming of lifecycle state components.
@xsahil03x xsahil03x requested a review from a team as a code owner September 30, 2025 11:46
@codecov
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.05%. Comparing base (8f3df60) to head (829a028).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #13   +/-   ##
=======================================
  Coverage   87.05%   87.05%           
=======================================
  Files           4        4           
  Lines         170      170           
=======================================
  Hits          148      148           
  Misses         22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xsahil03x xsahil03x merged commit c29f216 into main Sep 30, 2025
9 checks passed
@xsahil03x xsahil03x deleted the fix/reconnection branch September 30, 2025 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants