123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 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);
- }
- }
- }
|