Redesign StreamClient factory with StreamSocketConfig and StreamComponentProvider#54
Redesign StreamClient factory with StreamSocketConfig and StreamComponentProvider#54aleksandar-apostolov wants to merge 5 commits intodevelopfrom
Conversation
Split StreamClient construction into three clear concerns: - Function params: mandatory identity (apiKey, user, tokenProvider, etc.) - StreamClientConfig: optional tunables (wsUrl, health check timing, batch sizes, logging) with sensible defaults - StreamComponentProvider: optional DI overrides for replacing internal components (singleFlight, tokenManager, etc.) The simplified StreamClient() factory becomes the public API. The original 25-param factory is now internal (createStreamClientInternal) for test use. Removes retryProcessor from factory params as StreamClientImpl never consumed it — products create their own instances directly.
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
WalkthroughStreamClient's public factory API is refactored with a simplified required-parameter signature and two new configuration data classes— Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
stream-android-core/src/test/java/io/getstream/android/core/api/StreamClientFactoryTest.kt (1)
336-358: Consider adding test coverage for the new publicStreamClient()factory.The tests now use
createStreamClientInternal()directly, which is appropriate for detailed wiring verification. However, there's no test exercising the new publicStreamClient(config, components)signature to verify thatStreamClientConfigandStreamComponentProviderare correctly resolved and delegated.Would you like me to generate a test case that verifies the public factory correctly wires
StreamClientConfigtunables andStreamComponentProvideroverrides?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@stream-android-core/src/test/java/io/getstream/android/core/api/StreamClientFactoryTest.kt` around lines 336 - 358, Tests call createStreamClientInternal(...) but do not exercise the new public StreamClient(config, components) factory; add a unit test that constructs a StreamClient using the public StreamClient(StreamClientConfig, StreamComponentProvider) API and asserts it delegates to the same wiring as createStreamClientInternal — e.g., build a StreamClientConfig with the same tunables (apiKey, user, wsUrl, products, clientInfoHeader, tokenProvider, serializationConfig) and a fake StreamComponentProvider (similar to fakeAndroidComponents/logProvider), call StreamClient(config, components), then verify resulting client's behavior or internals match what createStreamClientInternal produces (or spy/mock the underlying components to assert they were used). Ensure the test lives alongside StreamClientFactoryTest and references StreamClient, StreamClientConfig, StreamComponentProvider, and createStreamClientInternal to validate delegation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@stream-android-core/src/main/java/io/getstream/android/core/api/StreamClient.kt`:
- Around line 207-280: The SampleApp.kt call to the StreamClient factory must be
updated because the public StreamClient(...) signature changed:
productEventSerializer is now a required parameter and wsUrl/serializationConfig
were moved into StreamClientConfig; update the StreamClient invocation in
SampleApp.kt to pass a productEventSerializer implementation as the 8th argument
and set wsUrl and serializationConfig inside the config =
StreamClientConfig(...) parameter (instead of passing wsUrl/serializationConfig
directly), keeping other arguments (scope, context, apiKey, user, tokenProvider,
products, clientInfoHeader) unchanged so the call matches the new
StreamClient(...) factory.
---
Nitpick comments:
In
`@stream-android-core/src/test/java/io/getstream/android/core/api/StreamClientFactoryTest.kt`:
- Around line 336-358: Tests call createStreamClientInternal(...) but do not
exercise the new public StreamClient(config, components) factory; add a unit
test that constructs a StreamClient using the public
StreamClient(StreamClientConfig, StreamComponentProvider) API and asserts it
delegates to the same wiring as createStreamClientInternal — e.g., build a
StreamClientConfig with the same tunables (apiKey, user, wsUrl, products,
clientInfoHeader, tokenProvider, serializationConfig) and a fake
StreamComponentProvider (similar to fakeAndroidComponents/logProvider), call
StreamClient(config, components), then verify resulting client's behavior or
internals match what createStreamClientInternal produces (or spy/mock the
underlying components to assert they were used). Ensure the test lives alongside
StreamClientFactoryTest and references StreamClient, StreamClientConfig,
StreamComponentProvider, and createStreamClientInternal to validate delegation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8c81a6e9-ff46-4e43-a1b5-b49a196c325e
📒 Files selected for processing (4)
stream-android-core/src/main/java/io/getstream/android/core/api/StreamClient.ktstream-android-core/src/main/java/io/getstream/android/core/api/model/config/StreamClientConfig.ktstream-android-core/src/main/java/io/getstream/android/core/api/model/config/StreamComponentProvider.ktstream-android-core/src/test/java/io/getstream/android/core/api/StreamClientFactoryTest.kt
stream-android-core/src/main/java/io/getstream/android/core/api/StreamClient.kt
Show resolved
Hide resolved
Update SampleApp to use the simplified StreamClient factory with StreamClientConfig for tunables and productEventSerializer as a direct parameter.
…Provider factory Verify that the public StreamClient(config, components) factory correctly wires all StreamClientConfig tunables (wsUrl, health timing, batch params, serialization) and StreamComponentProvider overrides (singleFlight, serialQueue, tokenManager, connectionIdHolder, socketFactory, healthMonitor, batcher, subscriptionManager) through to internal components.
… required - StreamSocketConfig now holds URL (as StreamWsUrl), auth, health timing, batch params, and connection timeout — products describe their socket - StreamClientConfig slimmed to logProvider, httpConfig, serializationConfig - StreamClient factory takes socketConfig as required param; apiKey and clientInfoHeader removed from top-level (live in socketConfig) - No more hardcoded chat wsUrl default — products must specify their endpoint - HTTP interceptors read apiKey/authType/clientInfo from socketConfig - Added connectionTimeoutMs to StreamSocketConfig (default 10s) - Updated sample app, all factory tests, socket config tests
- Remove StreamClientConfig — serializationConfig and httpConfig are now top-level params on StreamClient factory, logProvider moves to StreamComponentProvider - StreamClient factory signature: scope, context, user, tokenProvider, products, socketConfig, serializationConfig, httpConfig?, components? - Products pass StreamClientSerializationConfig.default(serializer) directly - No hidden config bags — everything visible at the call site
|



