123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- using Agora.Rtc;
- using Agora.Util;
- using SC.XR.Unity;
- using ShadowStudio.Model;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Serialization;
- using UnityEngine.UI;
- using XRTool.Util;
- using static Reporter;
- public class AgoraRTCManager : SingletonMono<AgoraRTCManager>
- {
- [FormerlySerializedAs("appIdInput")]
- [SerializeField]
- private AppIdInput _appIdInput;
- [Header("_____________Basic Configuration_____________")]
- [FormerlySerializedAs("APP_ID")]
- [SerializeField]
- private string _appID = "";
- [FormerlySerializedAs("TOKEN")]
- [SerializeField]
- private string _token = "";
- [FormerlySerializedAs("CHANNEL_NAME")]
- [SerializeField]
- private string _channelName = "";
- private uint uid;
- private string peerid;
- internal IRtcEngine RtcEngine = null;
- private AgoraCustomPeer myPeer;
- private Dictionary<string, uint> dicPeeridAndUid;
- private List<AgoraCustomPeer> listCustomPeer;
- public bool isSwitchCamera;
- public uint Uid
- {
- get { return uid; }
- set { uid = value; }
- }
- public AgoraCustomPeer MyPeer
- {
- get { return myPeer; }
- set { if(value!=null) myPeer = value; }
- }
- public string ChannelName
- {
- get { return _channelName; }
- set { if (value != null) _channelName = value; }
- }
- public string PeerId
- {
- get { return peerid; }
- set { if (value != null) peerid = value; }
- }
- private void Start()
- {
- LoadAssetData();
- //if (_appID.Length > 10)
- //{
-
- //}
- InitEngine();
- dicPeeridAndUid = new Dictionary<string, uint>();
- isSwitchCamera = false;
- listCustomPeer = new List<AgoraCustomPeer>();
- }
- private void Update()
- {
- PermissionHelper.RequestMicrophontPermission();
- PermissionHelper.RequestCameraPermission();
- }
-
- //Show data in AgoraBasicProfile
- [ContextMenu("ShowAgoraBasicProfileData")]
- private void LoadAssetData()
- {
- if (_appIdInput == null) return;
- _appID = _appIdInput.appID;
- _token = _appIdInput.token;
- _channelName = _appIdInput.channelName;
- }
- private void InitEngine()
- {
- RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
- AgoraRTCManagerHandler handler = new AgoraRTCManagerHandler(this);
- RtcEngineContext context = new RtcEngineContext(_appID, 0,
- CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION,
- AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
- RtcEngine.Initialize(context);
- RtcEngine.InitEventHandler(handler);
- RtcEngine.SetDefaultAudioRouteToSpeakerphone(true);
- }
- public void JoinChannel()
- {
- Debug.Log(" JoinChannel " + _channelName);
- RtcEngine.EnableAudio();
- if(DeviceType.type!="LeiNiao")
- {
- RtcEngine.EnableVideo();
- }
- // RtcEngine.DisableAudio();
- // RtcEngine.DisableVideo();
- if (DeviceType.type != "LeiNiao")
- {
- VideoEncoderConfiguration config = new VideoEncoderConfiguration();
- config.dimensions = new VideoDimensions(1280, 720);
- config.frameRate = 15;
- config.bitrate = 0;
- // config.orientationMode = ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
- RtcEngine.SetVideoEncoderConfiguration(config);
- }
- RtcEngine.SetChannelProfile(CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION);
- RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
- // _channelName = roomid;
- if (DeviceType.type != "LeiNiao")
- {
- RtcEngine.SetExternalVideoSource(true, true, EXTERNAL_VIDEO_SOURCE_TYPE.VIDEO_FRAME, new SenderOptions());
- }
- RtcEngine.JoinChannel(_token, _channelName, "", uid);
- if (DeviceType.type != "LeiNiao")
- {
- if (!isSwitchCamera && (DeviceType.type != "Rhinox" || DeviceType.type != "Phone"))
- {
- RtcEngine.SwitchCamera();
- isSwitchCamera = !isSwitchCamera;
- }
- }
- StartCoroutine(InitVideoAndAduio(1f));
- if (!RTCINIT)
- {
- RTCINIT = true;
- if (DeviceType.type != "LeiNiao")
- {
- StartCoroutine(RenderTexturesScreenCapture());
- }
- }
- }
- static bool RTCINIT;
- Texture2D screenShot;
- IEnumerator RenderTexturesScreenCapture()
- {
- Debug.Log("RenderTexturesScreenCapture发送图片1");
- yield return new WaitForEndOfFrame();
- if (screenShot == null)
- {
- screenShot = new Texture2D(1280, 720, TextureFormat.RGBA32, false);
- StartCoroutine(GetRenederFPS());
- }
- while (true)
- {
- // if (isSendVideo)
- // continue;
- // img.texture = RemoteRtc.Instance.cam.activeTexture;
- // RenderTexture.active = ca.activeTexture;
- // screenShot.ReadPixels(new Rect(0, 0, ca.activeTexture.width, ca.activeTexture.height), 0, 0);
- // screenShot.Apply();
- //Camera.main.targetTexture = null;
- // RenderTexture.active = null;
- yield return new WaitForSeconds(0.05f);
- if (bts != null)
- {
- // screenShot = HorizontalFlipTexture(screenShot2);
- var timetick = System.DateTime.Now.Ticks / 10000;
- ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
- externalVideoFrame.type = VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
- externalVideoFrame.format = VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_RGBA;
- externalVideoFrame.buffer = bts;// screenShot.GetRawTextureData();
- externalVideoFrame.stride = (int)screenShot.width;
- externalVideoFrame.height = (int)screenShot.height;
- externalVideoFrame.rotation = 180;
- externalVideoFrame.cropLeft = 1;
- externalVideoFrame.cropRight = 1;
- externalVideoFrame.timestamp = timetick;
- RtcEngine.PushVideoFrame(externalVideoFrame);
- // Debug.Log("发送中。。。。。");
- }
- }
- }
- public Camera cam2;
- byte[] bts;
- IEnumerator GetRenederFPS()
- {
- while (true)
- {
- var req = AsyncGPUReadback.Request(cam2.activeTexture);
- yield return new WaitUntil(() => req.done);
- if (!req.hasError)
- {
- if (bts == null)
- {
- bts = new byte[req.layerDataSize];
- }
- req.GetData<byte>().CopyTo(bts);
- // screenShot.LoadRawTextureData(bts);
- // screenShot.Apply();
- // tex.SetPixels32(req.GetData<Color32>().ToArray());
- // img.texture = screenShot;
- }
- else
- {
- Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
- }
- }
- }
- public void LeaveChannel()
- {
- Debug.Log("LeaveChannel ");
- int msg = RtcEngine.LeaveChannel();
- switch (msg)
- {
- case 0:
- Debug.Log( "鎴愬姛閫€鍑洪�閬擄細 " + _channelName);
- break;
- default:
- Debug.Log("閫€鍑洪�閬撳け璐ワ細 " + msg);
- break;
- }
-
- }
- public void ClearDatas()
- {
- myPeer = null;
- dicPeeridAndUid.Clear();
- dicPeeridAndUid = new Dictionary<string, uint>();
- listCustomPeer.Clear();
- listCustomPeer = new List<AgoraCustomPeer>();
- }
- private IEnumerator InitVideoAndAduio(float times)
- {
- yield return new WaitForSeconds(times);
- MuteLocalVideoStream(CustomInfo.isSendVideo);
- MuteLocalAudioStream(CustomInfo.isSendAudio);
- MyPeer.isAudio = true;
- MyPeer.isVideo = true;
- }
- public void AddDicPeerData(string peerid, uint uid)
- {
- if (dicPeeridAndUid.ContainsKey(peerid))
- return;
- dicPeeridAndUid.Add(peerid, uid);
- AgoraCustomPeer peer = new AgoraCustomPeer();
- peer.AgoraInit(peerid);
- listCustomPeer.Add(peer);
- if (peerid == PeerId)
- MyPeer = peer;
- }
- public void RemDicPeerData(string peerid)
- {
- Debug.Log(" RemAtPeeridUid " + peerid + " " + uid);
- dicPeeridAndUid.Remove(peerid);
- for (int i = 0; i < listCustomPeer.Count; i++)
- {
- if (listCustomPeer[i].peerId == peerid)
- listCustomPeer.Remove(listCustomPeer[i]);
- }
- }
- public void SetCustomPeerName(string peerid, string name)
- {
- Debug.Log("SetListCustomPeer " + peerid + " " + name);
- for (int i = 0; i < listCustomPeer.Count; i++)
- {
- if (peerid == listCustomPeer[i].peerId)
- {
- listCustomPeer[i].SetName(name);
- break;
- }
- }
- }
- public AgoraCustomPeer GetCustomPeer(string peerid)
- {
- Debug.Log("GetListCustomPeer " + peerid);
- for (int i = 0; i < listCustomPeer.Count; i++)
- {
- if (listCustomPeer[i].peerId == peerid)
- return listCustomPeer[i];
- }
- return null;
- }
- public void AgoarRawImageVideoView(string peerId, RawImage rawImage)
- {
- Debug.Log(" AgoarRawImageVideoView " + peerId);
- try
- {
- if (peerId == CommonMethod.MyPeer.PeerId)
- {
- rawImage.gameObject.SetActive(true);
- rawImage.rectTransform.localEulerAngles = new Vector3(0, 180, 180);
- MakeVideoView(0, rawImage);
- }
- else if (dicPeeridAndUid.ContainsKey(peerId))
- {
- // list_ShowView.Add(peerId, rawImage);
- rawImage.gameObject.SetActive(true);
- rawImage.rectTransform.localEulerAngles = new Vector3(0, 0, 180);
- MakeVideoView(dicPeeridAndUid[peerId], rawImage, this._channelName);
- }
- }
- catch (System.Exception e)
- {
- HttpsSendLog.Instance.SendLog("Agora", e.ToString());
- }
-
- }
- public void MuteLocalAudioStream(bool isAudio)
- {
- int msg = RtcEngine.MuteLocalAudioStream(!isAudio);
- // int msg = RtcEngine.EnableLocalAudio(isAudio);
- switch (msg)
- {
- case 0:
- Debug.Log(isAudio ? "鎵撳紑鏈�湴闊抽�鎴愬姛" : "鍏抽棴鏈�湴闊抽�鎴愬姛 ");
- MyPeer.isOpenAduio = !isAudio;
- break;
- default:
- Debug.LogError("寮€鍏虫湰鍦伴煶棰戝け璐ワ細 " + msg);
- break;
- }
- }
- public void MuteRemoteAudioStream(string peerid, bool isAudio)
- {
- Debug.Log(peerid);
- if (!dicPeeridAndUid.ContainsKey(peerid))
- return;
- int msg = RtcEngine.MuteRemoteAudioStream(dicPeeridAndUid[peerid], !isAudio);
- switch (msg)
- {
- case 0:
- Debug.Log(isAudio ? "璁㈤槄杩滅�闊抽�鎴愬姛" : "鍙栬�杩滅�闊抽�鎴愬姛 ");
- break;
- default:
- Debug.LogError("寮€鍏虫湰鍦伴煶棰戝け璐ワ細 " + msg);
- break;
- }
- }
- public void MuteLocalVideoStream(bool isVideo)
- {
- if(isVideo)
- {
- XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
- }
- else
- {
- XRRGBCamera.Instance.stopCamera();
- }
- int msg = RtcEngine.MuteLocalVideoStream(!isVideo);
- //RtcEngine.EnableVideo();
- //int msg = RtcEngine.EnableLocalVideo(isVideo);
- switch (msg)
- {
- case 0:
- Debug.Log(isVideo ? "鎵撳紑鏈�湴瑙嗛�鎴愬姛 " : "鍏抽棴鏈�湴瑙嗛�鎴愬姛 ");
- // myPeer.isCloseVideo = !isVideo;
- MyPeer.isOpenVideo = !isVideo;
- break;
- default:
- Debug.LogError("寮€鍏虫湰鍦拌�棰戝け璐ワ細 " + msg);
- break;
- }
- }
- public void MuteRemoteVideoStream(string peerid, bool isVideo)
- {
- // Debug.Log(peerid);
- if (!dicPeeridAndUid.ContainsKey(peerid))
- return;
- int msg = RtcEngine.MuteRemoteVideoStream(dicPeeridAndUid[peerid], !isVideo);
- switch (msg)
- {
- case 0:
- Debug.Log(isVideo ? "璁㈤槄杩滅�瑙嗛�鎴愬姛" : "鍙栬�杩滅�瑙嗛�鎴愬姛 ");
- break;
- default:
- Debug.LogError("寮€鍏虫湰鍦伴煶棰戝け璐ワ細 " + msg);
- break;
- }
- }
- public void RemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
- reason)
- {
- Debug.Log(uid + " " + state + " " + reason);
- Debug.Log("RemoteVideoStateChanged " + uid);
- if (!dicPeeridAndUid.ContainsValue(uid))
- return;
- for (int i = 0; i < listCustomPeer.Count; i++)
- {
- if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
- {
- switch (state)
- {
- case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STOPPED:
- // listCustomPeer[i].isVideo = false;
- break;
- case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STARTING:
- listCustomPeer[i].isVideo = true;
- break;
- case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_DECODING:
- listCustomPeer[i].isOpenVideo = false;
- break;
- case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FROZEN:
- break;
- case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FAILED:
- // listCustomPeer[i].isVideo = false;
- break;
- default:
- break;
- }
- switch (reason)
- {
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_INTERNAL:
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION://缃戠粶闃诲�銆?
- // listCustomPeer[i].isVideo = false;
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY:// 缃戠粶鎭㈠�姝e父銆?
- // listCustomPeer[i].isVideo = true;
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED://鏈�湴鐢ㄦ埛鍋滄�鎺ユ敹杩滅�瑙嗛�娴佹垨鏈�湴鐢ㄦ埛绂佺敤瑙嗛�妯″潡
- listCustomPeer[i].isOpenVideo = true;
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED://鏈�湴鐢ㄦ埛鎭㈠�鎺ユ敹杩滅�瑙嗛�娴佹垨鏈�湴鐢ㄦ埛鍚�姩瑙嗛�妯″潡
- listCustomPeer[i].isOpenVideo = false;
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED://杩滅�鐢ㄦ埛鍋滄�鍙戦€佽�棰戞祦鎴栬繙绔�敤鎴风�鐢ㄨ�棰戞ā鍧椼€?
- listCustomPeer[i].isVideo = false;
- // CloseAgoraMainImage(listCustomPeer[i].peerId, false);
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED://杩滅�鐢ㄦ埛鎭㈠�鍙戦€佽�棰戞祦鎴栬繙绔�敤鎴峰惎鐢ㄨ�棰戞ā鍧椼€?
- listCustomPeer[i].isVideo = true;
- // CloseAgoraMainImage(listCustomPeer[i].peerId, true);
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE: //杩滅�鐢ㄦ埛绂诲紑棰戦亾銆?
- listCustomPeer[i].isVideo = false;
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK:
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY:
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_VIDEO_STREAM_TYPE_CHANGE_TO_LOW:
- break;
- case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_VIDEO_STREAM_TYPE_CHANGE_TO_HIGH:
- break;
- default:
- break;
- }
- break;
- }
- }
- }
- public void RemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
- {
- Debug.Log(uid + " " + state + " " + reason);
- // Debug.Log("RemoteAudioStateChanged " + uid);
- if (!dicPeeridAndUid.ContainsValue(uid))
- return;
- // Debug.Log("RemoteAudioStateChanged " + 1);
- for (int i = 0; i < listCustomPeer.Count; i++)
- {
- Debug.Log(listCustomPeer[i].peerId);
- if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
- {
- // Debug.Log("RemoteAudioStateChanged " + 2);
- switch (state)
- {
- case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STOPPED:
- // listCustomPeer[i].isAudio = false;
- break;
- case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STARTING:
- listCustomPeer[i].isAudio = true;
- break;
- case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_DECODING:
- listCustomPeer[i].isOpenAduio = false;
- break;
- case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FROZEN:
- break;
- case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FAILED:
- // listCustomPeer[i].isAudio = false;
- break;
- default:
- break;
- }
- switch (reason)
- {
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_INTERNAL:
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_CONGESTION:
- // listCustomPeer[i].isAudio = false;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_RECOVERY:
- // listCustomPeer[i].isAudio = true;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_MUTED:
- listCustomPeer[i].isOpenAduio = true;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_UNMUTED:
- listCustomPeer[i].isOpenAduio = false;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_MUTED:
- listCustomPeer[i].isAudio = false;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_UNMUTED:
- listCustomPeer[i].isAudio = true;
- break;
- case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_OFFLINE:
- listCustomPeer[i].isAudio = false;
- break;
- default:
- break;
- }
- break;
- }
- }
- }
- private void OnDestroy()
- {
- Debug.Log("OnDestroy");
- if (RtcEngine == null) return;
- RtcEngine.InitEventHandler(null);
- RtcEngine.LeaveChannel();
- RtcEngine.Dispose();
- }
- internal static void MakeVideoView(uint uid, RawImage rawImage, string channelId = "")
- {
- Debug.Log("MakeVideoView " + uid);
- //var go = GameObject.Find(uid.ToString());
- //if (!ReferenceEquals(go, null))
- //{
- // return; // reuse
- //}
- // create a GameObject and assign to this new user
- // var videoSurface = MakePlaneSurface(uid.ToString());
- // configure videoSurface
- if (uid == 0)
- {
- rawImage.transform.localEulerAngles = Vector3.zero;
- //videoSurface.SetForUser(uid, channelId);
- rawImage.texture = AgoraRTCManager.Instance.cam2.activeTexture;
- }
- else
- {
- rawImage.transform.localEulerAngles = new Vector3(-180,180,0);
- var videoSurface = MakeImageSurface(rawImage);
- if (ReferenceEquals(videoSurface, null)) return;
- videoSurface.SetForUser(uid, channelId, VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE);
- videoSurface.SetEnable(true);
- }
- //videoSurface.OnTextureSizeModify += (int width, int height) =>
- //{
- // float scale = (float)height / (float)width;
- // videoSurface.transform.localScale = new Vector3(-5, 5 * scale, 1);
- // Debug.Log("OnTextureSizeModify: " + width + " " + height);
- //};
- }
- internal static void OnUserJoined(uint uid)
- {
- // _videoSample.Log.UpdateLog(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
- // Debug.Log(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed))
- Agora.Rtc.UserInfo userInfo = new Agora.Rtc.UserInfo();
- AgoraRTCManager.Instance.RtcEngine.GetUserInfoByUid(uid, ref userInfo);
- }
- internal static void OnRemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
- reason)
- {
- AgoraRTCManager.Instance.RemoteVideoStateChanged(uid, state, reason);
- }
- internal static void OnRemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
- {
- AgoraRTCManager.Instance.RemoteAudioStateChanged(uid, state, reason);
- }
- #region -- Video Render UI Logic ---
- // VIDEO TYPE 1: 3D Object
- private static VideoSurface MakePlaneSurface(string goName)
- {
- var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
- //for (int i = 0; i < list_UserInfo.Count; i++)
- //{
- // if (list_UserInfo[i].uid.ToString() == goName)
- // {
- // string userAccount = list_UserInfo[i].userAccount;
- // if (AgoraVideoAudioManager.Instance.list_ShowView.ContainsKey(list_UserInfo[i].userAccount))
- // {
- // go = AgoraVideoAudioManager.Instance.list_ShowView[list_UserInfo[i].userAccount].gameObject;
- // }
- // else
- // Debug.LogError(" Agora ShowView is NULL ");
- // }
- //}
- if (go == null)
- {
- go = GameObject.CreatePrimitive(PrimitiveType.Plane);
- return null;
- }
- go.name = goName;
- // set up transform
- go.transform.Rotate(-90.0f, 0.0f, 0.0f);
- var yPos = Random.Range(3.0f, 5.0f);
- var xPos = Random.Range(-2.0f, 2.0f);
- go.transform.position = Vector3.zero;
- go.transform.localScale = new Vector3(0.25f, 0.5f, 0.5f);
- // configure videoSurface
- var videoSurface = go.AddComponent<VideoSurface>();
- return videoSurface;
- }
- // Video TYPE 2: RawImage
- private static VideoSurface MakeImageSurface(RawImage rawImage)
- {
- rawImage.gameObject.AddComponent<UIElementDrag>();
- var videoSurface = rawImage.gameObject.AddComponent<VideoSurface>();
- return videoSurface;
- }
- #endregion
- }
- #region -- Agora Event ---
- public class AgoraRTCManagerHandler : IRtcEngineEventHandler
- {
- private readonly AgoraRTCManager _videoSample;
- internal AgoraRTCManagerHandler(AgoraRTCManager videoSample)
- {
- _videoSample = videoSample;
- }
- public override void OnError(int err, string msg)
- {
- // _videoSample.Log.UpdateLog(string.Format("OnError err: {0}, msg: {1}", err, msg));
- }
- public override void OnJoinChannelSuccess(RtcConnection connection, int elapsed)
- {
- int build = 0;
- Debug.Log("Agora: OnJoinChannelSuccess ");
- _videoSample.RtcEngine.GetVersion(ref build);
- }
- public override void OnUserJoined(RtcConnection connection, uint uid, int elapsed)
- {
- Debug.Log(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
- // _videoSample.Log.UpdateLog(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
- AgoraRTCManager.OnUserJoined(uid);
- // AgoraVideoAudioManager.MakeVideoView(uid, _videoSample.GetChannelName());
- }
- public override void OnRemoteVideoStateChanged(RtcConnection connection, uint remoteUid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON reason, int elapsed)
- {
- AgoraRTCManager.OnRemoteVideoStateChanged(remoteUid, state, reason);
- }
- public override void OnRemoteAudioStateChanged(RtcConnection connection, uint remoteUid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed)
- {
- AgoraRTCManager.OnRemoteAudioStateChanged(remoteUid, state, reason);
- }
- public override void OnLocalVideoStateChanged(RtcConnection connection, LOCAL_VIDEO_STREAM_STATE state, LOCAL_VIDEO_STREAM_ERROR errorCode)
- {
- }
- public override void OnLocalAudioStateChanged(RtcConnection connection, LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error)
- {
- }
- }
- #endregion
|