Skip to content

Conversation

@bcksl
Copy link

@bcksl bcksl commented Dec 3, 2025

Summary

This PR adds a webSocketFactory option to RealTimeDataClientArgs, allowing
callers to fully control how WebSocket instances are created.

This is useful for:

  • Connecting through proxy agents (HTTP/SOCKS/etc.)
  • Injecting custom WebSocket implementations (e.g. ws, undici, testing mocks)
  • Adding instrumentation or monitoring around socket creation

Key Changes

  • Adds WebSocketFactory type and webSocketFactory optional parameter.
  • Stores the factory on the client instance.
  • connect() now uses this factory instead of constructing WebSockets directly.
  • Maintains full backward compatibility:
    • Default behavior still uses new WebSocket(...) via isomorphic-ws.
    • No existing usage patterns break.
  • Cleans up constructor logic (?? instead of || for correctness).

Benefits

This makes the client substantially more flexible and easier to integrate into
production environments where proxying, observability, or custom network stacks
are required.

No behavioral changes for existing users.


Note

Adds an optional webSocketFactory to RealTimeDataClient and uses it in connect() with a backward-compatible default.

  • Client (src/client.ts):
    • Extensibility:
      • Add WebSocketFactory type and optional webSocketFactory in RealTimeDataClientArgs.
      • Store factory on the client and use it in connect() instead of new WebSocket(...).
      • Provide default factory (host => new WebSocket(host)) to preserve behavior.
    • Constructor cleanup:
      • Switch to ?? defaults and default args (constructor(args: RealTimeDataClientArgs = {})).

Written by Cursor Bugbot for commit f14e327. This will update automatically on new commits. Configure here.

Adds a new `webSocketFactory` option to `RealTimeDataClientArgs`, allowing
callers to control how WebSocket instances are created. This enables proxy
support, instrumentation, custom WebSocket implementations, or test stubbing.

Maintains full backward compatibility: the default behavior still constructs
a standard `isomorphic-ws` instance when no factory is provided.
@bcksl bcksl requested a review from a team as a code owner December 3, 2025 01:05
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.

1 participant