LiveRTCRoomMain.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using Blue;
  2. using LitJson;
  3. using Newtonsoft.Json.Linq;
  4. using SC.XR.Unity.Module_InputSystem;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using static ScenesManager;
  10. public class LiveRTCRoomMain : MonoSingleton<LiveRTCRoomMain>,IController
  11. {
  12. public Button videoOpenBtn;
  13. public Button videoCloseBtn;
  14. public Button audioOpenBtn;
  15. public Button audioCloseBtn;
  16. public Button clearArrowBtn;
  17. public Button leaveRoomBtn;
  18. public GameObject defaultUI;
  19. public Button noBtn;
  20. public Button yesBtn;
  21. public RawImage rtcRawImage;
  22. public ManipulationHandler dragBtn;
  23. private void Start()
  24. {
  25. OnInit();
  26. dragBtn.Target = transform.parent;
  27. }
  28. private void Update()
  29. {
  30. if (RTCRoomManager.Instance.expertView != null)
  31. {
  32. //if (!rtcRawImage.gameObject.activeSelf)
  33. // rtcRawImage.gameObject.SetActive(true);
  34. rtcRawImage.texture = RTCRoomManager.Instance.expertView.VideoView;
  35. }
  36. else
  37. {
  38. //if (rtcRawImage.gameObject.activeSelf)
  39. // rtcRawImage.gameObject.SetActive(false);
  40. }
  41. }
  42. private void OnInit()
  43. {
  44. videoOpenBtn.onClick.AddListener(()=> { SetVideo(true); });
  45. videoCloseBtn.onClick.AddListener(() => { SetVideo(false); });
  46. audioOpenBtn.onClick.AddListener(() => { SetAudio(true); });
  47. audioCloseBtn.onClick.AddListener(() => { SetAudio(false); });
  48. clearArrowBtn.onClick.AddListener(ClearAllArrow);
  49. leaveRoomBtn.onClick.AddListener(() => { SetDefaultUI(true); });
  50. noBtn.onClick.AddListener(() => { SetDefaultUI(false); });
  51. yesBtn.onClick.AddListener(LeaveRoom);
  52. }
  53. public void SetAudio(bool state)
  54. {
  55. GHZRtcManager.Instance.OnMicrophone(state);
  56. audioCloseBtn.gameObject.SetActive(state);
  57. audioOpenBtn.gameObject.SetActive(!state);
  58. }
  59. public void SetVideo(bool state)
  60. {
  61. GHZRtcManager.Instance.OnWebCam(state);
  62. videoCloseBtn.gameObject.SetActive(state);
  63. videoOpenBtn.gameObject.SetActive(!state);
  64. }
  65. public void ClearAllArrow()
  66. {
  67. if (ArrowList.Instance)
  68. {
  69. ArrowList.Instance.DeleteAll();
  70. }
  71. }
  72. public void SetDefaultUI(bool state)
  73. {
  74. defaultUI.SetActive(state);
  75. }
  76. public void LeaveRoom()
  77. {
  78. // RTCRoomManager.Instance.LeaveChannel();
  79. // MQTT 通知 专家退出房间
  80. JsonData data = new JsonData();
  81. data["action"] = "ExpertLeaveRoom";
  82. MQTTManager.Instance.PushMsg(MQTTManager.Instance.front + "room/" + MQTTManager.Instance.roomId, data.ToJson());
  83. // 通知后台 退出房间消息
  84. GameStart.Instance.StartCoroutine(HttpTool.Instance.SendHttp(HttpActionLang.rtc_leave, "", message =>
  85. {
  86. JObject jobject = JObject.Parse(message);
  87. if (jobject["code"].ToString() == "200")
  88. {
  89. //Debug.LogError($"Message:{message}+finished:{jobject["data"]["finished"]}");
  90. Debug.Log(HttpActionLang.rtc_leave + " DGJ ====> 请求成功 " + message);
  91. if (PopPeerView.Instance)
  92. {
  93. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  94. PopPeerView.Instance.list.localPosition = new Vector3(0, 0, 0);
  95. PopPeerView.Instance.list.localEulerAngles = new Vector3(0, 0, 0);
  96. }
  97. if (PopUpInfo.Instance)
  98. {
  99. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  100. PopUpInfo.Instance.transform.localPosition = new Vector3(0, 0, 0);
  101. PopUpInfo.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  102. }
  103. ScenesManager.Instance.showWindow(SceneType.ShowChoose);
  104. if (InviteDlg.Instance)
  105. {
  106. InviteDlg.Instance.InvitingUnionIdList.Clear();
  107. }
  108. if (ArrowList.Instance)
  109. {
  110. ArrowList.Instance.DeleteAll();
  111. }
  112. if (RoomFile.Instance)
  113. {
  114. RoomFile.Instance.ClearAllFileItem();
  115. }
  116. if (PrintscreenList.Instance)
  117. {
  118. PrintscreenList.Instance.DeleteAll();
  119. }
  120. if (PopPeerView.Instance)
  121. {
  122. PopPeerView.Instance.DestoryAll();
  123. }
  124. if (PopCall.Instance)
  125. {
  126. // PopCall.Instance.gameObject.SetActive(false);
  127. }
  128. //if (ShowRoom.Instance)
  129. //{
  130. // ShowRoom.Instance.ShowMainScreen();
  131. // ShowRoom.Instance.transform.localPosition = new Vector3(0, 0, 0);
  132. // ShowRoom.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  133. //}
  134. API_GSXR_Slam.GSXR_Reset_Slam();
  135. // RemoteRtc.Instance.FiltrationCamera(true);
  136. }
  137. else
  138. {
  139. Debug.LogError(HttpActionLang.rtc_leave + " 请求失败 " + message);
  140. }
  141. }));
  142. }
  143. private void OnEnable()
  144. {
  145. audioCloseBtn.gameObject.SetActive(true);
  146. audioOpenBtn.gameObject.SetActive(false);
  147. videoCloseBtn.gameObject.SetActive(true);
  148. videoOpenBtn.gameObject.SetActive(false);
  149. }
  150. }