Skip to main content

Leave Chatroom

Leaving a chatroom can occur in the following scenarios:

  • Passive Exit: Chatrooms have an automatic kick-out mechanism for offline members. When triggered, the RC server will remove the user from the chatroom. Users who are banned will also be removed from the chatroom.
  • Active Exit: The client provides an API that allows users to actively leave the chatroom.

Automatic Exit Mechanism for Offline Chatroom Members

Chatrooms have an automatic exit mechanism for offline members. When a user goes offline, if the following default conditions are met, the RC server will automatically remove the user from the chatroom:

  • If the 31st message is generated within 30 seconds after the user goes offline, the automatic kick-out is triggered.
  • Or, if a new message is generated in the chatroom 30 seconds after the user goes offline, the automatic kick-out is triggered.
tip
  • The default conditions require that new messages must be generated in the chatroom; otherwise, the kick-out action cannot be triggered. If no messages are generated in the chatroom, the abnormal user cannot be removed.
  • If you need to modify the default behavior's dependency on new messages, please submit a ticket to apply for the Real-time Kick-out for Abnormal Chatroom Members service. After enabling this service, the server will determine whether a user is in an abnormal state based on SDK behavior, and the abnormal user will be removed from the chatroom within 5 minutes at the latest.
  • To protect specific users from being automatically removed (e.g., in certain application scenarios where users may need to stay in the chatroom), you can use the Chatroom User Whitelist feature provided by the Server API.

Active Exit from Chatroom

Client users can actively leave a chatroom.

Method

Future<int> leaveChatRoom(String targetId, {IRCIMIWLeaveChatRoomCallback? callback});

Parameter Description

ParameterTypeDescription
targetIdStringChatroom conversation ID
callbackIRCIMIWLeaveChatRoomCallbackEvent callback. The SDK supports callback mode from version 5.3.1. Other callback methods for this interface are deprecated starting from version 5.4.0. If the callback parameter is passed, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>Status code of the current interface operation. 0 indicates success. The specific result needs to be implemented through the interface callback. Non-zero indicates that the current interface call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes.

Code Example

IRCIMIWLeaveChatRoomCallback? callback = IRCIMIWLeaveChatRoomCallback(onChatRoomLeft: (int? code, String? targetId) {
//...
});

int? ret = await engine?.leaveChatRoom(targetId, callback:callback);

Callback Method

  • onChatRoomLeft
Function(int? code, String? targetId)? onChatRoomLeft;

Parameter Description

ParameterTypeDescription
codeintStatus code of the interface callback. 0 indicates success, non-zero indicates an exception.
targetIdStringConversation ID

Code Example

engine?.onChatRoomLeft = (int? code, String? targetId) {
//...
};