OnWebSocketMsg.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using LiveKit.Proto;
  2. using Newtonsoft.Json.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class OnWebSocketMsg : MonoSingleton<OnWebSocketMsg>
  7. {
  8. private void Update()
  9. {
  10. if(SignalClient.SignalResponseList.Count>0)
  11. {
  12. int ct = SignalClient.SignalResponseList.Count;
  13. for (int i = 0; i < ct; i++)
  14. {
  15. OnWebSocketMessage(SignalClient.SignalResponseList.Dequeue());
  16. }
  17. }
  18. //if (SignalClient.showErrorList.Count > 0)
  19. //{
  20. // ShowError error = SignalClient.showErrorList.Dequeue();
  21. // // ErrorPopup.Instance.ShowRTCError(error.error, error.timer);
  22. //}
  23. }
  24. public void OnWebSocketMessage(SignalResponse response)
  25. {
  26. Debug.Log("DGJ ===++> OnWebSocketMessage " + response);
  27. switch (response.MessageCase)
  28. {
  29. case SignalResponse.MessageOneofCase.None:
  30. break;
  31. case SignalResponse.MessageOneofCase.Join:
  32. //string msg = response.Join.Participant.Metadata.ToString();
  33. ////msg = msg.Remove(0, 1);
  34. ////msg = msg.Remove(msg.Length - 1, 1);
  35. //// Debug.Log("DGJ ==> " + msg);
  36. ////JObject obj = JObject.Parse(msg);
  37. ////string metadata = obj["metadata"].ToString();
  38. //string metadata = msg;
  39. //// Debug.Log("DGJ == > metadata " + metadata);
  40. //metadata = metadata.Replace('\"', '"');
  41. //Debug.Log("DGJ == > metadata " + metadata);
  42. //JObject obj2 = JObject.Parse(metadata);
  43. //Debug.Log("DGJ ===> roleId " + obj2["roleId"].ToString());
  44. ////string state = obj["state"].ToString();
  45. //if (obj2["roleId"].ToString() == "2")
  46. //{
  47. // string uid = response.Join.Participant.Sid.ToString();
  48. // if (ScenesManager.Instance.getWindow() == ScenesManager.SceneType.ShowRTC)
  49. // {
  50. // ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRoom);
  51. // }
  52. // // 专家进入房间 并且当前是在远程协助页面
  53. // RTCRoomManager.Instance.ExpertJonin(uid);
  54. // RTCRoomManager.Instance.UserJoined(UserEnum.Expert, obj2);
  55. //}
  56. //if (obj2["roleId"].ToString() == "1")
  57. //{
  58. // RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2);
  59. //}
  60. //if (obj2["roleId"].ToString() == "3")
  61. //{
  62. // RTCRoomManager.Instance.UserJoined(UserEnum.Player);
  63. // // RTCRoomManager.Instance.OnLocalUserJoined();
  64. //}
  65. ////
  66. ////if (response.Update.Participants != null)
  67. ////{
  68. //// if (obj2["roleId"].ToString() == "1")
  69. //// {
  70. //// RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2);
  71. //// }
  72. //// if (obj2["roleId"].ToString() == "3")
  73. //// {
  74. //// RTCRoomManager.Instance.UserJoined(UserEnum.Player);
  75. //// // RTCRoomManager.Instance.OnLocalUserJoined();
  76. //// }
  77. //// //if (state == "DISCONNECTED")
  78. //// //{
  79. //// // //if (obj2["roleId"].ToString() == "2")
  80. //// // //{
  81. //// // // RTCRoomManager.Instance.UserOffline(UserEnum.Expert);
  82. //// // //}
  83. //// // //if (obj2["roleId"].ToString() == "1")
  84. //// // //{
  85. //// // // RTCRoomManager.Instance.UserOffline(UserEnum.Conterl);
  86. //// // //}
  87. //// //}
  88. //// //else if (state == "ACTIVE")
  89. //// //{
  90. //// //}
  91. ////}
  92. break;
  93. case SignalResponse.MessageOneofCase.Answer:
  94. break;
  95. case SignalResponse.MessageOneofCase.Offer:
  96. break;
  97. case SignalResponse.MessageOneofCase.Trickle:
  98. break;
  99. case SignalResponse.MessageOneofCase.Update:
  100. string msg = response.ToString();
  101. // msg = msg.Remove(0, 1);
  102. // msg = msg.Remove(msg.Length - 1, 1);
  103. Debug.Log("DGJ ==> " + msg);
  104. JObject obj = JObject.Parse(msg);
  105. if(obj["update"]["participants"][0]["metadata"]!=null)
  106. {
  107. string metadata = obj["update"]["participants"][0]["metadata"].ToString();
  108. // string metadata = msg;
  109. // Debug.Log("DGJ == > metadata " + metadata);
  110. metadata = metadata.Replace('\"', '"');
  111. Debug.Log("DGJ == > metadata " + metadata);
  112. JObject obj2 = JObject.Parse(metadata);
  113. string state = obj["update"]["participants"][0]["state"].ToString();
  114. Debug.Log(state + " DGJ ===> roleId " + obj2["roleId"].ToString());
  115. if (state == "ACTIVE" || state == "JOINED")
  116. {
  117. if (obj2["roleId"].ToString() == "2")
  118. {
  119. // string uid = response.Join.Participant.Sid.ToString();
  120. string uid = obj["update"]["participants"][0]["sid"].ToString();
  121. //if (ScenesManager.Instance.getWindow() == ScenesManager.SceneType.ShowRTC)
  122. //{
  123. if (ScenesManager.Instance.getWindow() != ScenesManager.SceneType.ShowRoom)
  124. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRoom);
  125. RTCMainManager.Instance.ShowRoomMain();
  126. //}
  127. // GHZRoomMain.Instance.show();
  128. // GHZRoomMain.Instance.Show();
  129. // 专家进入房间 并且当前是在远程协助页面
  130. RTCRoomManager.Instance.ExpertJonin(uid);
  131. RTCRoomManager.Instance.UserJoined(UserEnum.Expert, obj2);
  132. }
  133. if (obj2["roleId"].ToString() == "1")
  134. {
  135. RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2);
  136. }
  137. if (obj2["roleId"].ToString() == "3")
  138. {
  139. RTCRoomManager.Instance.UserJoined(UserEnum.Player);
  140. // ErrorPopup.Instance.UpdateRTCState(NetState.Connect);
  141. //if (SignalClient.isReconnect == true)
  142. //{
  143. // Debug.LogError("RTC服务重连成功");
  144. // SignalClient.showErrorList.Enqueue(new ShowError("RTC服务重连成功", 3));
  145. // SignalClient.isReconnect = false;
  146. //}
  147. // RTCRoomManager.Instance.OnLocalUserJoined();
  148. }
  149. }
  150. }
  151. break;
  152. case SignalResponse.MessageOneofCase.TrackPublished:
  153. break;
  154. case SignalResponse.MessageOneofCase.Leave:
  155. break;
  156. case SignalResponse.MessageOneofCase.Mute:
  157. break;
  158. case SignalResponse.MessageOneofCase.SpeakersChanged:
  159. break;
  160. case SignalResponse.MessageOneofCase.RoomUpdate:
  161. break;
  162. case SignalResponse.MessageOneofCase.ConnectionQuality:
  163. break;
  164. case SignalResponse.MessageOneofCase.StreamStateUpdate:
  165. break;
  166. case SignalResponse.MessageOneofCase.SubscribedQualityUpdate:
  167. break;
  168. case SignalResponse.MessageOneofCase.SubscriptionPermissionUpdate:
  169. break;
  170. case SignalResponse.MessageOneofCase.RefreshToken:
  171. break;
  172. case SignalResponse.MessageOneofCase.TrackUnpublished:
  173. break;
  174. case SignalResponse.MessageOneofCase.Pong:
  175. break;
  176. default:
  177. break;
  178. }
  179. }
  180. }