OnWebSocketMsg.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. }
  19. public void OnWebSocketMessage(SignalResponse response)
  20. {
  21. Debug.Log("DGJ ===> OnWebSocketMessage " + response);
  22. switch (response.MessageCase)
  23. {
  24. case SignalResponse.MessageOneofCase.None:
  25. break;
  26. case SignalResponse.MessageOneofCase.Join:
  27. break;
  28. case SignalResponse.MessageOneofCase.Answer:
  29. break;
  30. case SignalResponse.MessageOneofCase.Offer:
  31. break;
  32. case SignalResponse.MessageOneofCase.Trickle:
  33. break;
  34. case SignalResponse.MessageOneofCase.Update:
  35. if(response.Update.Participants!=null)
  36. {
  37. string msg = response.Update.Participants.ToString();
  38. msg = msg.Remove(0, 1);
  39. msg = msg.Remove(msg.Length - 1, 1);
  40. Debug.Log("DGJ ==> "+ msg);
  41. JObject obj = JObject.Parse(msg);
  42. string metadata = obj["metadata"].ToString();
  43. Debug.Log("DGJ == > metadata " + metadata);
  44. metadata = metadata.Replace('\"', '"');
  45. Debug.Log("DGJ == > metadata "+ metadata);
  46. JObject obj2 = JObject.Parse(metadata);
  47. Debug.Log("DGJ ===> roleId " + obj2["roleId"].ToString());
  48. string state = obj["state"].ToString();
  49. if(state == "DISCONNECTED")
  50. {
  51. if (obj2["roleId"].ToString() == "2")
  52. {
  53. RTCRoomManager.Instance.UserOffline(UserEnum.Expert);
  54. }
  55. if (obj2["roleId"].ToString() == "1")
  56. {
  57. RTCRoomManager.Instance.UserOffline(UserEnum.Conterl);
  58. }
  59. }
  60. else if(state == "ACTIVE")
  61. {
  62. if (obj2["roleId"].ToString() == "2")
  63. {
  64. string uid = obj["sid"].ToString();
  65. if (ScenesManager.Instance.getWindow() == ScenesManager.SceneType.ShowRTC)
  66. {
  67. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRoom);
  68. }
  69. // 专家进入房间 并且当前是在远程协助页面
  70. RTCRoomManager.Instance.ExpertJonin(uid);
  71. RTCRoomManager.Instance.UserJoined(UserEnum.Expert, obj2);
  72. }
  73. if (obj2["roleId"].ToString() == "1")
  74. {
  75. RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2);
  76. }
  77. }
  78. }
  79. break;
  80. case SignalResponse.MessageOneofCase.TrackPublished:
  81. break;
  82. case SignalResponse.MessageOneofCase.Leave:
  83. break;
  84. case SignalResponse.MessageOneofCase.Mute:
  85. break;
  86. case SignalResponse.MessageOneofCase.SpeakersChanged:
  87. break;
  88. case SignalResponse.MessageOneofCase.RoomUpdate:
  89. break;
  90. case SignalResponse.MessageOneofCase.ConnectionQuality:
  91. break;
  92. case SignalResponse.MessageOneofCase.StreamStateUpdate:
  93. break;
  94. case SignalResponse.MessageOneofCase.SubscribedQualityUpdate:
  95. break;
  96. case SignalResponse.MessageOneofCase.SubscriptionPermissionUpdate:
  97. break;
  98. case SignalResponse.MessageOneofCase.RefreshToken:
  99. break;
  100. case SignalResponse.MessageOneofCase.TrackUnpublished:
  101. break;
  102. case SignalResponse.MessageOneofCase.Pong:
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. }