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()); } } } public void OnWebSocketMessage(SignalResponse response) { Debug.Log("DGJ ===> OnWebSocketMessage " + response); switch (response.MessageCase) { case SignalResponse.MessageOneofCase.None: break; case SignalResponse.MessageOneofCase.Join: break; case SignalResponse.MessageOneofCase.Answer: break; case SignalResponse.MessageOneofCase.Offer: break; case SignalResponse.MessageOneofCase.Trickle: break; case SignalResponse.MessageOneofCase.Update: if(response.Update.Participants!=null) { string msg = response.Update.Participants.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(); 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(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") { if (obj2["roleId"].ToString() == "2") { string uid = obj["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); } } } 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; } } }