using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; public class SCRtcFactory { private static SCRtcFactory _instance; public static SCRtcFactory Instance { get { if (_instance == null) { _instance = new SCRtcFactory(); } return _instance; } } public SCRtcManager mSCRtcManager; public SCRtcHandle mSCRtcHandle; public SCRtcMe mSCRtcMe; public SCRtcPeers mSCRtcPeers; public bool isClose = true; public SCRtcFactory() { mSCRtcHandle = SCRtcHandle.Instance; } public SCRtcConfig mSCRtcConfig; public void init(SCRtcConfig sRtc, SCRtcManager ms, SCRtcMe me, SCRtcPeers sPeers=null) { this.mSCRtcConfig = sRtc; if (sPeers != null) { this.mSCRtcPeers = sPeers; } else { this.mSCRtcPeers = new SCRtcPeers(); } this.mSCRtcManager = ms; if (me != null) { this.mSCRtcMe = me; } else { this.mSCRtcMe = new SCRtcMe(); } mSCRtcHandle.InitRTC(sRtc); isClose = false; } public void Close() { this.mSCRtcHandle.Close(); // } public void Update() { if(!isClose) { mSCRtcHandle.goThread(); if (this.mSCRtcManager != null) { if (this.mSCRtcManager.queue.Count > 0) this.mSCRtcManager.OnRtcListener(this.mSCRtcManager.queue.Dequeue()); } if (mSCRtcMe != null) mSCRtcMe.updateTexture(); if (mSCRtcPeers != null) mSCRtcPeers.updateTextures(); if (WSHandler.Rtc != null && WSHandler.Rtc.newConsumers.Count > 0) { JsonData data = JsonMapper.ToObject(WSHandler.Rtc.newConsumers.Dequeue()); TimerMgr.Instance.CreateTimer(() => { SCRtcPeer p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(data["data"]["peerId"].ToString()); if (p != null) { // p.setInfo(data["data"]["kind"].ToString(), data["data"]["id"].ToString(), !bool.Parse(data["data"]["producerPaused"].ToString())); p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(data["data"]["peerId"].ToString()); if (p != null) { p.setInfo(data["data"]["kind"].ToString(), data["data"]["id"].ToString(), !bool.Parse(data["data"]["producerPaused"].ToString())); } SCRtcFactory.Instance.mSCRtcHandle.onNewConsumer(data["data"].ToJson(), data["id"].ToString()); } }, float.Parse(data["data"]["rtpParameters"]["mid"].ToString())/10 + 0.1f); } } } }