Skip to main content

Leave Chatroom

Leaving a chatroom is supported in the following scenarios:

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

Automatic Exit Mechanism for Offline Chatroom Members

The chatroom has an automatic exit mechanism for offline members. After a user goes offline, if the following default preset conditions are met, the RC server will automatically kick the user out of the chatroom:

  • Within 30 seconds after the user goes offline, when the 31st message is generated in the chatroom, the automatic kick-out is triggered.
  • Or, if the user has been offline for more than 30 seconds, when a new message is generated in the chatroom, the automatic kick-out is triggered.
tip
  • The default preset 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, abnormal users cannot be kicked out.
  • If you need to modify the default behavior's dependency on new messages, please submit a ticket to apply for Real-time Kick-out for Abnormal Chatroom Members. After enabling this service, the server will determine whether a user is in an abnormal state based on SDK behavior, and the abnormal user can be kicked out within 5 minutes at the latest.
  • If you need to protect specific users, i.e., prevent automatic kick-out of designated users (such as in certain application scenarios where users may need to stay in the chatroom), you can use the Chatroom User Allowlist function provided by the Server API.

Active Exit from Chatroom

Client users can actively leave the chatroom.

Method


leaveChatRoom(
targetId: string,
callback: IRCIMIWLeaveChatRoomCallback
): Promise<number>;

Parameter Description

Parameter NameParameter TypeDescription
targetIdstringChatroom Conversation ID
callbackIRCIMIWLeaveChatRoomCallbackInterface call result callback.

Return Value

Return ValueDescription
numberStatus code of the current interface operation. 0 indicates a successful call. Specific results need to be implemented in 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


const callback = {
onChatRoomLeft: (code: number, targetId: string) => {
//...
},
};
let code = await engine.leaveChatRoom(targetId, callback);