using LitJson; using System.Collections; using UnityEngine; class SDKCallbackListener : AndroidJavaProxy { // 这句话很重要!!!C#找到Jar中接口的引用 public SDKCallbackListener() : base("org.mediasoup.droid.demo.javaSDKCallbackListener") { } public Queue queue; public string data; //实现接口中的方法 public void OnSDKInited(string msg) { SCRtcHandle.Instance.isSendOk = true; Debug.Log("OnSDKInited:" + msg); // JsonData jd = JsonMapper.ToObject(msg); // VideoManager.queue.Add(jd); if (SCRtcFactory.Instance.mSCRtcManager!=null&&SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); data["action"] = "OnSDKInited"; data["method"] = "init"; data["data"] = msg; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } public void OnPeerFPS(string peerID) { // if (SCRtcFactory.Instance.mSCRtcPeers.ContainsKey(peerID)) // { //SCRtcFactory.Instance.mSCRtcPeers[peerID].FPS++; // } } public void OnSocket(string msg) { Debug.Log("OnSocket===>" + msg); JsonData data = JsonMapper.ToObject(msg); if (data.Keys.Contains("action")&& data["action"].ToString()== "onProduce") { WSHandler.Rtc.onProduce(data); } if (data.Keys.Contains("action") && data["action"].ToString() == "connectWebRtcTransport") { WSHandler.Rtc.connectWebRtcTransport(data); } if (data.Keys.Contains("action") && data["action"].ToString() == "getDevice") { WSHandler.Rtc.joinRoom(msg); } if (data.Keys.Contains("action") && data["action"].ToString() == "getMicID") { RemoteRtc.Instance.me.cIdA = data["data"].ToString(); } if (data.Keys.Contains("action") && data["action"].ToString() == "getVideoID") { RemoteRtc.Instance.me.cIdV = data["data"].ToString(); } // if (SCRtcFactory.Instance.mSCRtcPeers.ContainsKey(peerID)) // { //SCRtcFactory.Instance.mSCRtcPeers[peerID].FPS++; // } } public void OnSocketMeassage(string msg) { Debug.Log("OnSocketMeassage:" + msg); TClient.Instance.SocketSend(msg); // WebSocketClient.webSockets["castScreen"].Send(msg); // if (SCRtcFactory.Instance.mSCRtcManager.queue != null) // { // JsonData data = new JsonData(); // data["action"] = "OnSocketMeassage"; // data["data"] = msg; // SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); // } // Debug.Log("OnLogined:" + token); } public void OnListener(string token) { SCRtcHandle.Instance.isSendOk = true; Debug.Log("dddddd"+ token); data = token; if (SCRtcFactory.Instance.mSCRtcManager!=null&&SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); JsonData jd = JsonMapper.ToObject(token); data["action"] = "OnListener"; data["method"] = jd["action"]; data["data"] = jd; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } public void OnLoginOut() { } public void onDisconnected(string action, string token) { SCRtcHandle.Instance.isSendOk = true; if (SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); // JsonData jd = JsonMapper.ToObject(token); data["action"] = "onDisconnected"; data["method"] = action; data["data"] = token; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } public void onNotification(string action, string token) { SCRtcHandle.Instance.isSendOk = true; if (SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); JsonData jd = JsonMapper.ToObject(token); data["action"]= "onNotification"; data["method"] = action; data["data"] = jd; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } public void onRequest(string action, string token) { SCRtcHandle.Instance.isSendOk = true; if (SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); JsonData jd = JsonMapper.ToObject(token); data["action"] = "onRequest"; data["method"] = action; data["data"] = jd; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } public void onFail(string action, string token) { SCRtcHandle.Instance.isSendOk = true; if (SCRtcFactory.Instance.mSCRtcManager.queue != null) { JsonData data = new JsonData(); // JsonData jd = JsonMapper.ToObject(token); data["action"] = "onFail"; data["method"] = action; data["data"] = token; SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data); } } }