SCRtcAndroidEngine.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using LitJson;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SCRtcAndroidEngine : SCRtcEngine
  5. {
  6. public void setProduce(string msg)
  7. {
  8. #if UNITY_ANDROID && !UNITY_EDITOR
  9. CurrentRtcActivity.Call("setProduce", msg);
  10. #endif
  11. }
  12. public string getwifi()
  13. {
  14. #if UNITY_ANDROID && !UNITY_EDITOR
  15. return CurrentRtcActivity.Call<string>("ObtainWifiInfo");
  16. #endif
  17. return "";
  18. }
  19. //调节他人音量
  20. public double GetaudioMe()
  21. {
  22. double d = 0.0f;
  23. #if UNITY_ANDROID && !UNITY_EDITOR
  24. d = CurrentRtcActivity.Call<double>("GetaudioMe");
  25. #endif
  26. return d;
  27. }
  28. //调节他人音量
  29. public double GetaudioPeer(string consumerId)
  30. {
  31. double d = 0.0f;
  32. #if UNITY_ANDROID && !UNITY_EDITOR
  33. d = CurrentRtcActivity.Call<double>("GetaudioPeer", consumerId);
  34. #endif
  35. return d;
  36. }
  37. SDKCallbackListener sdk;
  38. //增加监听
  39. public void addListener()
  40. {
  41. if (sdk == null)
  42. {
  43. sdk = new SDKCallbackListener();
  44. #if UNITY_ANDROID&& !UNITY_EDITOR
  45. CurrentRtcActivity.Call("initSDK", sdk);
  46. #endif
  47. }
  48. }
  49. override public void send(Queue<JsonData> jsondata)
  50. {
  51. JsonData data;
  52. if (jsondata.Count > 0)
  53. {
  54. data = jsondata.Dequeue();
  55. switch (data["action"].ToString())
  56. {
  57. case "InitRTC":
  58. #if UNITY_ANDROID && !UNITY_EDITOR
  59. addListener();
  60. CurrentRtcActivity.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()),false);
  61. CurrentRtcActivity.Call("InitSocket", data["data"]["Url"].ToString());
  62. #endif
  63. break;
  64. case "changeVideo":
  65. #if UNITY_ANDROID && !UNITY_EDITOR
  66. CurrentRtcActivity.Call("changeVideo",int.Parse(data["data"]["w"].ToString()),int.Parse(data["data"]["h"].ToString()),int.Parse(data["data"]["fps"].ToString()));
  67. #endif
  68. break;
  69. case "setMute":
  70. #if UNITY_ANDROID && !UNITY_EDITOR
  71. CurrentRtcActivity.Call("setMute",bool.Parse(data["data"]["boo"].ToString()));
  72. #endif
  73. break;
  74. case "sendVideo":
  75. #if UNITY_ANDROID && !UNITY_EDITOR
  76. CurrentRtcActivity.Call("sendVideo",bool.Parse(data["data"]["boo"].ToString()));
  77. #endif
  78. break;
  79. case "enableVideoOnly":
  80. #if UNITY_ANDROID && !UNITY_EDITOR
  81. CurrentRtcActivity.Call("enableVideoOnly",bool.Parse(data["data"]["boo"].ToString()));
  82. #endif
  83. break;
  84. case "enableAudioOnly":
  85. #if UNITY_ANDROID && !UNITY_EDITOR
  86. CurrentRtcActivity.Call("enableAudioOnly",bool.Parse(data["data"]["boo"].ToString()));
  87. #endif
  88. break;
  89. case "openSpeaker":
  90. #if UNITY_ANDROID && !UNITY_EDITOR
  91. CurrentRtcActivity.Call("openSpeaker",bool.Parse(data["data"]["boo"].ToString()));
  92. #endif
  93. break;
  94. case "closeSpeaker":
  95. #if UNITY_ANDROID && !UNITY_EDITOR
  96. CurrentRtcActivity.Call("closeSpeaker",bool.Parse(data["data"]["boo"].ToString()));
  97. #endif
  98. break;
  99. case "setVolume":
  100. #if UNITY_ANDROID && !UNITY_EDITOR
  101. CurrentRtcActivity.Call("setVolume",int.Parse(data["data"]["i"].ToString()));
  102. #endif
  103. break;
  104. case "sendMic":
  105. #if UNITY_ANDROID && !UNITY_EDITOR
  106. CurrentRtcActivity.Call("sendMic",bool.Parse(data["data"]["boo"].ToString()));
  107. #endif
  108. break;
  109. case "openRev":
  110. #if UNITY_ANDROID && !UNITY_EDITOR
  111. CurrentRtcActivity.Call("openRev",data["data"]["consumerId"].ToString());
  112. #endif
  113. break;
  114. case "closeRev":
  115. #if UNITY_ANDROID && !UNITY_EDITOR
  116. CurrentRtcActivity.Call("closeRev",data["data"]["consumerId"].ToString());
  117. #endif
  118. break;
  119. case "Close":
  120. #if UNITY_ANDROID && !UNITY_EDITOR
  121. CurrentRtcActivity.Call("close");
  122. #endif
  123. SCRtcFactory.Instance.isClose = true;
  124. break;
  125. case "addTextureID":
  126. #if UNITY_ANDROID && !UNITY_EDITOR
  127. CurrentRtcActivity.Call("addTextureID", data["data"]["peerId"].ToString(), int.Parse(data["data"]["textureID"].ToString()));
  128. #endif
  129. break;
  130. case "audioPeerChange":
  131. #if UNITY_ANDROID && !UNITY_EDITOR
  132. CurrentRtcActivity.Call("audioPeerChange", data["data"]["consumerId"].ToString(), double.Parse(data["data"]["d"].ToString()));
  133. #endif
  134. break;
  135. case "audioMeChange":
  136. #if UNITY_ANDROID && !UNITY_EDITOR
  137. CurrentRtcActivity.Call("audioMeChange", double.Parse(data["data"]["d"].ToString()));
  138. #endif
  139. break;
  140. case "changePeerVideo":
  141. #if UNITY_ANDROID && !UNITY_EDITOR
  142. CurrentRtcActivity.Call("changePeerVideo", data["data"]["consumerId"].ToString(), int.Parse(data["data"]["fps"].ToString()));
  143. #endif
  144. break;
  145. case "changeName":
  146. #if UNITY_ANDROID && !UNITY_EDITOR
  147. CurrentRtcActivity.Call("changeName", data["data"]["name"].ToString());
  148. #endif
  149. break;
  150. case "joinRoom":
  151. #if UNITY_ANDROID && !UNITY_EDITOR
  152. CurrentRtcActivity.Call("joinRoom", data["data"]["req"].ToString());
  153. #endif
  154. break;
  155. case "GetaudioMe":
  156. #if UNITY_ANDROID && !UNITY_EDITOR
  157. CurrentRtcActivity.Call("GetaudioMe");
  158. #endif
  159. break;
  160. case "GetaudioPeer":
  161. #if UNITY_ANDROID && !UNITY_EDITOR
  162. CurrentRtcActivity.Call("GetaudioPeer");
  163. #endif
  164. break;
  165. case "onSocketMesseage":
  166. #if UNITY_ANDROID && !UNITY_EDITOR
  167. CurrentRtcActivity.Call("onSocketMesseage", data["data"].ToString());
  168. #endif
  169. break;
  170. case "initRtpCapabilities":
  171. #if UNITY_ANDROID && !UNITY_EDITOR
  172. CurrentRtcActivity.Call("initRtpCapabilities", data["data"].ToString());
  173. #endif
  174. break;
  175. case "createRecvTransport":
  176. #if UNITY_ANDROID && !UNITY_EDITOR
  177. CurrentRtcActivity.Call("createRecvTransport", data["data"].ToString());
  178. #endif
  179. break;
  180. case "createSendTransport":
  181. #if UNITY_ANDROID && !UNITY_EDITOR
  182. CurrentRtcActivity.Call("createSendTransport", data["data"].ToString());
  183. #endif
  184. break;
  185. case "onNewConsumer":
  186. #if UNITY_ANDROID && !UNITY_EDITOR
  187. CurrentRtcActivity.Call("onNewConsumer", data["data"].ToString(), data["id"].ToString());
  188. #endif
  189. break;
  190. case "getDevice":
  191. #if UNITY_ANDROID && !UNITY_EDITOR
  192. CurrentRtcActivity.Call("getDevice");
  193. #endif
  194. break;
  195. case "setProduce":
  196. #if UNITY_ANDROID && !UNITY_EDITOR
  197. CurrentRtcActivity.Call("setProduce", data["data"].ToString());
  198. #endif
  199. break;
  200. case "startCamera":
  201. #if UNITY_ANDROID && !UNITY_EDITOR
  202. CurrentRtcActivity.Call("startCamera");
  203. #endif
  204. break;
  205. case "stopCamera":
  206. #if UNITY_ANDROID && !UNITY_EDITOR
  207. CurrentRtcActivity.Call("stopCamera");
  208. #endif
  209. break;
  210. case "addCameraLocal":
  211. #if UNITY_ANDROID && !UNITY_EDITOR
  212. CurrentRtcActivity.Call("addCameraLocal", int.Parse(data["L"].ToString()));
  213. #endif
  214. break;
  215. }
  216. }
  217. }
  218. }