Chat rooms enable real-time messaging among multiple users.
This page shows how to use the Agora Chat SDK to manage the attributes of a chat room in your app.
The Agora Chat SDK allows you to implement the following features:
Before proceeding, ensure that you meet the following requirements:
This section introduces how to call the APIs provided by the Agora Chat SDK to implement the features listed above.
All chat room members can retrieve the detailed information of the current chat room, including the subject, announcements, description, member type, and admin list.
The chat room owner and admins can also set and update the chat room information.
// Chat room members can call getChatRoomDetails to get the information of the specified chat room.
AgoraError *error = nil;
let option = {
chatRoomId: 'chatRoomId'
}
conn.getChatRoomDetails(option).then(res => console.log(res))
// The chat room owner and admins can call modifyChatRoom to update the chat room attributes.
let option = {
chatRoomId: 'chatRoomId',
chatRoomName: 'chatRoomName', // The name of the chat room
description: 'description', // The description of the chat room
maxusers: 200 // The maximum number of chat room members
}
conn.modifyChatRoom(option).then(res => console.log(res))
All chat room members can retrieve the chat room announcements.
The chat room owner and admins can set and update the chat room announcements. Once the announcements are updated, all the chat room members receive the updateAnnouncement
callback.
// Chat room members can call fetchChatRoomAnnouncement to retrieve the chat room announcements.
var option = {
roomId: 'roomId'
};
conn.fetchChatRoomAnnouncement(option).then(res => console.log(res))
// The chat room owner and admins can call updateChatRoomAnnouncement to set or update the chat room announcements.
let option = {
roomId: 'roomId',
announcement: 'hello everyone'
};
conn.updateChatRoomAnnouncement(option).then(res => console.log(res))
For details, see Chat Room Events.