using LiveKit.Proto; using Newtonsoft.Json.Linq; using System.Collections; using System.Collections.Generic; using UnityEngine; public class OnWebSocketMsg : MonoSingleton { private void Update() { if(SignalClient.SignalResponseList.Count>0) { int ct = SignalClient.SignalResponseList.Count; for (int i = 0; i < ct; i++) { OnWebSocketMessage(SignalClient.SignalResponseList.Dequeue()); } } //if (SignalClient.showErrorList.Count > 0) //{ // ShowError error = SignalClient.showErrorList.Dequeue(); // // ErrorPopup.Instance.ShowRTCError(error.error, error.timer); //} } public void OnWebSocketMessage(SignalResponse response) { Debug.Log("DGJ ===++> OnWebSocketMessage " + response); switch (response.MessageCase) { case SignalResponse.MessageOneofCase.None: break; case SignalResponse.MessageOneofCase.Join: //string msg = response.Join.Participant.Metadata.ToString(); ////msg = msg.Remove(0, 1); ////msg = msg.Remove(msg.Length - 1, 1); //// Debug.Log("DGJ ==> " + msg); ////JObject obj = JObject.Parse(msg); ////string metadata = obj["metadata"].ToString(); //string metadata = msg; //// Debug.Log("DGJ == > metadata " + metadata); //metadata = metadata.Replace('\"', '"'); //Debug.Log("DGJ == > metadata " + metadata); //JObject obj2 = JObject.Parse(metadata); //Debug.Log("DGJ ===> roleId " + obj2["roleId"].ToString()); ////string state = obj["state"].ToString(); //if (obj2["roleId"].ToString() == "2") //{ // string uid = response.Join.Participant.Sid.ToString(); // if (ScenesManager.Instance.getWindow() == ScenesManager.SceneType.ShowRTC) // { // ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRoom); // } // // 专家进入房间 并且当前是在远程协助页面 // RTCRoomManager.Instance.ExpertJonin(uid); // RTCRoomManager.Instance.UserJoined(UserEnum.Expert, obj2); //} //if (obj2["roleId"].ToString() == "1") //{ // RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2); //} //if (obj2["roleId"].ToString() == "3") //{ // RTCRoomManager.Instance.UserJoined(UserEnum.Player); // // RTCRoomManager.Instance.OnLocalUserJoined(); //} //// ////if (response.Update.Participants != null) ////{ //// if (obj2["roleId"].ToString() == "1") //// { //// RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2); //// } //// if (obj2["roleId"].ToString() == "3") //// { //// RTCRoomManager.Instance.UserJoined(UserEnum.Player); //// // RTCRoomManager.Instance.OnLocalUserJoined(); //// } //// //if (state == "DISCONNECTED") //// //{ //// // //if (obj2["roleId"].ToString() == "2") //// // //{ //// // // RTCRoomManager.Instance.UserOffline(UserEnum.Expert); //// // //} //// // //if (obj2["roleId"].ToString() == "1") //// // //{ //// // // RTCRoomManager.Instance.UserOffline(UserEnum.Conterl); //// // //} //// //} //// //else if (state == "ACTIVE") //// //{ //// //} ////} break; case SignalResponse.MessageOneofCase.Answer: break; case SignalResponse.MessageOneofCase.Offer: break; case SignalResponse.MessageOneofCase.Trickle: break; case SignalResponse.MessageOneofCase.Update: string msg = response.ToString(); // msg = msg.Remove(0, 1); // msg = msg.Remove(msg.Length - 1, 1); Debug.Log("DGJ ==> " + msg); JObject obj = JObject.Parse(msg); if(obj["update"]["participants"][0]["metadata"]!=null) { string metadata = obj["update"]["participants"][0]["metadata"].ToString(); // string metadata = msg; // Debug.Log("DGJ == > metadata " + metadata); metadata = metadata.Replace('\"', '"'); Debug.Log("DGJ == > metadata " + metadata); JObject obj2 = JObject.Parse(metadata); string state = obj["update"]["participants"][0]["state"].ToString(); Debug.Log(state + " DGJ ===> roleId " + obj2["roleId"].ToString()); if (state == "ACTIVE" || state == "JOINED") { if (obj2["roleId"].ToString() == "2") { // string uid = response.Join.Participant.Sid.ToString(); string uid = obj["update"]["participants"][0]["sid"].ToString(); //if (ScenesManager.Instance.getWindow() == ScenesManager.SceneType.ShowRTC) //{ if (ScenesManager.Instance.getWindow() != ScenesManager.SceneType.ShowRoom) ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRoom); RTCMainManager.Instance.ShowRoomMain(); //} // GHZRoomMain.Instance.show(); // GHZRoomMain.Instance.Show(); // 专家进入房间 并且当前是在远程协助页面 RTCRoomManager.Instance.ExpertJonin(uid); RTCRoomManager.Instance.UserJoined(UserEnum.Expert, obj2); } if (obj2["roleId"].ToString() == "1") { RTCRoomManager.Instance.UserJoined(UserEnum.Conterl, obj2); } if (obj2["roleId"].ToString() == "3") { RTCRoomManager.Instance.UserJoined(UserEnum.Player); // ErrorPopup.Instance.UpdateRTCState(NetState.Connect); //if (SignalClient.isReconnect == true) //{ // Debug.LogError("RTC服务重连成功"); // SignalClient.showErrorList.Enqueue(new ShowError("RTC服务重连成功", 3)); // SignalClient.isReconnect = false; //} // RTCRoomManager.Instance.OnLocalUserJoined(); } } } break; case SignalResponse.MessageOneofCase.TrackPublished: break; case SignalResponse.MessageOneofCase.Leave: break; case SignalResponse.MessageOneofCase.Mute: break; case SignalResponse.MessageOneofCase.SpeakersChanged: break; case SignalResponse.MessageOneofCase.RoomUpdate: break; case SignalResponse.MessageOneofCase.ConnectionQuality: break; case SignalResponse.MessageOneofCase.StreamStateUpdate: break; case SignalResponse.MessageOneofCase.SubscribedQualityUpdate: break; case SignalResponse.MessageOneofCase.SubscriptionPermissionUpdate: break; case SignalResponse.MessageOneofCase.RefreshToken: break; case SignalResponse.MessageOneofCase.TrackUnpublished: break; case SignalResponse.MessageOneofCase.Pong: break; default: break; } } }