123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using LiveKit.Proto;
- using Newtonsoft.Json.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class OnWebSocketMsg : MonoSingleton<OnWebSocketMsg>
- {
- 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;
- }
- }
- }
|