Skip to content

Commit

Permalink
Merge pull request #728 from haoxiuwen/doc-v2
Browse files Browse the repository at this point in the history
Add Android Doc for Updating the Count of Chat Room Member in Real Time
  • Loading branch information
haoxiuwen authored Apr 18, 2024
2 parents 765abae + 31c3b60 commit 5f876fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/document/android/room_manage.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,32 @@ public interface EMChatRoomChangeListener {
default void onChatroomAttributesDidRemoved(String chatRoomId, Map<String,String> attributeMap , String from){}

}
```

### 实时更新聊天室成员人数

如果聊天室短时间内有成员频繁加入或退出时,实时更新聊天室成员人数的逻辑如下:

1. 聊天室内有成员加入时,其他成员会收到 `onMemberJoined` 事件。有成员主动或被动退出时,其他成员会收到 `onMemberExited``onRemovedFromChatRoom` 事件。

2. 收到通知事件后,调用 `EMChatRoomManager#getChatRoom` 方法获取本地聊天室详情,再通过`EMChatRoom#getMemberCount`获取聊天室当前人数。

```java
EMClient.getInstance().chatroomManager().addChatRoomChangeListener(new EMChatRoomChangeListener() {

@Override
public void onMemberJoined(String roomId, String participant) {
//获取聊天室在线人数
int memberCount = EMClient.getInstance().chatroomManager().getChatRoom(roomId).getMemberCount();

}

@Override
public void onMemberExited(String roomId, String roomName, String participant) {
//int memberCount = EMClient.getInstance().chatroomManager().getChatRoom(roomId).getMemberCount();
}

……
});

```
1 change: 1 addition & 0 deletions docs/document/android/room_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
| 获取聊天室详情 | 所有聊天室成员有权限获取聊天室详情。 |
| 修改聊天室名称 | 需要聊天室所有者权限。 |
| 聊天室公告 | 仅聊天室所有者有权限编辑公告、删除公告。<br/>公告更新会通过监听同步给所有成员。 |
| 实时更新聊天室成员人数 | 如果聊天室短时间内有成员频繁加入或退出时,可以实现实时更新聊天室成员人数。|

#### 聊天室成员管理

Expand Down

0 comments on commit 5f876fa

Please sign in to comment.