Skip to main content

Reconnection Mechanism and Reconnection Mutual Kick

Automatic Reconnection Mechanism

The SDK has implemented an automatic reconnection mechanism. Once the connection is successfully established, the SDK's reconnection mechanism will immediately take effect and handle all reconnection processes. When the connection is lost due to network issues, the SDK will internally attempt to re-establish the connection, and no additional connection operations are required from you.

Possible abnormal situations that may cause the SDK to disconnect and reconnect include:

  • Weak Network Environment: The SDK may continuously attempt to reconnect. Since there is a keep-alive mechanism between the client SDK and the RC server, if the network is too poor and causes a heartbeat timeout, the SDK will trigger a reconnection operation and keep trying until the connection is successful.
  • No Network Environment: The SDK's reconnection mechanism will pause. Once the network is restored, the SDK will attempt to reconnect.
tip

Once a connection error callback is triggered, the SDK will exit the reconnection mechanism. Please handle it based on the specific status code.

Reconnection Time Intervals

When the SDK attempts to reconnect, the time intervals increase progressively: 0s, 0.25s, 0.5s, 1s, 2s, 4s, 8s, 16s, 32s. After that, it retries every 64s.

When the app switches to the foreground or the network status changes, the reconnection time will start over from the intervals mentioned above, ensuring a quick connection in such scenarios.

Manually Exiting the Reconnection Mechanism

After the application actively disconnects, the SDK will exit the reconnection mechanism and no longer attempt to reconnect.

Reconnection Mutual Kick Strategy

The reconnection mutual kick strategy controls whether the SDK needs to kick out devices when it successfully reconnects.

By default, the IM service only allows the same user account to log in on a single mobile device. Once a newly logged-in mobile device successfully connects, the previously logged-in device will be automatically kicked out. In some cases, the SDK's reconnection mechanism may prevent the newly logged-in device from staying online.

For example, the default reconnection mutual kick strategy may lead to the following scenario:

  1. User Zhangsan attempts to log in on mobile device A, but due to unstable network on device A, the connection fails, triggering the SDK's automatic reconnection mechanism.
  2. The user then tries to log in on mobile device B. Device B successfully connects, and the user can use the IM service normally on device B.
  3. When the network on device A stabilizes, the SDK reconnects successfully. Since device A is the newly connected device, device B is kicked out.

Modifying the Reconnection Mutual Kick Strategy for App Users

If app users want to keep device B logged in while kicking out device A in the above scenario, they can modify the reconnection mutual kick strategy for the current user (User ID).

tip

Before using this interface, you must enable Allow SDK to Modify Reconnection Mutual Kick Strategy in the RC Console under Configuration > Chat settings > Basic features > Others.

Set whether to kick out the reconnecting device when the connection is lost. This configuration is part of the engine settings and must be set before initializing the engine.

let options: RCIMIWEngineOptions = {kickReconnectDevice: true};

Parameter Description

ParameterTypeDescription
kickReconnectDeviceboolWhether to kick out the reconnecting device. See the detailed explanation below for the kickReconnectDevice parameter.

Detailed Explanation of the kickReconnectDevice Parameter:

  • Set to true:

    If another mobile device is already online during reconnection, the SDK will not reconnect, and the already logged-in mobile device will remain unaffected.

  • Set to false:

    If another mobile device is already online during reconnection, the SDK will kick out the already logged-in mobile device and allow the current device to log in.