Goal
Redesign the
StreamClientfactory API so that product SDKs (Feeds, Video, Chat) can configure their client with a clear, self-documenting signature — no hidden config bags, no ambiguous defaults.Implementation
Before: Single factory with 15+ params,
StreamClientConfigwrapper hiding tunables, hardcoded chat WS URL default,retryProcessorparam that wasn't used.After: Flat factory with clear separation:
Key changes:
StreamSocketConfig— required, holds URL (StreamWsUrl, type-safe), auth type (jwt/anonymous/custom), API key, client info header, plus operational tunables (health timing, batch params, connection timeout). Factory methods:.jwt(),.anonymous(),.custom()StreamComponentProvider— optional DI overrides for internal components. Now also holdslogProvider(with sensible default)StreamClientConfigdeleted —serializationConfigandhttpConfigpromoted to top-level factory paramsretryProcessorremoved — building block, not a client concernconnectionTimeoutMsadded — configurable per socket (default 10s)authTypeexposed — anonymous connections now possible (Chat needs this)Files changed:
StreamClient.ktStreamSocketConfig.ktStreamWsUrl+ operational tunables + 3 factory methodsStreamClientConfig.ktStreamComponentProvider.ktlogProviderStreamWebSocketFactoryImpl.ktconfig.url.rawValueSampleApp.ktStreamClientConfigFactoryTest.ktStreamClientFactoryTest.ktStreamSocketConfigTest.ktStreamWebSocketFactoryImplTest.ktStreamWsUrlStreamSocketSessionTest.ktStreamWsUrlTesting
StreamCompositeEventSerializationImplTest— unrelated)pr: breaking-change