AgoraRTCManager.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. using Agora.Rtc;
  2. using Agora.Util;
  3. using SC.XR.Unity;
  4. using ShadowStudio.Model;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Runtime.Remoting.Contexts;
  8. using UnityEngine;
  9. using UnityEngine.Serialization;
  10. using UnityEngine.UI;
  11. using XRTool.Util;
  12. using static Reporter;
  13. public class AgoraRTCManager : SingletonMono<AgoraRTCManager>
  14. {
  15. [FormerlySerializedAs("appIdInput")]
  16. [SerializeField]
  17. private AppIdInput _appIdInput;
  18. [Header("_____________Basic Configuration_____________")]
  19. [FormerlySerializedAs("APP_ID")]
  20. [SerializeField]
  21. private string _appID = "";
  22. [FormerlySerializedAs("TOKEN")]
  23. [SerializeField]
  24. private string _token = "";
  25. [FormerlySerializedAs("CHANNEL_NAME")]
  26. [SerializeField]
  27. private string _channelName = "";
  28. private uint uid;
  29. private string peerid;
  30. internal IRtcEngine RtcEngine = null;
  31. private AgoraCustomPeer myPeer;
  32. private Dictionary<string, uint> dicPeeridAndUid;
  33. private List<AgoraCustomPeer> listCustomPeer;
  34. public bool isSwitchCamera;
  35. public uint Uid
  36. {
  37. get { return uid; }
  38. set { uid = value; }
  39. }
  40. public AgoraCustomPeer MyPeer
  41. {
  42. get { return myPeer; }
  43. set { if(value!=null) myPeer = value; }
  44. }
  45. public string ChannelName
  46. {
  47. get { return _channelName; }
  48. set { if (value != null) _channelName = value; }
  49. }
  50. public string PeerId
  51. {
  52. get { return peerid; }
  53. set { if (value != null) peerid = value; }
  54. }
  55. private void Start()
  56. {
  57. LoadAssetData();
  58. //if (_appID.Length > 10)
  59. //{
  60. //}
  61. InitEngine();
  62. dicPeeridAndUid = new Dictionary<string, uint>();
  63. isSwitchCamera = false;
  64. listCustomPeer = new List<AgoraCustomPeer>();
  65. }
  66. private void Update()
  67. {
  68. PermissionHelper.RequestMicrophontPermission();
  69. PermissionHelper.RequestCameraPermission();
  70. }
  71. //Show data in AgoraBasicProfile
  72. [ContextMenu("ShowAgoraBasicProfileData")]
  73. private void LoadAssetData()
  74. {
  75. if (_appIdInput == null) return;
  76. _appID = _appIdInput.appID;
  77. _token = _appIdInput.token;
  78. _channelName = _appIdInput.channelName;
  79. }
  80. private void InitEngine()
  81. {
  82. RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
  83. AgoraRTCManagerHandler handler = new AgoraRTCManagerHandler(this);
  84. RtcEngineContext context = new RtcEngineContext(_appID, 0,
  85. CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION,
  86. AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
  87. RtcEngine.Initialize(context);
  88. RtcEngine.InitEventHandler(handler);
  89. }
  90. public void JoinChannel()
  91. {
  92. Debug.Log(" JoinChannel " + _channelName);
  93. RtcEngine.EnableAudio();
  94. RtcEngine.EnableVideo();
  95. VideoEncoderConfiguration config = new VideoEncoderConfiguration();
  96. config.dimensions = new VideoDimensions(1280, 720);
  97. config.frameRate = 15;
  98. config.bitrate = 0;
  99. RtcEngine.SetVideoEncoderConfiguration(config);
  100. // RtcEngine.SetAudioProfile(0, AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_GAME_STREAMING);
  101. RtcEngine.SetAudioProfile(AUDIO_PROFILE_TYPE.AUDIO_PROFILE_DEFAULT);
  102. RtcEngine.SetAudioScenario(AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_GAME_STREAMING);
  103. RtcEngine.SetChannelProfile(CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION);
  104. RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
  105. RtcEngine.JoinChannel(_token, _channelName, "", uid);
  106. if (!isSwitchCamera&&DeviceType.type != "Rhinox")
  107. {
  108. RtcEngine.SwitchCamera();
  109. isSwitchCamera = !isSwitchCamera;
  110. }
  111. StartCoroutine(InitVideoAndAduio(1f));
  112. }
  113. public void LeaveChannel()
  114. {
  115. Debug.Log("LeaveChannel ");
  116. int msg = RtcEngine.LeaveChannel();
  117. switch (msg)
  118. {
  119. case 0:
  120. Debug.Log( "成功退出频道: " + _channelName);
  121. break;
  122. default:
  123. Debug.Log("退出频道失败: " + msg);
  124. break;
  125. }
  126. }
  127. public void ClearDatas()
  128. {
  129. myPeer = null;
  130. dicPeeridAndUid.Clear();
  131. dicPeeridAndUid = new Dictionary<string, uint>();
  132. listCustomPeer.Clear();
  133. listCustomPeer = new List<AgoraCustomPeer>();
  134. }
  135. private IEnumerator InitVideoAndAduio(float times)
  136. {
  137. yield return new WaitForSeconds(times);
  138. MuteLocalVideoStream(CustomInfo.isSendVideo);
  139. MuteLocalAudioStream(CustomInfo.isSendAudio);
  140. MyPeer.isAudio = true;
  141. MyPeer.isVideo = true;
  142. }
  143. public void AddDicPeerData(string peerid, uint uid)
  144. {
  145. if (dicPeeridAndUid.ContainsKey(peerid))
  146. return;
  147. dicPeeridAndUid.Add(peerid, uid);
  148. AgoraCustomPeer peer = new AgoraCustomPeer();
  149. peer.AgoraInit(peerid);
  150. listCustomPeer.Add(peer);
  151. if (peerid == PeerId)
  152. MyPeer = peer;
  153. }
  154. public void RemDicPeerData(string peerid)
  155. {
  156. Debug.Log(" RemAtPeeridUid " + peerid + " " + uid);
  157. dicPeeridAndUid.Remove(peerid);
  158. for (int i = 0; i < listCustomPeer.Count; i++)
  159. {
  160. if (listCustomPeer[i].peerId == peerid)
  161. listCustomPeer.Remove(listCustomPeer[i]);
  162. }
  163. }
  164. public void SetCustomPeerName(string peerid, string name)
  165. {
  166. Debug.Log("SetListCustomPeer " + peerid + " " + name);
  167. for (int i = 0; i < listCustomPeer.Count; i++)
  168. {
  169. if (peerid == listCustomPeer[i].peerId)
  170. {
  171. listCustomPeer[i].SetName(name);
  172. break;
  173. }
  174. }
  175. }
  176. public AgoraCustomPeer GetCustomPeer(string peerid)
  177. {
  178. Debug.Log("GetListCustomPeer " + peerid);
  179. for (int i = 0; i < listCustomPeer.Count; i++)
  180. {
  181. if (listCustomPeer[i].peerId == peerid)
  182. return listCustomPeer[i];
  183. }
  184. return null;
  185. }
  186. public void AgoarRawImageVideoView(string peerId, RawImage rawImage)
  187. {
  188. try
  189. {
  190. if (peerId == CommonMethod.MyPeer.PeerId)
  191. {
  192. rawImage.gameObject.SetActive(true);
  193. rawImage.rectTransform.localEulerAngles += new Vector3(0, 180, 180);
  194. MakeVideoView(0, rawImage);
  195. }
  196. else if (dicPeeridAndUid.ContainsKey(peerId))
  197. {
  198. Debug.Log(" AddListShowView " + peerId);
  199. // list_ShowView.Add(peerId, rawImage);
  200. rawImage.gameObject.SetActive(true);
  201. rawImage.rectTransform.localEulerAngles = new Vector3(0, 180, 180);
  202. MakeVideoView(dicPeeridAndUid[peerId], rawImage, this._channelName);
  203. }
  204. }
  205. catch (System.Exception e)
  206. {
  207. HttpsSendLog.Instance.SendLog("Agora", e.ToString());
  208. }
  209. }
  210. public void MuteLocalAudioStream(bool isAudio)
  211. {
  212. int msg = RtcEngine.MuteLocalAudioStream(!isAudio);
  213. // int msg = RtcEngine.EnableLocalAudio(isAudio);
  214. switch (msg)
  215. {
  216. case 0:
  217. Debug.Log(isAudio ? "打开本地音频成功" : "关闭本地音频成功 ");
  218. MyPeer.isOpenAduio = !isAudio;
  219. break;
  220. default:
  221. Debug.LogError("开关本地音频失败: " + msg);
  222. break;
  223. }
  224. }
  225. public void MuteRemoteAudioStream(string peerid, bool isAudio)
  226. {
  227. Debug.Log(peerid);
  228. if (!dicPeeridAndUid.ContainsKey(peerid))
  229. return;
  230. int msg = RtcEngine.MuteRemoteAudioStream(dicPeeridAndUid[peerid], !isAudio);
  231. switch (msg)
  232. {
  233. case 0:
  234. Debug.Log(isAudio ? "订阅远端音频成功" : "取订远端音频成功 ");
  235. break;
  236. default:
  237. Debug.LogError("开关本地音频失败: " + msg);
  238. break;
  239. }
  240. }
  241. public void MuteLocalVideoStream(bool isVideo)
  242. {
  243. int msg = RtcEngine.MuteLocalVideoStream(!isVideo);
  244. //RtcEngine.EnableVideo();
  245. //int msg = RtcEngine.EnableLocalVideo(isVideo);
  246. switch (msg)
  247. {
  248. case 0:
  249. Debug.Log(isVideo ? "打开本地视频成功 " : "关闭本地视频成功 ");
  250. // myPeer.isCloseVideo = !isVideo;
  251. MyPeer.isOpenVideo = !isVideo;
  252. break;
  253. default:
  254. Debug.LogError("开关本地视频失败: " + msg);
  255. break;
  256. }
  257. }
  258. public void MuteRemoteVideoStream(string peerid, bool isVideo)
  259. {
  260. // Debug.Log(peerid);
  261. if (!dicPeeridAndUid.ContainsKey(peerid))
  262. return;
  263. int msg = RtcEngine.MuteRemoteVideoStream(dicPeeridAndUid[peerid], !isVideo);
  264. switch (msg)
  265. {
  266. case 0:
  267. Debug.Log(isVideo ? "订阅远端视频成功" : "取订远端视频成功 ");
  268. break;
  269. default:
  270. Debug.LogError("开关本地音频失败: " + msg);
  271. break;
  272. }
  273. }
  274. public void RemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
  275. reason)
  276. {
  277. Debug.Log(uid + " " + state + " " + reason);
  278. Debug.Log("RemoteVideoStateChanged " + uid);
  279. if (!dicPeeridAndUid.ContainsValue(uid))
  280. return;
  281. for (int i = 0; i < listCustomPeer.Count; i++)
  282. {
  283. if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
  284. {
  285. switch (state)
  286. {
  287. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STOPPED:
  288. // listCustomPeer[i].isVideo = false;
  289. break;
  290. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STARTING:
  291. listCustomPeer[i].isVideo = true;
  292. break;
  293. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_DECODING:
  294. listCustomPeer[i].isOpenVideo = false;
  295. break;
  296. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FROZEN:
  297. break;
  298. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FAILED:
  299. // listCustomPeer[i].isVideo = false;
  300. break;
  301. default:
  302. break;
  303. }
  304. switch (reason)
  305. {
  306. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_INTERNAL:
  307. break;
  308. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION://网络阻塞。
  309. // listCustomPeer[i].isVideo = false;
  310. break;
  311. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY:// 网络恢复正常。
  312. // listCustomPeer[i].isVideo = true;
  313. break;
  314. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED://本地用户停止接收远端视频流或本地用户禁用视频模块
  315. listCustomPeer[i].isOpenVideo = true;
  316. break;
  317. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED://本地用户恢复接收远端视频流或本地用户启动视频模块
  318. listCustomPeer[i].isOpenVideo = false;
  319. break;
  320. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED://远端用户停止发送视频流或远端用户禁用视频模块。
  321. listCustomPeer[i].isVideo = false;
  322. // CloseAgoraMainImage(listCustomPeer[i].peerId, false);
  323. break;
  324. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED://远端用户恢复发送视频流或远端用户启用视频模块。
  325. listCustomPeer[i].isVideo = true;
  326. // CloseAgoraMainImage(listCustomPeer[i].peerId, true);
  327. break;
  328. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE: //远端用户离开频道。
  329. listCustomPeer[i].isVideo = false;
  330. break;
  331. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK:
  332. break;
  333. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY:
  334. break;
  335. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_VIDEO_STREAM_TYPE_CHANGE_TO_LOW:
  336. break;
  337. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_VIDEO_STREAM_TYPE_CHANGE_TO_HIGH:
  338. break;
  339. default:
  340. break;
  341. }
  342. break;
  343. }
  344. }
  345. }
  346. public void RemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
  347. {
  348. Debug.Log(uid + " " + state + " " + reason);
  349. // Debug.Log("RemoteAudioStateChanged " + uid);
  350. if (!dicPeeridAndUid.ContainsValue(uid))
  351. return;
  352. // Debug.Log("RemoteAudioStateChanged " + 1);
  353. for (int i = 0; i < listCustomPeer.Count; i++)
  354. {
  355. Debug.Log(listCustomPeer[i].peerId);
  356. if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
  357. {
  358. // Debug.Log("RemoteAudioStateChanged " + 2);
  359. switch (state)
  360. {
  361. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STOPPED:
  362. // listCustomPeer[i].isAudio = false;
  363. break;
  364. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STARTING:
  365. listCustomPeer[i].isAudio = true;
  366. break;
  367. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_DECODING:
  368. listCustomPeer[i].isOpenAduio = false;
  369. break;
  370. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FROZEN:
  371. break;
  372. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FAILED:
  373. // listCustomPeer[i].isAudio = false;
  374. break;
  375. default:
  376. break;
  377. }
  378. switch (reason)
  379. {
  380. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_INTERNAL:
  381. break;
  382. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_CONGESTION:
  383. // listCustomPeer[i].isAudio = false;
  384. break;
  385. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_RECOVERY:
  386. // listCustomPeer[i].isAudio = true;
  387. break;
  388. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_MUTED:
  389. listCustomPeer[i].isOpenAduio = true;
  390. break;
  391. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_UNMUTED:
  392. listCustomPeer[i].isOpenAduio = false;
  393. break;
  394. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_MUTED:
  395. listCustomPeer[i].isAudio = false;
  396. break;
  397. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_UNMUTED:
  398. listCustomPeer[i].isAudio = true;
  399. break;
  400. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_OFFLINE:
  401. listCustomPeer[i].isAudio = false;
  402. break;
  403. default:
  404. break;
  405. }
  406. break;
  407. }
  408. }
  409. }
  410. private void OnDestroy()
  411. {
  412. Debug.Log("OnDestroy");
  413. if (RtcEngine == null) return;
  414. RtcEngine.InitEventHandler(null);
  415. RtcEngine.LeaveChannel();
  416. RtcEngine.Dispose();
  417. }
  418. internal static void MakeVideoView(uint uid, RawImage rawImage, string channelId = "")
  419. {
  420. Debug.Log("MakeVideoView " + uid);
  421. //var go = GameObject.Find(uid.ToString());
  422. //if (!ReferenceEquals(go, null))
  423. //{
  424. // return; // reuse
  425. //}
  426. // create a GameObject and assign to this new user
  427. var videoSurface = MakeImageSurface(rawImage);
  428. // var videoSurface = MakePlaneSurface(uid.ToString());
  429. if (ReferenceEquals(videoSurface, null)) return;
  430. // configure videoSurface
  431. if (uid == 0)
  432. {
  433. videoSurface.SetForUser(uid, channelId);
  434. }
  435. else
  436. {
  437. videoSurface.SetForUser(uid, channelId, VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE);
  438. }
  439. //videoSurface.OnTextureSizeModify += (int width, int height) =>
  440. //{
  441. // float scale = (float)height / (float)width;
  442. // videoSurface.transform.localScale = new Vector3(-5, 5 * scale, 1);
  443. // Debug.Log("OnTextureSizeModify: " + width + " " + height);
  444. //};
  445. videoSurface.SetEnable(true);
  446. }
  447. internal static void OnUserJoined(uint uid)
  448. {
  449. // _videoSample.Log.UpdateLog(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
  450. // Debug.Log(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed))
  451. Agora.Rtc.UserInfo userInfo = new Agora.Rtc.UserInfo();
  452. AgoraRTCManager.Instance.RtcEngine.GetUserInfoByUid(uid, ref userInfo);
  453. }
  454. internal static void OnRemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
  455. reason)
  456. {
  457. AgoraRTCManager.Instance.RemoteVideoStateChanged(uid, state, reason);
  458. }
  459. internal static void OnRemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
  460. {
  461. AgoraRTCManager.Instance.RemoteAudioStateChanged(uid, state, reason);
  462. }
  463. #region -- Video Render UI Logic ---
  464. // VIDEO TYPE 1: 3D Object
  465. private static VideoSurface MakePlaneSurface(string goName)
  466. {
  467. var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
  468. //for (int i = 0; i < list_UserInfo.Count; i++)
  469. //{
  470. // if (list_UserInfo[i].uid.ToString() == goName)
  471. // {
  472. // string userAccount = list_UserInfo[i].userAccount;
  473. // if (AgoraVideoAudioManager.Instance.list_ShowView.ContainsKey(list_UserInfo[i].userAccount))
  474. // {
  475. // go = AgoraVideoAudioManager.Instance.list_ShowView[list_UserInfo[i].userAccount].gameObject;
  476. // }
  477. // else
  478. // Debug.LogError(" Agora ShowView is NULL ");
  479. // }
  480. //}
  481. if (go == null)
  482. {
  483. go = GameObject.CreatePrimitive(PrimitiveType.Plane);
  484. return null;
  485. }
  486. go.name = goName;
  487. // set up transform
  488. go.transform.Rotate(-90.0f, 0.0f, 0.0f);
  489. var yPos = Random.Range(3.0f, 5.0f);
  490. var xPos = Random.Range(-2.0f, 2.0f);
  491. go.transform.position = Vector3.zero;
  492. go.transform.localScale = new Vector3(0.25f, 0.5f, 0.5f);
  493. // configure videoSurface
  494. var videoSurface = go.AddComponent<VideoSurface>();
  495. return videoSurface;
  496. }
  497. // Video TYPE 2: RawImage
  498. private static VideoSurface MakeImageSurface(RawImage rawImage)
  499. {
  500. rawImage.gameObject.AddComponent<UIElementDrag>();
  501. var videoSurface = rawImage.gameObject.AddComponent<VideoSurface>();
  502. return videoSurface;
  503. }
  504. #endregion
  505. }
  506. #region -- Agora Event ---
  507. public class AgoraRTCManagerHandler : IRtcEngineEventHandler
  508. {
  509. private readonly AgoraRTCManager _videoSample;
  510. internal AgoraRTCManagerHandler(AgoraRTCManager videoSample)
  511. {
  512. _videoSample = videoSample;
  513. }
  514. public override void OnError(int err, string msg)
  515. {
  516. // _videoSample.Log.UpdateLog(string.Format("OnError err: {0}, msg: {1}", err, msg));
  517. }
  518. public override void OnJoinChannelSuccess(RtcConnection connection, int elapsed)
  519. {
  520. int build = 0;
  521. Debug.Log("Agora: OnJoinChannelSuccess ");
  522. _videoSample.RtcEngine.GetVersion(ref build);
  523. }
  524. public override void OnUserJoined(RtcConnection connection, uint uid, int elapsed)
  525. {
  526. Debug.Log(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
  527. // _videoSample.Log.UpdateLog(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
  528. AgoraRTCManager.OnUserJoined(uid);
  529. // AgoraVideoAudioManager.MakeVideoView(uid, _videoSample.GetChannelName());
  530. }
  531. public override void OnRemoteVideoStateChanged(RtcConnection connection, uint remoteUid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON reason, int elapsed)
  532. {
  533. AgoraRTCManager.OnRemoteVideoStateChanged(remoteUid, state, reason);
  534. }
  535. public override void OnRemoteAudioStateChanged(RtcConnection connection, uint remoteUid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed)
  536. {
  537. AgoraRTCManager.OnRemoteAudioStateChanged(remoteUid, state, reason);
  538. }
  539. public override void OnLocalVideoStateChanged(RtcConnection connection, LOCAL_VIDEO_STREAM_STATE state, LOCAL_VIDEO_STREAM_ERROR errorCode)
  540. {
  541. }
  542. public override void OnLocalAudioStateChanged(RtcConnection connection, LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error)
  543. {
  544. }
  545. }
  546. #endregion