Skip to main content

Quit Chatroom

Leaving a chatroom is supported in the following scenarios:

  • Passive Exit from Chatroom: Chatrooms have an automatic kick-out mechanism for offline members. When triggered, the RC server will remove the user from the chatroom. Users will also be kicked out if they are banned.

  • Active Exit from Chatroom: The client provides an API that allows users to voluntarily leave the chatroom.

Automatic Exit Mechanism for Offline Chatroom Members​

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

  • When the 31st message is generated in the chatroom within 30 seconds of the user going offline, triggering an automatic kick-out.

  • Or when a new message is generated in the chatroom after the user has been offline for 30 seconds, triggering an automatic kick-out.

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, abnormal users cannot be removed.

  • To modify the default dependency on new messages, submit a ticket to enable Real-Time Kick-Out for Abnormally Disconnected Chatroom Members. Once enabled, the server will determine whether a user is in an abnormal state based on SDK behavior (requires Android/iOS IMLib SDK version ≥ 5.1.6 or Web IMLib version ≥ 5.3.2). Abnormal users will be kicked out within 5 minutes at the latest.

  • To protect specific users (e.g., ensuring they remain in the chatroom for certain application scenarios), use the Chatroom User Allowlist feature provided by the Server API.

Active Exit from Chatroom​

Client users can voluntarily leave a chatroom. Call [quitChatRoom] to exit the chatroom.

Interface​

RongIMLib.quitChatRoom(chatRoomId)


#### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| chatRoomId | string | Yes | Chatroom ID |
| extra | string | No | Pass-through information, supported starting from version 5.30.1 |


#### Example Code

```js
const chatRoomId = "<Chatroom ID>";

RongIMLib.quitChatRoom(chatRoomId).then(res => {
// Successfully exited the chatroom
if(res.code === 0){
console.log('Exited chatroom ' + chatRoomId)
}
})

<!-- api links -->
[quitChatRoom]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#quitChatRoom