using BeinLab.Util; using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; 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; private bool _isClose; public bool isClose { get { return _isClose; } set { // Debug.Log("3333333333333333333333"); _isClose = value; } } public SCRtcFactory() { mSCRtcHandle = SCRtcHandle.Instance; } public SCRtcConfig mSCRtcConfig; public void init(SCRtcConfig sRtc, SCRtcManager ms, SCRtcMe me, SCRtcPeers sPeers=null) { // Debug.Log("isClose=init==>"); 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) // { // Debug.Log("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(()=> { Debug.Log("data====>" + data.ToJson()); SCRtcPeer p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(data["data"]["peerId"].ToString()); 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())+0.5f); } // } } }