Chat rooms enable real-time messaging among multiple users.
Chat rooms do not have a strict membership, and members do not retain any permanent relationship with each other. Once going offline, chat room members cannot receive any messages from the chat room and automatically leave the chat room after 2 minutes. Chat rooms are widely applied in live broadcast use cases such as stream chat in Twitch.
This page shows how to use the Chat SDK to create and manage a chat room in your app.
The Chat SDK provides the
ChatRoom classes for chat room management, which allows you to implement the following features:
- Create and destroy a chat room
- Join and leave a chat room
- Retrieve the chat room list from the server
- Retrieve the attributes of a chat room
- Listen for chat room events
Before proceeding, ensure that you meet the following requirements:
- You have initialized the Chat SDK. For details, see SDK quickstart.
- You understand the call frequency limit of the Chat APIs supported by different pricing plans as described in Limitations.
- You understand the number of chat rooms supported by different pricing plans as described in Pricing Plan Details.
- Only the app super admin has the privilege of creating a chat room. Ensure that you have added an app super admin by calling the super-admin RESTful API.
This section introduces how to call the APIs provided by the Chat SDK to implement the features listed above.
The app super admin can call
createChatRoom to create a chat room and set the chat room attributes such as the chat room subject, description, and the maximum number of members.
All the chat users can all
joinChatRoom to join the specified chat room.
By default, when you leave a chat room, the SDK removes all the chat room messages on the local device. If you do not want these messages removed, set
All chat users can get the chat room list from the server and retrieve the basic information of the specified chat room using the chat room ID.
To monitor the chat room events, you can listen for the callbacks in the
ChatRoomManager class and add app logics accordingly. If you want to stop listening for the callback, make sure that you remove the listener to prevent memory leakage.