Skip to content

Conversation

jake-luster
Copy link
Contributor

This pull request introduces a configurable automatic reconnection mechanism for WebSocket connections, improving connection reliability in the client. The changes add new configuration options, refactor event listener management, and implement logic to handle reconnection attempts with customizable limits and delays.

WebSocket reconnection support

  • Added a new WebSocketConnectionConfig type to BaseConnection.ts that allows configuring reconnection behavior, including enabling/disabling, max attempts, and delay between attempts. (packages/client/src/utils/BaseConnection.ts, packages/client/src/utils/BaseConnection.tsR50-R55)
  • Updated the BaseSessionConfig type to include an optional webSocketConnectionConfig property for passing reconnection settings to sessions. (packages/client/src/utils/BaseConnection.ts, packages/client/src/utils/BaseConnection.tsR102)

WebSocketConnection class enhancements

  • Refactored WebSocketConnection to manage event listeners with dedicated setup and removal methods, improving resource management and reliability. (packages/client/src/utils/WebSocketConnection.ts, packages/client/src/utils/WebSocketConnection.tsR20-R64)
  • Implemented the reconnection logic in the tryReconnect method, which attempts to reconnect the socket based on configuration and exponential delay, and resets attempts on success. (packages/client/src/utils/WebSocketConnection.ts, packages/client/src/utils/WebSocketConnection.tsL158-R243)
  • Updated constructor and static create method to accept and store session config, enabling access to reconnection parameters throughout the connection lifecycle. (packages/client/src/utils/WebSocketConnection.ts, [1] [2]

@PaulAsjes
Copy link
Collaborator

Could you add some tests for the new functionality please?

@mrvissercb
Copy link
Contributor

@jake-luster do you think this would support retries in scenarios where it fails an initial connection? i.e., #257

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