123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
-
- using LitJson;
- using System.Collections.Generic;
- using UnityEngine;
- public class SCRtcHandle
- {
- public bool isSendOk = true;
- Queue<JsonData> jsondata = new Queue<JsonData>();
- 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.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();
- Debug.Log("close22222");
- JsonData data = new JsonData();
- data["action"] = "Close";
- jsondata.Enqueue(data);
- Debug.Log("close22222end");
- }
- //设置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 void setProduce(string msg)
- {
- // (_Instance.mSCRtcEngine as SCRtcAndroidEngine).setProduce(msg);
- }
- }
|