Class ChatClient.Builder
-
- All Implemented Interfaces:
public final class ChatClient.Builder extends ChatClient.ChatClientBuilder
Builder to initialize the singleton ChatClient instance and configure its parameters.
-
-
Constructor Summary
Constructors Constructor Description ChatClient.Builder(String apiKey, Context appContext)
-
Method Summary
Modifier and Type Method Description final ChatClient.BuilderlogLevel(ChatLogLevel level)Sets the log level to be used by the client. final ChatClient.BuilderloggerHandler(ChatLoggerHandler loggerHandler)Sets a ChatLoggerHandler instance that will receive log events from the SDK. final ChatClient.BuilderclientDebugger(ChatClientDebugger clientDebugger)Sets a ChatClientDebugger instance that will be invoked accordingly through various flows within SDK. final ChatClient.Buildernotifications(NotificationConfig notificationConfig, NotificationHandler notificationsHandler)Sets a custom NotificationHandler that the SDK will use to handle everything around push notifications. final ChatClient.Buildernotifications(NotificationConfig notificationConfig)Sets a custom NotificationHandler that the SDK will use to handle everything around push notifications. final ChatClient.BuilderfileTransformer(FileTransformer fileTransformer)Sets a custom FileTransformer implementation that will be used by the client to transform files before uploading them. final ChatClient.BuilderwithApiModelTransformer(ApiModelTransformers apiModelTransformers)Sets a custom ApiModelTransformers implementation that will be used by the client to transform models. final ChatClient.BuilderfileUploader(FileUploader fileUploader)Sets a custom file uploader implementation that will be used by the client to upload files and images. final ChatClient.BuildersendMessageInterceptor(SendMessageInterceptor sendMessageInterceptor)Sets a custom message sender implementation that will be used to send messages to the server. final ChatClient.BuilderdisableWarmUp()By default, ChatClient performs a dummy HTTP call to the Stream API when a user is set to initialize the HTTP connection and make subsequent requests reusing this connection execute faster. final ChatClient.BuilderokHttpClient(OkHttpClient okHttpClient)Sets a custom OkHttpClient that will be used by the client to perform API calls to Stream. final ChatClient.BuilderbaseUrl(String value)Sets the base URL to be used by the client. final ChatClient.BuilderforceHttpUrl(String value)Sets the HTTP URL to be used by the client. final ChatClient.BuilderforceWsUrl(String value)Sets the WebSocket URL to be used by the client. final ChatClient.BuildercdnUrl(String value)Sets the CDN URL to be used by the client. final ChatClient.BuilderforceInsecureConnection()Force to use insecure connection (HTTP) instead of secure connection (HTTPS). final ChatClient.BuilderwithRepositoryFactoryProvider(RepositoryFactory.Provider provider)Inject a RepositoryFactory.Provider to use your own DB Persistence mechanism. final ChatClient.BuilderwithPlugins(PluginFactory pluginFactories)Adds plugins factory to be used by the client. final ChatClient.BuildercredentialStorage(UserCredentialStorage credentialStorage)Overrides a default, based on shared preferences implementation for UserCredentialStorage. final ChatClient.BuilderdebugRequests(Boolean shouldDebug)Debug requests using ApiRequestsAnalyser. final ChatClient.BuilderretryPolicy(RetryPolicy retryPolicy)Sets a custom RetryPolicy used to determine whether a particular call should be retried. final ChatClient.BuilderdisableDistinctApiCalls()Allows simultaneous network calls of the same request, avoiding combining them into one. final ChatClient.BuilderuploadAttachmentsNetworkType(UploadAttachmentsNetworkType type)An enumeration of various network types used as a constraint inside upload attachments worker. final ChatClient.BuilderappName(String appName)Sets name of the application that is using the Stream Chat SDK. final ChatClient.BuilderappVersion(String appVersion)Sets version of the application that is using the Stream Chat SDK. ChatClientbuild()Create a ChatClient instance based on the current configuration of the Builder. ChatClientinternalBuild()-
-
Constructor Detail
-
ChatClient.Builder
ChatClient.Builder(String apiKey, Context appContext)
- Parameters:
apiKey- The API key of your Stream Chat app obtained from the Stream Dashboard.appContext- The application Context.
-
-
Method Detail
-
logLevel
final ChatClient.Builder logLevel(ChatLogLevel level)
Sets the log level to be used by the client.
See ChatLogLevel for details about the available options.
We strongly recommend using ChatLogLevel.NOTHING in production builds, which produces no logs.
- Parameters:
level- The log level to use.
-
loggerHandler
final ChatClient.Builder loggerHandler(ChatLoggerHandler loggerHandler)
Sets a ChatLoggerHandler instance that will receive log events from the SDK.
Use this to forward SDK events to your own logging solutions.
See the FirebaseLogger class in the UI Components sample app for an example implementation.
- Parameters:
loggerHandler- Your custom ChatLoggerHandler implementation.
-
clientDebugger
final ChatClient.Builder clientDebugger(ChatClientDebugger clientDebugger)
Sets a ChatClientDebugger instance that will be invoked accordingly through various flows within SDK.
Use this to debug SDK inner processes like Message sending.
- Parameters:
clientDebugger- Your custom ChatClientDebugger implementation.
-
notifications
@JvmOverloads() final ChatClient.Builder notifications(NotificationConfig notificationConfig, NotificationHandler notificationsHandler)
Sets a custom NotificationHandler that the SDK will use to handle everything around push notifications. Create your own subclass and override methods to customize notification appearance and behavior.
See the Push Notifications documentation for more information.
- Parameters:
notificationConfig- Config push notification.notificationsHandler- Your custom class implementation of NotificationHandler.
-
notifications
@JvmOverloads() final ChatClient.Builder notifications(NotificationConfig notificationConfig)
Sets a custom NotificationHandler that the SDK will use to handle everything around push notifications. Create your own subclass and override methods to customize notification appearance and behavior.
See the Push Notifications documentation for more information.
- Parameters:
notificationConfig- Config push notification.
-
fileTransformer
final ChatClient.Builder fileTransformer(FileTransformer fileTransformer)
Sets a custom FileTransformer implementation that will be used by the client to transform files before uploading them.
-
withApiModelTransformer
final ChatClient.Builder withApiModelTransformer(ApiModelTransformers apiModelTransformers)
Sets a custom ApiModelTransformers implementation that will be used by the client to transform models.
-
fileUploader
final ChatClient.Builder fileUploader(FileUploader fileUploader)
Sets a custom file uploader implementation that will be used by the client to upload files and images.
The default implementation uses Stream's own CDN to store these files, which has a 100 MB upload size limit.
For more info, see the File Uploads documentation.
- Parameters:
fileUploader- Your custom implementation of FileUploader.
-
sendMessageInterceptor
final ChatClient.Builder sendMessageInterceptor(SendMessageInterceptor sendMessageInterceptor)
Sets a custom message sender implementation that will be used to send messages to the server. By providing a custom SendMessageInterceptor you can override the logic for sending messages with your own custom logic.
Example: You can use this to send any message to your own server (instead of the Stream server), which would later be synced between your own server and the Stream server.
See SendMessageInterceptor for more information.
IMPORTANT: This is an experimental API and can be changed or removed in the future.
- Parameters:
sendMessageInterceptor- Your custom implementation of SendMessageInterceptor.
-
disableWarmUp
final ChatClient.Builder disableWarmUp()
By default, ChatClient performs a dummy HTTP call to the Stream API when a user is set to initialize the HTTP connection and make subsequent requests reusing this connection execute faster.
Calling this method disables this connection warm-up behavior.
-
okHttpClient
final ChatClient.Builder okHttpClient(OkHttpClient okHttpClient)
Sets a custom OkHttpClient that will be used by the client to perform API calls to Stream.
Use this to configure parameters like timeout values, or to add interceptors to process all network requests.
- Parameters:
okHttpClient- The client to use for API calls.
-
baseUrl
final ChatClient.Builder baseUrl(String value)
Sets the base URL to be used by the client.
By default, this is the URL of Stream's Edge API Infrastructure, which provides low latency regardless of which region your Stream app is hosted in.
You should only change this URL if you're on dedicated Stream Chat infrastructure.
- Parameters:
value- The base URL to use.
-
forceHttpUrl
final ChatClient.Builder forceHttpUrl(String value)
Sets the HTTP URL to be used by the client.
This for internal use only.
- Parameters:
value- The HTTP URL to use.
-
forceWsUrl
final ChatClient.Builder forceWsUrl(String value)
Sets the WebSocket URL to be used by the client.
This for internal use only.
- Parameters:
value- The WebSocket URL to use.
-
cdnUrl
final ChatClient.Builder cdnUrl(String value)
Sets the CDN URL to be used by the client.
-
forceInsecureConnection
final ChatClient.Builder forceInsecureConnection()
Force to use insecure connection (HTTP) instead of secure connection (HTTPS). This is useful for testing purposes. By default, the client uses HTTPS. Production apps should always use HTTPS.
-
withRepositoryFactoryProvider
final ChatClient.Builder withRepositoryFactoryProvider(RepositoryFactory.Provider provider)
Inject a RepositoryFactory.Provider to use your own DB Persistence mechanism.
-
withPlugins
final ChatClient.Builder withPlugins(PluginFactory pluginFactories)
Adds plugins factory to be used by the client.
- Parameters:
pluginFactories- The factories to be added.
-
credentialStorage
final ChatClient.Builder credentialStorage(UserCredentialStorage credentialStorage)
Overrides a default, based on shared preferences implementation for UserCredentialStorage.
-
debugRequests
final ChatClient.Builder debugRequests(Boolean shouldDebug)
Debug requests using ApiRequestsAnalyser. Use this to debug your requests. This shouldn't be enabled in release builds as it uses a memory cache.
-
retryPolicy
final ChatClient.Builder retryPolicy(RetryPolicy retryPolicy)
Sets a custom RetryPolicy used to determine whether a particular call should be retried. By default, no calls are retried.
- Parameters:
retryPolicy- Custom RetryPolicy implementation.
-
disableDistinctApiCalls
final ChatClient.Builder disableDistinctApiCalls()
Allows simultaneous network calls of the same request, avoiding combining them into one. By default distinctApiCalls is enabled.
-
uploadAttachmentsNetworkType
final ChatClient.Builder uploadAttachmentsNetworkType(UploadAttachmentsNetworkType type)
An enumeration of various network types used as a constraint inside upload attachments worker.
-
appName
final ChatClient.Builder appName(String appName)
Sets name of the application that is using the Stream Chat SDK. Used for logging and debugging purposes.
-
appVersion
final ChatClient.Builder appVersion(String appVersion)
Sets version of the application that is using the Stream Chat SDK. Used for logging and debugging purposes. Eg: 1.0.0
-
build
ChatClient build()
Create a ChatClient instance based on the current configuration of the Builder.
-
internalBuild
ChatClient internalBuild()
-
-
-
-