123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using LitJson;
- using System.Collections.Generic;
- using UnityEngine;
- public class SCRtcAndroidEngine : SCRtcEngine
- {
- //调节他人音量
- public double GetaudioMe()
- {
- double d = 0.0f;
- #if UNITY_ANDROID && !UNITY_EDITOR
- d = CurrentActivity.Call<double>("GetaudioMe");
- #endif
- return d;
- }
- //调节他人音量
- public double GetaudioPeer(string consumerId)
- {
- double d = 0.0f;
- #if UNITY_ANDROID && !UNITY_EDITOR
- d = CurrentActivity.Call<double>("GetaudioPeer", consumerId);
- #endif
- return d;
- }
- SDKCallbackListener sdk;
- //增加监听
- public void addListener()
- {
- if (sdk == null)
- {
- sdk = new SDKCallbackListener();
- UnityEngine.Debug.Log("addListener");
- #if UNITY_ANDROID&& !UNITY_EDITOR
- CurrentActivity.Call("initSDK", sdk);
- #endif
- Debug.Log("addListenerEND"); ;
- }
- }
- override public void send(Queue<JsonData> jsondata)
- {
- JsonData data;
- if (jsondata.Count > 0)
- {
- Debug.Log("close22222333");
- data = jsondata.Dequeue();
- Debug.Log("close22222" + data["action"].ToString());
- switch (data["action"].ToString())
- {
- case "InitRTC":
- #if UNITY_ANDROID && !UNITY_EDITOR
- addListener();
- CurrentActivity.Call("SetConfig", data["data"]["RoomId"].ToString(), data["data"]["roomPwd"].ToString(),bool.Parse(data["data"]["isSendAudio"].ToString()), bool.Parse(data["data"]["isSendVideo"].ToString()), bool.Parse(data["data"]["isRevAllAudio"].ToString()), bool.Parse(data["data"]["isRevAllVideo"].ToString()), int.Parse(data["data"]["mWidth"].ToString()), int.Parse(data["data"]["mHight"].ToString()), int.Parse(data["data"]["FPS"].ToString()));
- CurrentActivity.Call("InitSocket", data["data"]["Url"].ToString(), int.Parse(data["data"]["Post"].ToString()));
- #endif
- break;
- case "changeVideo":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("changeVideo",int.Parse(data["data"]["w"].ToString()),int.Parse(data["data"]["h"].ToString()),int.Parse(data["data"]["fps"].ToString()));
- #endif
- break;
- case "setMute":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("setMute",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "sendVideo":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("sendVideo",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "enableVideoOnly":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("enableVideoOnly",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "enableAudioOnly":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("enableAudioOnly",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "openSpeaker":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("openSpeaker",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "closeSpeaker":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("closeSpeaker",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "setVolume":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("setVolume",int.Parse(data["data"]["i"].ToString()));
- #endif
- break;
- case "sendMic":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("sendMic",bool.Parse(data["data"]["boo"].ToString()));
- #endif
- break;
- case "openRev":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("openRev",data["data"]["consumerId"].ToString());
- #endif
- break;
- case "closeRev":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("closeRev",data["data"]["consumerId"].ToString());
- #endif
- break;
- case "Close":
- Debug.Log("退出房间Start");
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("close");
- #endif
- Debug.Log("退出房间End");
- SCRtcFactory.Instance.isClose = true;
- break;
- case "addTextureID":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("addTextureID", data["data"]["peerId"].ToString(), int.Parse(data["data"]["textureID"].ToString()));
- #endif
- break;
- case "audioPeerChange":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("audioPeerChange", data["data"]["consumerId"].ToString(), double.Parse(data["data"]["d"].ToString()));
- #endif
- break;
- case "audioMeChange":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("audioMeChange", double.Parse(data["data"]["d"].ToString()));
- #endif
- break;
- case "changePeerVideo":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("changePeerVideo", data["data"]["consumerId"].ToString(), int.Parse(data["data"]["fps"].ToString()));
- #endif
- break;
- case "changeName":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("changeName", data["data"]["name"].ToString());
- #endif
- break;
- case "joinRoom":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("joinRoom", data["data"]["req"].ToString());
- #endif
- break;
- case "GetaudioMe":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("GetaudioMe");
- #endif
- break;
- case "GetaudioPeer":
- #if UNITY_ANDROID && !UNITY_EDITOR
- CurrentActivity.Call("GetaudioPeer");
- #endif
- break;
- }
- }
- }
- }
|