public class PresenceApi extends Object
构造器和说明 |
---|
PresenceApi(Context context) |
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Mono<PresenceUserStatusSubscribeResult> |
getSubscribeList(String operator,
int pageNum,
int pageSize)
查询订阅列表。
|
reactor.core.publisher.Mono<Integer> |
getUserOnlineCount(String id,
int type)
查询单个群组的在线成员数量。
|
reactor.core.publisher.Mono<List<PresenceUserStatusResource>> |
getUserStatus(String operator,
List<String> usernames)
批量获取在线状态信息。
|
reactor.core.publisher.Mono<Void> |
setUserStatus(String username,
String resource,
String status,
String ext)
设置用户在线状态信息。
|
reactor.core.publisher.Mono<List<PresenceUserStatusSubscribeResource>> |
subscribeUserStatus(String operator,
List<String> usernames,
Long expiry)
批量订阅在线状态。
|
reactor.core.publisher.Mono<Void> |
unsubscribeUserStatus(String operator,
List<String> usernames)
取消订阅多个用户的在线状态。
|
public PresenceApi(Context context)
public reactor.core.publisher.Mono<Void> setUserStatus(String username, String resource, String status, String ext)
API使用示例:
EMService service;
try {
service.presence().setUserStatus("username", "resource", "1", "ext").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 设置哪个用户的在线状态信息。resource
- 要设置用户在哪个设备的在线状态信息,即传入服务器分配给每个设备资源的唯一标识符,格式为 {device type}_{resource ID},其中设备类型 device type 可以是 android、ios 或 web,资源 ID resource ID 由 SDK 分配。例如,android_123423453246。status
- 用户的在线状态:- 0:离线;- 1:在线;- 其它数字字符串:自定义在线状态。ext
- 在线状态扩展信息。建议不超过 1024 字节。public reactor.core.publisher.Mono<List<PresenceUserStatusResource>> getUserStatus(String operator, List<String> usernames)
API使用示例:
EMService service;
try {
List<String> usernames = Arrays.asList("test_user1", "test_user2");
List<PresenceUserStatusResource> userStatus = service.presence().getUserStatus("operator", usernames).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
operator
- 操作者用户名usernames
- 需要获取其在线状态的用户列表,例如 ["user1", "user2"],最多可传 100 个用户 ID。public reactor.core.publisher.Mono<List<PresenceUserStatusSubscribeResource>> subscribeUserStatus(String operator, List<String> usernames, Long expiry)
API使用示例:
EMService service;
try {
List<String> usernames = Arrays.asList("test_user1", "test_user2");
List<PresenceUserStatusSubscribeResource> subscribeUserStatus = service.presence().subscribeUserStatus("operator", usernames, 86400).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
operator
- 为哪个用户订阅在线状态。usernames
- 被订阅用户的用户 ID 数组,例如 ["user1", "user2"]。该数组最多可包含 100 个用户 ID。expiry
- 订阅时长,单位为秒,最大值为 2,592,000,即 30 天。public reactor.core.publisher.Mono<Void> unsubscribeUserStatus(String operator, List<String> usernames)
API使用示例:
EMService service;
try {
List<String> usernames = Arrays.asList("test_user1", "test_user2");
service.presence().unsubscribeUserStatus("operator", usernames).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
operator
- 为哪个用户取消订阅的在线状态。usernames
- 要取消订阅在线状态的用户 ID 数组,例如 ["user1", "user2"],最多可传 100 个用户 ID。public reactor.core.publisher.Mono<PresenceUserStatusSubscribeResult> getSubscribeList(String operator, int pageNum, int pageSize)
API使用示例:
EMService service;
try {
PresenceUserStatusSubscribeResult result = service.presence().getSubscribeList("operator", 1, 10).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
operator
- 查询哪个用户的订阅列表。若传入的用户 ID 不存在或未订阅其他用户的在线状态,返回空列表。pageNum
- 要查询的页码。该参数的值须大于等于 1。若不传,默认值为 1。pageSize
- 每页显示的订阅用户数量。取值范围为 [1,500],若不传默认值为 1。public reactor.core.publisher.Mono<Integer> getUserOnlineCount(String id, int type)
API使用示例:
EMService service;
try {
Integer onlineCount = service.presence().getUserOnlineCount("1324236456", 1).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
id
- 群组 ID。type
- 查询类型,查询群组的在线成员数量,传 1 即可。Copyright © 2024. All rights reserved.