using LitJson; using rtc; using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using XRTool.Util; public class PeerSamllView : BaseView, IPointerEnterHandler, IPointerExitHandler { public Text tName; public TMP_Text name; public MeshRenderer mViewTexture; public GameObject user; public GameObject add; public GameObject enterBtn; public SysEnterManager sysEenter; public CustomPeer cPeer; public Button addBtn; private InviteUserConfig inviteUserConfig; private float alltime = 30f; private bool istime = false; public Texture texture; public GameObject ChooseKuang; public GameObject AudioEffect; private void Start() { addBtn.onClick.AddListener(ClickAdd); WSHandler.Rtc.OnActiveSpeaker += ActiveSpeaker; } private void OnDestroy() { WSHandler.Rtc.OnActiveSpeaker -= ActiveSpeaker; } SCRtcPeer p; private void ActiveSpeaker(JsonData data) { if (this.gameObject.activeSelf) { if (data["data"]["peerId"] != null) { string peerId = data["data"]["peerId"].ToString(); if (!string.IsNullOrEmpty(peerId)) { p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(peerId); if (p != null) { p.changeVolumn(int.Parse(data["data"]["volume"].ToString())); } if (cPeer != null && peerId == cPeer.peerId) { AudioEffect.SetActive(true); } else { AudioEffect.SetActive(false); } } } } } private void ShowChooseKuang(string id) { if (id == cPeer.peerId) { ChooseKuang.SetActive(true); } else { ChooseKuang.SetActive(false); } } private void Update() { if (istime) { alltime -= Time.deltaTime; if (alltime <= 0) { istime = false; alltime = 30f; if (this.inviteUserConfig != null) { if (InviteDlg.Instance && InviteDlg.Instance.InvitingUnionIdList.Contains(this.inviteUserConfig)) { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, this.inviteUserConfig.NickName + "无应答"); InviteDlg.Instance.InvitingUnionIdList.Remove(this.inviteUserConfig); RoomOtherUser.Instance.UpdateList(); } } } } else { alltime = 30f; } } private void OnEnable() { alltime = 30f; istime = false; AudioEffect.SetActive(false); } private void OnDisable() { alltime = 30f; istime = false; AudioEffect.SetActive(false); } public override void init(int i, BaseConfig c, int vi) { base.init(i, c, vi); mViewTexture.material.mainTexture = texture; if (c is PeerConfig) { Debug.Log("initinitinitinitinitinit"); if (this.inviteUserConfig != null) { this.inviteUserConfig = null; } // user.SetActive(true); add.SetActive(false); enterBtn.SetActive(false); sysEenter.gameObject.SetActive(true); cPeer = (c as PeerConfig).peer; sysEenter.cPeer = cPeer; // tName.text = cPeer.name; name.text = cPeer.name; if (!cPeer.isSn) { if (!string.IsNullOrEmpty(cPeer.avater)) { NetWorkHeaders.Instance.getNetTexture(cPeer.avater, null, (Texture tex) => { mViewTexture.material.mainTexture = tex; }); } else { if (UserInfo.defaulttextIcon != null) { mViewTexture.material.mainTexture = UserInfo.defaulttextIcon; } } } else { NetWorkHeaders.GetUserAvater((aData) => { for (int j = 0; j < aData["data"]["sn"].Count; j++) { NetWorkHeaders.Instance.getNetTexture(aData["data"]["sn"][j].ToString(), null, (Texture tex) => { mViewTexture.material.mainTexture = tex; }); } }); } cPeer.onChangeInfo -= OnChangeInfo; cPeer.onChangeInfo += OnChangeInfo; cPeer.onChangeTexture -= onChangeTexture; cPeer.onChangeTexture += onChangeTexture; cPeer.onChangeName -= onChangeName; cPeer.onChangeName += onChangeName; RoomOtherUser.ShowAction -= ShowChooseKuang; RoomOtherUser.ShowAction += ShowChooseKuang; if (RoomMain.Instance.userId == RoomMain.NOUSER) { RoomMain.Instance.setBigView(cPeer.tex, cPeer.peerId); } alltime = 30f; istime = false; bool isAdd =false; for (int j = 0; j < AgoraVideoAudioManager.Instance.listCustomPeer.Count; j++) { if(AgoraVideoAudioManager.Instance.listCustomPeer[j].peerId == cPeer.peerId) { isAdd = true; } } if(!isAdd) AgoraVideoAudioManager.Instance.listCustomPeer.Add(cPeer); } else if (c is InviteUserConfig) { if (cPeer != null) { cPeer = null; } this.inviteUserConfig = c as InviteUserConfig; // user.SetActive(true); add.SetActive(false); // tName.text = "等待进入..."; name.text = "等待进入..."; sysEenter.gameObject.SetActive(false); if (this.inviteUserConfig != null && !string.IsNullOrEmpty(inviteUserConfig.Avatar)) { NetWorkHeaders.Instance.getNetTexture(inviteUserConfig.Avatar, null, (Texture tex) => { mViewTexture.material.mainTexture = tex; }); } else { if (UserInfo.defaulttextIcon != null) { mViewTexture.material.mainTexture = UserInfo.defaulttextIcon; } } enterBtn.SetActive(false); alltime = 30f; istime = true; } else { user.SetActive(false); // add.SetActive(true); alltime = 30f; istime = false; } } void onChangeTexture() { if(RoomMain.Instance.userId==cPeer.peerId) { RoomMain.Instance.setBigView(cPeer.tex, cPeer.peerId); } } void onChangeName(string cName) { // tName.text = cName; name.text = cName; } public void setBigView() { if (cPeer == null) { return; } RoomMain.Instance.setBigView(cPeer.tex,cPeer.peerId); RoomOtherUser.ShowAction?.Invoke(cPeer.peerId); AgoraVideoAudioManager.Instance.AddListShowView(cPeer.peerId, RoomMain.Instance.agoraRawImage, true); } public void showBigView() { RoomMain.Instance.setBigView(RemoteRtc.Instance.NoUser, RoomMain.NOUSER); PopPeerView.Instance.addBigView(cPeer); } private Timer t; public void OnEnterBtn() { } public void exitBtn() { enterBtn.SetActive(false); } private void ClickAdd() { if (ShowRoom.Instance) { ShowRoom.Instance.window[4].SetActive(true); if (InviteDlg.Instance) { InviteDlg.Instance.ShowHistory(); } } } private void OnChangeInfo(string type, string id) { if (type == "video") { if (cPeer.isVideo) { if (cPeer.isCloseVideo) { RemoteRtc.Instance.closeRev(cPeer.cIdV); } } else { } if (RoomMain.Instance.userId == cPeer.peerId) { Debug.Log("开启大视频"); RoomMain.Instance.setBigView(cPeer.tex, cPeer.peerId); } } else { if (cPeer.isAudio) { if (cPeer.isCloseAudio) { RemoteRtc.Instance.closeRev(cPeer.cIdA); } } else { } } } public void OpenVideo() { //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo) //{ // RemoteRtc.Instance.startRev(cPeer.cIdV); // cPeer.isCloseVideo = false; // // cPeer.setInfo("audio", cPeer.cIdA,true); // // AgoraVideoAudioManager.Instance.EnableLocalVideo(true); //} // cPeer.setInfo("audio", cPeer.cIdA,true); AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true); // RoomMain.Instance.agoraRawImage.gameObject.SetActive(true); } public void CloseVideo() { //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo) //{ // RemoteRtc.Instance.closeRev(cPeer.cIdV); // cPeer.isCloseVideo = true; // // cPeer.setInfo("audio", cPeer.cIdA,true); // //AgoraVideoAudioManager.Instance.EnableLocalVideo(false); //} // cPeer.setInfo("audio", cPeer.cIdA,true); AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false); RoomMain.Instance.agoraRawImage.gameObject.SetActive(false); } public void openMic() { //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && cPeer.isCloseAudio) //{ // RemoteRtc.Instance.startRev(cPeer.cIdA); // cPeer.isCloseAudio = true; // // cPeer.setInfo("audio", cPeer.cIdA,true); // // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true); //} // cPeer.setInfo("audio", cPeer.cIdA,true); AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true); } public void closeMic() { //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio) //{ // RemoteRtc.Instance.closeRev(cPeer.cIdA); // cPeer.isCloseAudio = false; // // cPeer.setInfo("audio", cPeer.cIdA, false); // // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false); //} // cPeer.setInfo("audio", cPeer.cIdA, false); AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false); } public void OnPointerEnter(PointerEventData eventData) { if (cPeer == null) { return; } if (t != null) { TimerMgr.Instance.DestroyTimer(t); } PeerList plist = this.transform.parent.GetComponent(); plist.exitBtn(); enterBtn.GetComponent().cPeer = cPeer; // enterBtn.SetActive(true); BoxCollider bc = mViewTexture.GetComponent(); bc.size = new Vector3(1.8f, 1.4f, bc.size.z); bc.center = new Vector3(0, -0.2f, 0); /* t = TimerMgr.Instance.CreateTimer(() => { exitBtn(); }, 4f);*/ } public void OnPointerExit(PointerEventData eventData) { t = TimerMgr.Instance.CreateTimer(() => { BoxCollider bc = mViewTexture.GetComponent(); bc.size = new Vector3(1f, 1f, bc.size.z); bc.center = new Vector3(0, 0f, 0); exitBtn(); }, 2f); } }