Skip to content

feat: Introduce WebSocket Reconnect Behavior - #167

Open
jake-luster wants to merge 1 commit into
elevenlabs:mainfrom
jake-luster:jake-luster/websocket-reconnection
Open

feat: Introduce WebSocket Reconnect Behavior#167
jake-luster wants to merge 1 commit into
elevenlabs:mainfrom
jake-luster:jake-luster/websocket-reconnection

Conversation

@jake-luster

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Could you add some tests for the new functionality please?

@mrvissercb

Copy link
Copy Markdown
Contributor

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

@kraenhansen kraenhansen added the stale PR or issue has not had recent activity and may be closed label Apr 28, 2026
@kraenhansen

kraenhansen commented Apr 28, 2026

Copy link
Copy Markdown
Member

Sorry we didn't get to reviewing this sooner. We're doing a spring cleaning of open PRs and marking this as stale for now. If you're still interested in getting this merged, let us know and we'll prioritize a review!

@kraenhansen

Copy link
Copy Markdown
Member

Also, your branch has merge conflicts and will need a rebase before it can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR or issue has not had recent activity and may be closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants