How to execute disconnect with a false argument in Flutter SDK

[Problem/Question]
To control the number of simultaneous connections, we would like to execute the disconnect() method while the chat screen is not open.

However, in the current SDK implementation, the disconnect() method can only be used as a “strong” disconnect with a true logout argument.

  @override
  Future<void> disconnect({required bool logout}) async {
    sbLog.i(StackTrace.current);
    await chat.connectionManager.doDisconnect(clear: logout, logout: logout);
  }

The method that is executed when the app enters the background state is a “weak” disconnect() with a logout argument of false, allowing the use of the reconnect() method.

Is there any reason why “weak” disconnect() cannot be used when the app is in the foreground state? Are there any plans for modification?

Translated with DeepL.com (free version)


// If problem, please fill out the below. If question, please delete.
[SDK Version]

sendbird_chat_sdk 4.2.30

[Reproduction Steps]
// Please provide reproduction steps and, if possible, code snippets.

[Frequency]
// How frequently is this issue occurring?

[Current impact]
// How is this currently impacting your implementation?

Hi @y.kitaike716.

Disconnecting with logout set to false is intended for use with Local Caching.

When a user disconnects with logout set to true, the Sendbird SDK clears messages and channels stored in the local database while terminating the WebSocket connection. However, if logout is set to false, the SDK only terminates the WebSocket connection while preserving the locally stored messages and channels.

As a result, the Sendbird SDK performs a “weak” disconnect (i.e., logout = false) when the app transitions to the background. However, the SDK has its own reconnection mechanism. There is a distinction between a user manually calling disconnect() with logout set to false and the SDK automatically doing so when the app moves to the background. If a user manually calls disconnect() with logout set to false, the SDK will not attempt to reconnect until Sendbird.connect() is explicitly invoked.

Moreover, if you are not using Local Caching, the logout parameter (whether true or false) has no effect on the disconnect behavior.