SDKCallBackListener.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using LitJson;
  2. using System.Collections;
  3. using UnityEngine;
  4. class SDKCallbackListener : AndroidJavaProxy
  5. {
  6. // 这句话很重要!!!C#找到Jar中接口的引用
  7. public SDKCallbackListener() : base("org.mediasoup.droid.demo.javaSDKCallbackListener") { }
  8. public Queue queue;
  9. public string data;
  10. //实现接口中的方法
  11. public void OnSDKInited(string msg)
  12. {
  13. SCRtcHandle.Instance.isSendOk = true;
  14. Debug.Log("OnSDKInited:" + msg);
  15. // JsonData jd = JsonMapper.ToObject(msg);
  16. // VideoManager.queue.Add(jd);
  17. if (SCRtcFactory.Instance.mSCRtcManager!=null&&SCRtcFactory.Instance.mSCRtcManager.queue != null)
  18. {
  19. JsonData data = new JsonData();
  20. data["action"] = "OnSDKInited";
  21. data["method"] = "init";
  22. data["data"] = msg;
  23. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  24. }
  25. }
  26. public void OnPeerFPS(string peerID)
  27. {
  28. // if (SCRtcFactory.Instance.mSCRtcPeers.ContainsKey(peerID))
  29. // {
  30. //SCRtcFactory.Instance.mSCRtcPeers[peerID].FPS++;
  31. // }
  32. }
  33. public void OnSocket(string msg)
  34. {
  35. Debug.Log("OnSocket===>" + msg);
  36. JsonData data = JsonMapper.ToObject(msg);
  37. if (data.Keys.Contains("action")&& data["action"].ToString()== "onProduce")
  38. {
  39. WSHandler.Rtc.onProduce(data);
  40. }
  41. if (data.Keys.Contains("action") && data["action"].ToString() == "connectWebRtcTransport")
  42. {
  43. WSHandler.Rtc.connectWebRtcTransport(data);
  44. }
  45. if (data.Keys.Contains("action") && data["action"].ToString() == "getDevice")
  46. {
  47. WSHandler.Rtc.joinRoom(msg);
  48. }
  49. if (data.Keys.Contains("action") && data["action"].ToString() == "getMicID")
  50. {
  51. RemoteRtc.Instance.me.cIdA = data["data"].ToString();
  52. }
  53. if (data.Keys.Contains("action") && data["action"].ToString() == "getVideoID")
  54. {
  55. RemoteRtc.Instance.me.cIdV = data["data"].ToString();
  56. }
  57. // if (SCRtcFactory.Instance.mSCRtcPeers.ContainsKey(peerID))
  58. // {
  59. //SCRtcFactory.Instance.mSCRtcPeers[peerID].FPS++;
  60. // }
  61. }
  62. public void OnSocketMeassage(string msg)
  63. {
  64. Debug.Log("OnSocketMeassage:" + msg);
  65. TClient.Instance.SocketSend(msg);
  66. // WebSocketClient.webSockets["castScreen"].Send(msg);
  67. // if (SCRtcFactory.Instance.mSCRtcManager.queue != null)
  68. // {
  69. // JsonData data = new JsonData();
  70. // data["action"] = "OnSocketMeassage";
  71. // data["data"] = msg;
  72. // SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  73. // }
  74. // Debug.Log("OnLogined:" + token);
  75. }
  76. public void OnListener(string token)
  77. {
  78. SCRtcHandle.Instance.isSendOk = true;
  79. Debug.Log("dddddd"+ token);
  80. data = token;
  81. if (SCRtcFactory.Instance.mSCRtcManager!=null&&SCRtcFactory.Instance.mSCRtcManager.queue != null)
  82. {
  83. JsonData data = new JsonData();
  84. JsonData jd = JsonMapper.ToObject(token);
  85. data["action"] = "OnListener";
  86. data["method"] = jd["action"];
  87. data["data"] = jd;
  88. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  89. }
  90. }
  91. public void OnLoginOut()
  92. {
  93. }
  94. public void onDisconnected(string action, string token)
  95. {
  96. SCRtcHandle.Instance.isSendOk = true;
  97. if (SCRtcFactory.Instance.mSCRtcManager.queue != null)
  98. {
  99. JsonData data = new JsonData();
  100. // JsonData jd = JsonMapper.ToObject(token);
  101. data["action"] = "onDisconnected";
  102. data["method"] = action;
  103. data["data"] = token;
  104. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  105. }
  106. }
  107. public void onNotification(string action, string token)
  108. {
  109. SCRtcHandle.Instance.isSendOk = true;
  110. if (SCRtcFactory.Instance.mSCRtcManager.queue != null)
  111. {
  112. JsonData data = new JsonData();
  113. JsonData jd = JsonMapper.ToObject(token);
  114. data["action"]= "onNotification";
  115. data["method"] = action;
  116. data["data"] = jd;
  117. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  118. }
  119. }
  120. public void onRequest(string action, string token)
  121. {
  122. SCRtcHandle.Instance.isSendOk = true;
  123. if (SCRtcFactory.Instance.mSCRtcManager.queue != null)
  124. {
  125. JsonData data = new JsonData();
  126. JsonData jd = JsonMapper.ToObject(token);
  127. data["action"] = "onRequest";
  128. data["method"] = action;
  129. data["data"] = jd;
  130. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  131. }
  132. }
  133. public void onFail(string action, string token)
  134. {
  135. SCRtcHandle.Instance.isSendOk = true;
  136. if (SCRtcFactory.Instance.mSCRtcManager.queue != null)
  137. {
  138. JsonData data = new JsonData();
  139. // JsonData jd = JsonMapper.ToObject(token);
  140. data["action"] = "onFail";
  141. data["method"] = action;
  142. data["data"] = token;
  143. SCRtcFactory.Instance.mSCRtcManager.queue.Enqueue(data);
  144. }
  145. }
  146. }