using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CustomRTC : SCRtcManager { public static CustomRTC Instance; public TextMesh text; public GameObject myQuad; public RenderTexture myRenderTexture; //public GameObject peerQuad; public Camera cam; public LoginManager loginManager; public CustomPeerList cpl; public CustomMe me; public ItemList list; public MeshRenderer bigMr; public string bigNameID = ""; public Texture2D t2; public Texture2D t2fang; private void Start() { Instance = this; //initRtc(); } private void Update() { SCRtcFactory.Instance.Update(); } //加入Rtc public void initRtc() { InitListener(); cpl = new CustomPeerList(); list.initList(cpl); me = new CustomMe(); me.myQuad = myQuad; // changeVideo3(); // } public void showNextTexture() { bool isChoose = false; CustomPeer hasBig = null; foreach (CustomPeer value in cpl.getPeers().Values) { Debug.Log("Word"); if(value.peerId!=bigNameID&&value.cIdV!=""&&!value.isBig) { bigMr.material.mainTexture = value.tex; bigNameID = value.peerId; isChoose = true; } if (value.peerId != bigNameID && value.cIdV != "" ) { hasBig = value; } } if(!isChoose) { Debug.Log("LLL"); bigMr.material.mainTexture = t2fang; bigNameID = ""; } if(list.configs.Count<=0&& hasBig!=null) { hasBig.bigView.GetComponent().close(); } } public void joinRoom() { Debug.Log("joinRoom" + SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities); SCRtcFactory.Instance.mSCRtcHandle.joinRoom(SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities); } public void changeName(string name) { SCRtcFactory.Instance.mSCRtcConfig.disPlayName = name; SCRtcFactory.Instance.mSCRtcHandle.changeName(SCRtcFactory.Instance.mSCRtcConfig.disPlayName); } //改变自己的Video public void ChangeMyVideo(int width, int hight, int FPS) { SCRtcFactory.Instance.mSCRtcHandle.changeVideo(width, hight, FPS); } public void changeMySize(int w, int h, int Fps = 30) { CustomInfo.mWidth = w; CustomInfo.mHight = h; // openCamera.Instance.restart(Fps); if (myRenderTexture != null) { myRenderTexture.Release(); } myRenderTexture = new RenderTexture(w, h, 1); cam.targetTexture = myRenderTexture; // SCRtcFactory.Instance.mSCRtcMe.changeQuad(w, h); SCRtcFactory.Instance.mSCRtcMe.setMyCamera(myRenderTexture); } public void changeFps1() { SCRtcFactory.Instance.mSCRtcConfig.FPS = 30; openCamera.Instance.restart(SCRtcFactory.Instance.mSCRtcConfig.FPS); Debug.Log("FPS"+30); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 30); } public void changeFps2() { SCRtcFactory.Instance.mSCRtcConfig.FPS = 15; openCamera.Instance.restart(SCRtcFactory.Instance.mSCRtcConfig.FPS); Debug.Log("FPS"+15); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 15); } public void changeFps3() { SCRtcFactory.Instance.mSCRtcConfig.FPS = 1; openCamera.Instance.restart(SCRtcFactory.Instance.mSCRtcConfig.FPS); Debug.Log("FPS"+1); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 1); } public void changeVideo1() { changeMySize(1920, 1080); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 30); Debug.Log("超清"); } public void changeVideo2() { changeMySize(1280, 720); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 30); Debug.Log("高清"); } public void changeVideo3() { changeMySize(640, 480); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 30); Debug.Log("标清"); } public void changeVideo4() { changeMySize(360, 240); SCRtcFactory.Instance.mSCRtcHandle.changeVideo(CustomInfo.mWidth, CustomInfo.mHight, 30); } //开启或关闭Video public void sendVideo(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo); } //开启或关闭全部Video public void enableAudioOnly(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.enableAudioOnly(boo); } //开启或关闭全部Audio public void enableVideoOnly(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.enableVideoOnly(boo); } //开启或关闭Audio public void sendMic(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendMic(boo); } //开启扬声器 public void openSpeaker() { SCRtcFactory.Instance.mSCRtcHandle.openSpeaker(); } //关闭扬声器 public void closeSpeaker() { SCRtcFactory.Instance.mSCRtcHandle.closeSpeaker(); } public TextMesh volume; double volumeD; public void setAddVolume(int f) { volumeD += 0.1f; volume.text = volumeD.ToString(); Debug.Log("setVolume" + volumeD.ToString()); SCRtcFactory.Instance.mSCRtcHandle.audioMeChange(volumeD); } public void setVolume(int f) { volumeD -= 0.1f; volume.text = volumeD.ToString(); Debug.Log("setVolume" + volumeD.ToString()); SCRtcFactory.Instance.mSCRtcHandle.audioMeChange(volumeD); } //关闭RTC public void Close() { Debug.Log("退出房间CloseStart"); SCRtcFactory.Instance.Close(); if (SCRtcFactory.Instance.mSCRtcPeers != null) { foreach (CustomPeer value in SCRtcFactory.Instance.mSCRtcPeers.getPeers().Values) { if(value.isBig) Destroy(value.bigView); } SCRtcFactory.Instance.mSCRtcPeers.initPeers(); } ViewManager.Instance.ShowView(ViewManager.LOGINROOM_VIEW); loginManager.ClearRoomInput(); loginManager.ClearPassInput(); bigNameID = ""; } public override void OnRtcListener(JsonData data) { base.OnRtcListener(data); if (text != null) text.text = text.text.Insert(0, "\n" + data.ToJson() + "Start"); //base.OnRtcListener(data);//这个方法让父类的方法又执行了一次 if (data != null) { switch (data["action"].ToString()) { case "OnSDKInited": OnSDKInited(data); break; case "OnListener": OnListener(data); break; case "onDisconnected": ViewManager.Instance.ShowTuSi("ServerException"); onDisconnected(data); break; case "onNotification": onNotification(data); break; case "onRequest": onRequest(data); break; case "onFail": onFail(data); break; } } if (text != null) text.text = text.text.Insert(0, "\nEnd"); } public void OnSDKInited(JsonData data) { } public void OnListener(JsonData data) { string pid; SCRtcPeer p; switch (data["data"]["action"].ToString()) { case "addPeer": break; case "addVideo": break; case "changeResolution": break; } } public void onDisconnected(JsonData data) { } public void onNotification(JsonData data) { switch (data["method"].ToString()) { case "consumerClosed": Debug.Log("PPT1"); CustomPeer cp = (CustomPeer)cpl.getPeer(data["data"]["peerId"].ToString()); //if (cp.cIdA == data["data"]["consumerId"].ToString()) //{ // return; //} cp.changeInfo(data["data"]["consumerId"].ToString(), cp); // list.Refresh(); break; case "init": string nameS = PlayerPrefs.GetString("name"); if (nameS != null && nameS != "") { changeName(nameS); } else { ViewManager.Instance.ShowView(ViewManager.SETNAME_VIEW); } break; case "closed": list.initList(cpl); if(bigNameID == data["data"]["peerId"].ToString()) { Debug.Log("PPT"); showNextTexture(); //list.Refresh(); } if(list.configs.Count<=0) { showNextTexture(); } break; case "joined": break; case "joinRoom": loginManager.JoinSuccess(); // ViewManager.Instance.ShowView(ViewManager.ROOM_VIEW); break; case "changeDisplayName": joinRoom(); break; } } public void onRequest(JsonData data) { } public void onFail(JsonData data) { Debug.Log("data===========>" + data.ToJson()); Debug.Log("cccc" + data["data"].ToString()); loginManager.JoinFail(data); // Close(); } }