环信聊天室模型支持最大成员数为5000,和群组不同,聊天室内成员离线后,服务器当监听到此成员不在线后不再会给此成员再发推送。
curl -X POST “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms” -H “Authorization: Bearer ${token}” -d ‘{“owner”:”u1”,”members”:[“u1”,”u2”],”maxusers”:5000,”groupname”:”chatroom title”,”desc”:”chatroom description”}”
curl -X GET “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms” -H “Authorization: Bearer ${token}”
curl -X GET “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/1430798028680235” -H “Authorization: Bearer ${token}”
curl -X DELETE ‘https://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/1430798028680235/users/u2’ -H “Authorization: Bearer ${token}”
curl -X DELETE ‘https://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/143228117786605’ -H “Authorization: Bearer ${token}”
更多服务器端 REST 操作请参考聊天室管理。
EMChatroomManager(EMClient.getInstance().chatroomManager())
操作。//roomId为聊天室ID
EMClient.getInstance().chatroomManager().joinChatRoom(roomId, new EMValueCallBack<EMChatRoom>() {
@Override
public void onSuccess(EMChatRoom value) {
//加入聊天室成功
}
@Override
public void onError(final int error, String errorMsg) {
//加入聊天室失败
}
});
注意:对于聊天室模型,请一定要等到 Join 回调成功后再去初始化 conversation。
EMClient.getInstance().chatroomManager().leaveChatRoom(toChatUsername);
此方法是异步方法,不会阻塞当前线程。此方法没有回调,原因是在任何场景下退出聊天室,SDK 保证退出成功,无论有网出错,还是无网退出。对于聊天室模型,一般退出会话页面,就会调用此 leave 方法。
/**
* \~chinese
* 创建聊天室,聊天室最大人数上限10000。只有特定用户有权限创建聊天室。
* @param subject 名称
* @param description 描述
* @param welcomeMessage 邀请成员加入聊天室的消息
* @param maxUserCount 允许加入聊天室的最大成员数
* @param members 邀请加入聊天室的成员列表
* @return EMChatRoom 聊天室
* @throws HyphenateException
*/
EMClient.getInstance().chatroomManager().createChatRoom(String subject, String description, String welcomeMessage,
int maxUserCount, List<String> members);
/**
* 销毁聊天室,需要owner权,同步方法
* @param chatRoomId
* @throws HyphenateException
*/
EMClient.getInstance().chatroomManager().destroyChatRoom(String chatRoomId);
EMCursorResult<EMChatRoom> result = EMClient.getInstance().chatroomManager().fetchPublicChatRoomsFromServer(pageSize, cursor)
参数:
返回值:
EMCursorResult<EMChatRoom> 内部包含返回的cursor和List<EMChatRoom>
代码
EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(roomId)
room.getName();//聊天室名称
room.getId();//聊天室id
room.getDescription();//聊天室描述
room.getOwner();//聊天室创建者
.
.
.
参考API文档
roomId 聊天室id
fetchMembers 是否要获取聊天室成员
EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(roomId, fetchMembers)
// 修改聊天室名称
EMClient.getInstance().chatroomManager().changeChatRoomSubject(String chatRoomId, String newSubject);
// 修改聊天室描述
EMClient.getInstance().chatroomManager().changeChatroomDescription(String chatRoomId, String newDescription));
/**
* \~chinese
* 禁止聊天室成员发言,需要聊天室拥有者或者管理员权限
* @param chatRoomId
* @param muteMembers 禁言的用户列表
* @param duration 禁言的时间,单位是毫秒
* @return 聊天室
* @throws HyphenateException
*/
EMClient.getInstance().chatroomManager().muteChatRoomMembers(String chatRoomId, List<String> muteMembers, long duration);
/**
* \~chinese
* 取消禁言,需要聊天室拥有者或者管理员权限
* @param chatRoomId
* @param members
* @return
* @throws HyphenateException
*/
EMClient.getInstance().chatroomManager().unMuteChatRoomMembers(String chatRoomId, List<String> members);
/**
* \~chinese
* 获取聊天室的禁言列表,需要拥有者或者管理员权限
* @param chatRoomId
* @param pageNum 分页获取禁言列表
* @param pageSize 每页包含禁言成员数目
* @return Map.entry.key 是禁言的成员id,Map.entry.value是禁言动作失效的时间,单位是毫秒
* @throws HyphenateException
*/
Map<String, Long> mutes = EMClient.getInstance().chatroomManager().fetchChatRoomMuteList(String chatRoomId, int pageNum, int pageSize);
//增加聊天室管理员
EMChatRoom chatRoom = EMClient.getInstance().chatroomManager().addChatRoomAdmin(String chatRoomId, String admin);
//删除聊天室管理员
EMChatRoom chatRoom = EMClient.getInstance().chatroomManager().removeChatRoomAdmin(String chatRoomId, String admin);
//获取管理员列表,需要先获取群详情
EMChatRoom chatRoom = EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(String roomId);
List<String> adminList = chatroom.getAdminList();
/**
* 删除聊天室成员,需要拥有者或者管理员权限
* @param chatRoomId
* @param members
* @return
* @throws HyphenateException
*/
EMChatRoom chatRoom = EMClient.getInstance().chatroomManager().removeChatRoomMembers(String chatRoomId, List<String> members);
// 添加成员到黑名单,禁止成员继续加入聊天室,需要拥有者或者管理员权限
EMChatRoom chatroom = EMClient.getInstance().chatroomManager().blockChatroomMembers(String chatRoomId, List<String> members);
//将成员从黑名单种移除,需要拥有者或者管理员权限
EMChatRoom chatroom = EMClient.getInstance().chatroomManager().unblockChatRoomMembers(String chatRoomId, List<String> members);
//分页获取聊天室黑名单
List<String> blackList = EMClient.getInstance().chatroomManager().fetchChatRoomBlackList(String chatRoomId, int pageNum, int pageSize);
EMClient.getInstance().chatroomManager().fetchChatRoomAnnouncement(roomId);
EMClient.getInstance().chatroomManager().updateChatRoomAnnouncement(chatRoomId, announcement);
在会话页面注册监听,来监听成员被踢和聊天室被删除。
EMClient.getInstance().chatroomManager().addChatRoomChangeListener(new EMChatRoomChangeListener(){
@Override
public void onChatRoomDestroyed(String roomId, String roomName) {
}
@Override
public void onMemberJoined(String roomId, String participant) {
}
@Override
public void onMemberExited(String roomId, String roomName, String participant) {
}
@Override
public void onMemberKicked(String roomId, String roomName, String participant) {
}
@Override
public void onMuteListAdded(final String chatRoomId, final List<String> mutes, final long expireTime) {
}
@Override
public void onMuteListRemoved(final String chatRoomId, final List<String> mutes) {
}
@Override
public void onAdminAdded(final String chatRoomId, final String admin) {
}
@Override
public void onAdminRemoved(final String chatRoomId, final String admin) {
}
@Override
public void onOwnerChanged(final String chatRoomId, final String newOwner, final String oldOwner) {
}
@Override
public void onAnnouncementChanged(String chatRoomId, final String announcement) {
}
});