Appearance
用户信息
用户信息管理相关的 API。
getOnlineRemoteUsers
获取在线远端用户列表。
方法签名
typescript
getOnlineRemoteUsers(): string[]1
返回值
string[] - 在线远端用户 ID 数组
使用示例
javascript
const onlineUsers = engine.getOnlineRemoteUsers();
console.log('在线用户:', onlineUsers);
onlineUsers.forEach(userId => {
console.log('用户 ID:', userId);
});1
2
3
4
5
6
2
3
4
5
6
getUserInfo
获取指定用户的信息。
方法签名
typescript
getUserInfo(uid: string): AliRtcRemoteUserInfo | undefined1
参数说明
| 参数 | 类型 | 描述 |
|---|---|---|
| uid | string | 用户 ID |
返回值
AliRtcRemoteUserInfo | undefined - 用户信息对象,如果用户不存在则返回 undefined
用户信息对象说明
typescript
interface AliRtcRemoteUserInfo {
// 用户 ID
userId: string;
// 用户显示名称
displayName?: string;
// 是否推送音频
hasAudio: boolean;
// 是否推送视频
hasVideo: boolean;
// 是否推送屏幕共享
hasScreen: boolean;
// 音频是否静音
isAudioMuted: boolean;
// 视频是否静音
isVideoMuted: boolean;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
使用示例
javascript
const userInfo = engine.getUserInfo('user123');
if (userInfo) {
console.log('用户名:', userInfo.displayName);
console.log('是否有音频:', userInfo.hasAudio);
console.log('是否有视频:', userInfo.hasVideo);
console.log('是否有屏幕共享:', userInfo.hasScreen);
}1
2
3
4
5
6
7
2
3
4
5
6
7
isUserOnline
检查指定用户是否在线。
方法签名
typescript
isUserOnline(uid: string): boolean1
参数说明
| 参数 | 类型 | 描述 |
|---|---|---|
| uid | string | 用户 ID |
返回值
- true: 用户在线
- false: 用户不在线
使用示例
javascript
const isOnline = engine.isUserOnline('user123');
console.log('用户是否在线:', isOnline);
if (isOnline) {
// 用户在线,可以进行订阅操作
await engine.subscribeRemoteVideoStream('user123', true, 1);
}1
2
3
4
5
6
7
2
3
4
5
6
7
属性
channel
获取当前频道号。
类型
typescript
readonly channel: string | undefined1
说明
- 已入会成功返回频道号
- 未入会返回 undefined
使用示例
javascript
const currentChannel = engine.channel;
console.log('当前频道:', currentChannel);1
2
2
userId
获取当前用户的 userId。
类型
typescript
readonly userId: string | undefined1
说明
- 已入会成功返回自己的 userId
- 未入会返回 undefined
使用示例
javascript
const myUserId = engine.userId;
console.log('我的用户 ID:', myUserId);1
2
2
remoteUsers
获取远端用户列表。
类型
typescript
readonly remoteUsers: RemoteUser[]1
说明
返回当前频道内所有远端用户的详细信息数组。
使用示例
javascript
const remoteUsers = engine.remoteUsers;
console.log('远端用户数量:', remoteUsers.length);
remoteUsers.forEach(user => {
console.log('用户 ID:', user.userId);
console.log('用户状态:', user);
});1
2
3
4
5
6
7
2
3
4
5
6
7