123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- 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<BigVideoManager>().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();
- }
- }
|