123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- 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<PeerList>();
- plist.exitBtn();
- enterBtn.GetComponent<SysEnterManager>().cPeer = cPeer;
- // enterBtn.SetActive(true);
- BoxCollider bc = mViewTexture.GetComponent<BoxCollider>();
- 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<BoxCollider>();
- bc.size = new Vector3(1f, 1f, bc.size.z);
- bc.center = new Vector3(0, 0f, 0);
- exitBtn();
- }, 2f);
- }
- }
|