From a0f1c761005a108fb6bd990faf1e19b93e4b274c Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 15 Jun 2021 13:57:03 +0530 Subject: [PATCH] minor fixes Signed-off-by: Sahil Kumar --- packages/stream_chat/lib/src/client/client.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 9abfa94c..7a3734da 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -320,7 +320,7 @@ class StreamChatClient { } if (wsConnectionStatus == ConnectionStatus.connected) { - throw StreamChatError('Connection already connected for ${user.id}'); + throw StreamChatError('Connection already available for ${user.id}'); } _wsConnectionStatus = ConnectionStatus.connecting; @@ -343,6 +343,9 @@ class StreamChatClient { /// This will not trigger default auto-retry mechanism for reconnection. /// You need to call [openConnection] to reconnect to [_ws]. void closeConnection() { + if (wsConnectionStatus == ConnectionStatus.disconnected) return; + + logger.info('Closing web-socket connection for ${state.user?.id}'); _wsConnectionStatus = ConnectionStatus.disconnected; _connectionStatusSubscription?.cancel(); @@ -1225,6 +1228,8 @@ class StreamChatClient { /// If [flushChatPersistence] is true the client deletes all offline /// user's data. Future disconnectUser({bool flushChatPersistence = false}) async { + logger.info('Disconnecting user : ${state.user?.id}'); + // resetting state state.dispose(); state = ClientState(this); @@ -1243,15 +1248,19 @@ class StreamChatClient { /// Call this function to dispose the client Future dispose() async { + logger.info('Disposing new StreamChatClient'); + + // disposing state state.dispose(); - await _eventController.close(); - await _wsConnectionStatusController.close(); // disconnecting persistence client await _chatPersistenceClient?.disconnect(); // closing web-socket connection closeConnection(); + + await _eventController.close(); + await _wsConnectionStatusController.close(); } }