【发布时间】:2021-03-26 13:25:04
【问题描述】:
自从我尝试以任何方式连接 Unity 中的 Agora.io SDK 以来已经有几天了。 我是 Agora 的新手,刚开始学习如何使用它,我基本上尝试了所有教程来学习如何使用 SDK,但我无法让它以任何方式工作。
这是我做的步骤:
- 创建了一个新的 Agora 帐户
- 创建了新的 appID(尝试了使用和不使用令牌)
- 统一创建了一个新的空项目
- 从asset store the SDK导入
- 设置 appID 以及是否询问令牌(取决于项目是空项目还是 GitHub 上的 example project)
- 尝试连接/加入频道
- 得到如下错误: 警告代码:104 消息:查找通道超时(服务器无响应)
这些是我遵循的教程:
- https://www.youtube.com/watch?v=uxIQOZr6RiU
- https://www.agora.io/en/blog/agora-video-sdk-for-unity-quick-start-programming-guide/
- https://docs.agora.io/en/Video/start_call_unity?platform=Unity
- https://docs.agora.io/en/Video/run_demo_video_call_unity?platform=Unity
- https://medium.com/agora-io/how-to-create-a-video-chat-app-in-unity-26780b479a78
- https://www.agora.io/en/blog/how-to-embed-group-video-chat-in-your-unity-games/?utm_source=twitter&utm_medium=social&utm_campaign=embed-group-videochat-into-unity
这真是令人沮丧,我真的不知道我还能做什么。另外,我尝试在我的 PC 上打开 firewall ports 或禁用防病毒软件,但没有成功。 (在我使用 Mirror 的另一个项目中使用相同版本的 Unity 并且它可以工作,没有任何东西阻止它)
如果有用的话,这里是我遵循的tutorial 代码:
using agora_gaming_rtc;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Agora_tutorial
{
public class AgoraChat : MonoBehaviour
{
public string AppID;
public string ChannelName;
VideoSurface myView;
VideoSurface remoteView;
IRtcEngine mRtcEngine;
void Awake()
{
SetupUI();
}
void Start()
{
SetupAgora();
}
void SetupUI()
{
GameObject go = GameObject.Find("MyView");
myView = go.AddComponent<VideoSurface>();
go = GameObject.Find("JoinButton");
if (go != null)
{
Button objectButton = go.GetComponent<Button>();
objectButton.onClick.AddListener(Join);
}
go = GameObject.Find("LeaveButton");
if (go != null)
{
Button objectButton = go.GetComponent<Button>();
objectButton.onClick.AddListener(Leave);
}
}
void SetupAgora()
{
mRtcEngine = IRtcEngine.GetEngine(AppID);
// Callbacks for the local user
mRtcEngine.OnJoinChannelSuccess = OnJoinChannelSuccessHandler; // When the local user joins the channel successfully
mRtcEngine.OnLeaveChannel = OnLeaveChannelHandler; // When the local user leaves the channel
// Callbacks for the remote users
mRtcEngine.OnUserJoined = OnUserJoined; // When the remote user joins the channel
mRtcEngine.OnUserOffline = OnUserOffline; // When the remote user leaves the channel
}
public void Join()
{
Debug.Log($"Joining");
mRtcEngine.EnableVideo();
mRtcEngine.EnableVideoObserver();
myView.SetEnable(true);
mRtcEngine.JoinChannel(ChannelName, "", 0);
}
public void Leave()
{
Debug.Log($"Leaving");
mRtcEngine.LeaveChannel();
mRtcEngine.DisableVideo();
mRtcEngine.DisableVideoObserver();
}
private void OnJoinChannelSuccessHandler(string channelName, uint uid, int elapsed)
{
// can add other logics here, for now just print to the log
Debug.LogFormat("Joined channel {0} successful, my uid = {1}", channelName, uid);
}
void OnLeaveChannelHandler(RtcStats stats)
{
// Turn off the rendering, otherwise, the last frame of the camera video will stay on the RawImage.
myView.SetEnable(false);
if (remoteView != null)
{
remoteView.SetEnable(false);
}
}
void OnUserJoined(uint uid, int elapsed)
{
GameObject go = GameObject.Find("RemoteView");
if (remoteView == null)
{
remoteView = go.AddComponent<VideoSurface>();
}
remoteView.SetForUser(uid);
remoteView.SetEnable(true);
remoteView.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage);
remoteView.SetGameFps(30);
}
void OnUserOffline(uint uid, USER_OFFLINE_REASON reason)
{
remoteView.SetEnable(false);
}
void OnApplicationQuit()
{
if (mRtcEngine != null)
{
IRtcEngine.Destroy();
mRtcEngine = null;
}
}
}
}
但是当我按下加入按钮时,只有一个按钮调用(加入方法)并且没有调用回调 OnJoinChannelSuccessHandler。
【问题讨论】:
标签: c# windows unity3d agora.io