Reconnection Mechanism and Reconnection Kick Policy
Automatic Reconnection Mechanism
The IMLib SDK has a built-in automatic reconnection mechanism. Once connected, the SDK's reconnection mechanism takes effect immediately and handles all reconnection processes. When disconnection occurs due to network issues, the SDK will automatically attempt to reconnect without requiring additional manual operations.
Common scenarios that may trigger SDK reconnection include:
- Weak network conditions: The SDK may repeatedly attempt reconnection. Since there's a keep-alive mechanism between the client SDK and RC servers, heartbeat timeouts caused by poor network quality will trigger reconnection attempts until successful.
- No network connectivity: The reconnection mechanism pauses. Once network connectivity is restored, the SDK resumes reconnection attempts.
When a connection error callback is triggered, the SDK exits the reconnection mechanism. Handle this scenario based on the specific status code.
Reconnection Intervals
The SDK uses progressively increasing intervals for reconnection attempts: 0.05s (0s before v5.6.2), 0.25s, 0.5s, 1s, 2s, 4s, 8s, 16s, 32s. Subsequent attempts occur every 64s.
When the app returns to the foreground or network status changes, the reconnection interval resets to the initial sequence to ensure prompt reconnection.
Manual Exit from Reconnection Mechanism
When the app actively disconnects, the SDK exits the reconnection mechanism and stops further attempts.
Reconnection Kick Policy
This policy determines whether automatically reconnected devices should be kicked when another device is already online.
By default, RC Chat only allows a single user account to be logged in on one mobile device at a time. When a new mobile device connects successfully, it automatically kicks out previously logged-in devices. In some scenarios, the SDK's reconnection mechanism may prevent newly connected devices from staying online.
Example scenario with default policy:
- User Zhangsan attempts to log in on Device A, but unstable network prevents successful connection, triggering automatic reconnection.
- The user then logs in successfully on Device B and can use RC Chat normally.
- When Device A's network stabilizes and reconnects successfully, it becomes the "newer" device, causing Device B to be kicked.
Modifying Reconnection Kick Policy
If you want Device A to be kicked while keeping Device B online in such scenarios, modify your reconnection kick policy.
IMKit doesn't provide direct APIs for this. Use IMLib SDK's setReconnectKickEnable
method if needed. See IMLib documentation: Reconnection Mechanism and Reconnection Kick Policy.