【发布时间】:2019-04-12 09:10:55
【问题描述】:
我正在使用 Agora.io Unity SDK 在游戏中实现视频聊天功能。但我不知道如何检索频道中当前存在的用户列表。有人知道怎么做吗?
【问题讨论】:
-
欢迎来到stackoverflow,请查看这篇文章:stackoverflow.com/help/how-to-ask。请通过添加有关您的问题的更多详细信息来编辑您的问题,并提供您迄今为止尝试过的代码示例
我正在使用 Agora.io Unity SDK 在游戏中实现视频聊天功能。但我不知道如何检索频道中当前存在的用户列表。有人知道怎么做吗?
【问题讨论】:
没有脚本可以查询频道中的用户列表。您必须自己跟踪。很简单。
在初始化 Agora 引擎的脚本中,创建一个列表
static List<uint> remoteStreams = new List<uint>();
然后,每当您初始化引擎时,请务必包含回调以侦听任何加入流的远程用户。
mRtcEngine.OnUserJoined += (uint uid, int elapsed) => {
string userJoinedMessage = string.Format("onUserJoined with uid {0}", uid);
Debug.Log(userJoinedMessage);
remoteStreams.Add(uid); // add remote stream id to list of users
};
一旦用户加入频道,就会为频道中的每个现有用户调用上述回调,然后在有新人加入时再次调用。
【讨论】: