StreamChatClient constructor
StreamChatClient(
- String apiKey, {
- Level logLevel = Level.WARNING,
- LogHandlerFunction? logHandlerFunction,
- RetryPolicy? retryPolicy,
- @Deprecated(''' Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0. Read more here: https://getstream.io/blog/chat-edge-infrastructure ''') Location? location,
- String? baseURL,
- Duration connectTimeout = const Duration(seconds: 6),
- Duration receiveTimeout = const Duration(seconds: 6),
- StreamChatApi? chatApi,
- WebSocket? ws,
- AttachmentFileUploader? attachmentFileUploader,
Create a client instance with default options. You should only create the client once and re-use it across your application.
Implementation
StreamChatClient(
String apiKey, {
this.logLevel = Level.WARNING,
LogHandlerFunction? logHandlerFunction,
RetryPolicy? retryPolicy,
@Deprecated('''
Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0.
Read more here: https://getstream.io/blog/chat-edge-infrastructure
''') Location? location,
String? baseURL,
Duration connectTimeout = const Duration(seconds: 6),
Duration receiveTimeout = const Duration(seconds: 6),
StreamChatApi? chatApi,
WebSocket? ws,
AttachmentFileUploader? attachmentFileUploader,
}) {
this.logHandlerFunction = logHandlerFunction ?? _defaultLogHandler;
logger.info('Initiating new StreamChatClient');
final options = StreamHttpClientOptions(
baseUrl: baseURL,
connectTimeout: connectTimeout,
receiveTimeout: receiveTimeout,
headers: {'X-Stream-Client': defaultUserAgent},
);
_chatApi = chatApi ??
StreamChatApi(
apiKey,
options: options,
tokenManager: _tokenManager,
connectionIdManager: _connectionIdManager,
attachmentFileUploader: attachmentFileUploader,
logger: detachedLogger('πΈοΈ'),
);
_ws = ws ??
WebSocket(
apiKey: apiKey,
baseUrl: options.baseUrl,
tokenManager: _tokenManager,
handler: handleEvent,
logger: detachedLogger('π'),
queryParameters: {'X-Stream-Client': defaultUserAgent},
);
_retryPolicy = retryPolicy ??
RetryPolicy(
shouldRetry: (_, attempt, __) => attempt < 5,
retryTimeout: (_, attempt, __) => Duration(seconds: attempt),
);
state = ClientState(this);
}