using LitJson; using System.Collections.Generic; using UnityEngine; public class SCRtcHandle { public bool isSendOk = true; Queue jsondata = new Queue(); public SCRtcEngine mSCRtcEngine; private static SCRtcHandle _Instance; public static SCRtcHandle Instance { get { if (_Instance == null) { _Instance = new SCRtcHandle(); _Instance.mSCRtcEngine = new SCRtcAndroidEngine(); #if UNITY_ANDROID && !UNITY_EDITOR _Instance.mSCRtcEngine = new SCRtcAndroidEngine(); #endif #if UNITY_IOS && !UNITY_EDITOR _Instance.mSCRtcEngine = new SCRtcIosEngine(); #endif } return _Instance; } } public void goThread() { //Debug.Log("goThread=============>"); mSCRtcEngine.send(jsondata); } //加入RTC public void InitRTC(SCRtcConfig scC) { JsonData data = new JsonData(); data["action"] = "InitRTC"; data["data"] = new JsonData(); data["data"]["RoomId"] = scC.RoomId; data["data"]["roomPwd"] = scC.roomPwd; data["data"]["isSendAudio"] = scC.isSendAudio; data["data"]["isSendVideo"] = scC.isSendVideo; data["data"]["isRevAllAudio"] = scC.isRevAllAudio; data["data"]["isRevAllVideo"] = scC.isRevAllVideo; data["data"]["mWidth"] = scC.mWidth; data["data"]["mHight"] = scC.mHight; data["data"]["FPS"] = scC.FPS; data["data"]["Url"] = scC.Url; data["data"]["Post"] = scC.Post; jsondata = new Queue(); jsondata.Enqueue(data); } //加入房间 public void joinRoom(string req) { JsonData data = new JsonData(); data["action"] = "joinRoom"; data["data"] = new JsonData(); data["data"]["req"] = req; jsondata.Enqueue(data); } //加入房间 public void changeName(string name) { JsonData data = new JsonData(); data["action"] = "changeName"; data["data"] = new JsonData(); data["data"]["name"] = name; jsondata.Enqueue(data); } //开启摄像头 public void startCamera() { JsonData data = new JsonData(); data["action"] = "startCamera"; jsondata.Enqueue(data); } //关闭摄像头 public void stopCamera() { JsonData data = new JsonData(); data["action"] = "stopCamera"; jsondata.Enqueue(data); } //设置Video大小 public void changeVideo(int w,int h,int fps) { JsonData data = new JsonData(); data["action"] = "changeVideo"; data["data"] = new JsonData(); data["data"]["w"] = w; data["data"]["h"] = h; data["data"]["fps"] = fps; jsondata.Enqueue(data); } //开启或关闭Audio public void sendMic(bool boo) { JsonData data = new JsonData(); data["action"] = "sendMic"; data["data"] = new JsonData(); data["data"]["boo"] = boo; jsondata.Enqueue(data); } public void setMute(bool boo) { JsonData data = new JsonData(); data["action"] = "setMute"; data["data"] = new JsonData(); data["data"]["boo"] = boo; jsondata.Enqueue(data); } //开启或关闭Video public void sendVideo(bool boo) { JsonData data = new JsonData(); data["action"] = "sendVideo"; data["data"] = new JsonData(); data["data"]["boo"] = boo; jsondata.Enqueue(data); } //开启或关闭全部Video public void enableAudioOnly(bool boo) { JsonData data = new JsonData(); data["action"] = "enableAudioOnly"; data["data"] = new JsonData(); data["data"]["boo"] = boo; jsondata.Enqueue(data); } //开启或关闭全部Audio public void enableVideoOnly(bool boo) { JsonData data = new JsonData(); data["action"] = "enableVideoOnly"; data["data"] = new JsonData(); data["data"]["boo"] = boo; jsondata.Enqueue(data); } //开启扬声器 public void openSpeaker() { JsonData data = new JsonData(); data["action"] = "openSpeaker"; data["data"] = new JsonData(); data["data"]["boo"] = true ; jsondata.Enqueue(data); } //关闭扬声器 public void closeSpeaker() { JsonData data = new JsonData(); data["action"] = "closeSpeaker"; data["data"] = new JsonData(); data["data"]["boo"] = false; jsondata.Enqueue(data); } //调节音量 public void setVolume(int i) { JsonData data = new JsonData(); data["action"] = "setVolume"; data["data"] = new JsonData(); data["data"]["i"] = i; jsondata.Enqueue(data); } //调节外放音量 public void setSpeakerVolume(int i) { JsonData data = new JsonData(); data["action"] = "setSpeakerVolume"; data["data"] = new JsonData(); data["data"]["i"] = i; jsondata.Enqueue(data); } //订阅某人的设备 public void openRev(string consumerId) { WSHandler.Rtc.subscribe(consumerId); JsonData data = new JsonData(); data["action"] = "openRev"; data["data"] = new JsonData(); data["data"]["consumerId"] = consumerId; jsondata.Enqueue(data); } //取消订阅某人的设备 public void closeRev(string consumerId) { WSHandler.Rtc.unsubscribe(consumerId); JsonData data = new JsonData(); data["action"] = "closeRev"; data["data"] = new JsonData(); data["data"]["consumerId"] = consumerId; jsondata.Enqueue(data); } //关闭RTC public void Close() { WSHandler.Rtc.leave(); JsonData data = new JsonData(); data["action"] = "Close"; jsondata.Enqueue(data); Debug.Log("close"); } //设置TextureID public void addTextureID(string peerId,int textureID) { JsonData data = new JsonData(); data["action"] = "addTextureID"; data["data"] = new JsonData(); data["data"]["peerId"] = peerId; data["data"]["textureID"] = textureID; jsondata.Enqueue(data); } //调节自身音量 public void audioMeChange(double d) { JsonData data = new JsonData(); data["action"] = "audioMeChange"; data["data"] = new JsonData(); data["data"]["d"] = d; jsondata.Enqueue(data); } //设置Peer帧率 public void changePeerVideo(string consumerId,double d) { JsonData data = new JsonData(); data["action"] = "changePeerVideo"; data["data"] = new JsonData(); data["data"]["fps"] = d; data["data"]["consumerId"] = consumerId; jsondata.Enqueue(data); } //调节他人音量 public void audioPeerChange(string consumerId, double d) { JsonData data = new JsonData(); data["action"] = "audioPeerChange"; data["data"] = new JsonData(); data["data"]["d"] = d; data["data"]["consumerId"] = consumerId; jsondata.Enqueue(data); } //获取音量 public void GetaudioMe() { JsonData data = new JsonData(); data["action"] = "GetaudioMe"; jsondata.Enqueue(data); } //获取他人音量 public void GetaudioPeer(string consumerId) { JsonData data = new JsonData(); data["action"] = "GetaudioPeer"; jsondata.Enqueue(data); } public void onSocketMesseage(string msg) { JsonData data = new JsonData(); data["action"] = "onSocketMesseage"; data["data"] = msg; jsondata.Enqueue(data); } public void initRtpCapabilities(string msg) { JsonData data = new JsonData(); data["action"] = "initRtpCapabilities"; data["data"] = msg; jsondata.Enqueue(data); } public void createRecvTransport(string msg) { JsonData data = new JsonData(); data["action"] = "createRecvTransport"; data["data"] = msg; jsondata.Enqueue(data); } public void createSendTransport(string msg) { JsonData data = new JsonData(); data["action"] = "createSendTransport"; data["data"] = msg; jsondata.Enqueue(data); } public void onNewConsumer(string msg,string id) { JsonData data = new JsonData(); data["action"] = "onNewConsumer"; data["data"] = msg; data["id"] = id; jsondata.Enqueue(data); } public void getDevice() { JsonData data = new JsonData(); data["action"] = "getDevice"; jsondata.Enqueue(data); } public void addCameraLocal(int L) { JsonData data = new JsonData(); data["action"] = "addCameraLocal"; data["L"] = L; jsondata.Enqueue(data); } public string getwifi() { return (_Instance.mSCRtcEngine as SCRtcAndroidEngine).getwifi(); } public void setProduce(string msg) { (_Instance.mSCRtcEngine as SCRtcAndroidEngine).setProduce(msg); } }