using BeinLab.Util; using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class SCRtcManager : MonoBehaviour { public Queue queue; private void Start() { } public void InitListener() { queue = new Queue(); /* StopCoroutine("onUpdateRtc"); StartCoroutine("onUpdateRtc");*/ Debug.Log("StartListener"); } private void Update() { SCRtcFactory.Instance.Update(); } IEnumerator onUpdateRtc() { while (true) { yield return new WaitForEndOfFrame(); SCRtcFactory.Instance.Update(); yield return new WaitForEndOfFrame(); } } public virtual void OnRtcListener(JsonData data) { string pid; SCRtcPeer p; if (data != null) { switch (data["action"].ToString()) { case "OnListener": switch (data["data"]["action"].ToString()) { case "addPeer": SCRtcFactory.Instance.mSCRtcPeers.getPeer(data["data"]["data"]["pid"].ToString()).setInfo(data["data"]["data"]["kind"].ToString(), data["data"]["data"]["cid"].ToString(),true); WSHandler.Rtc.RtcResponse(data["data"]["data"]); WSHandler.Rtc.isnewConsumer = false; break; case "addVideo": pid = data["data"]["data"]["peerID"].ToString(); SCRtcFactory.Instance.mSCRtcPeers.getPeer(pid).setTexture(data); break; case "changeResolution": pid = data["data"]["data"]["peerID"].ToString(); if (pid != "Local") { SCRtcFactory.Instance.mSCRtcPeers.getPeer(pid).changeTexture(data); } break; } break; case "onNotification": switch (data["method"].ToString()) { case "closed": pid = data["data"]["peerId"].ToString(); Debug.Log("删除===>" + pid); SCRtcFactory.Instance.mSCRtcPeers.removePeers(pid); break; case "joined": p = SCRtcFactory.Instance.mSCRtcPeers.addPeers(data["data"]["peerId"].ToString()); p.setName(data["data"]["displayName"].ToString()); Debug.Log("添加===>" + p.name); break; case "joinRoom": if (data["data"]["room"]["users"].Count > 0) { for (int i = 0; i < data["data"]["room"]["users"].Count; i++) { SCRtcFactory.Instance.mSCRtcPeers.addPeers(data["data"]["room"]["users"][i]["peerId"].ToString()).setName(data["data"]["room"]["users"][i]["displayName"].ToString()); ; Debug.Log("添加===>" + data["data"]["room"]["users"][i]["displayName"].ToString()); } } break; case "init": SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities = data["data"].ToJson(); SCRtcFactory.Instance.mSCRtcHandle.joinRoom(SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities); break; } break; } } } }