SCRtcAndroidEngine.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using LitJson;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SCRtcAndroidEngine : SCRtcEngine
  5. {
  6. //调节他人音量
  7. public double GetaudioMe()
  8. {
  9. double d = 0.0f;
  10. #if UNITY_ANDROID && !UNITY_EDITOR
  11. d = CurrentActivity.Call<double>("GetaudioMe");
  12. #endif
  13. return d;
  14. }
  15. //调节他人音量
  16. public double GetaudioPeer(string consumerId)
  17. {
  18. double d = 0.0f;
  19. #if UNITY_ANDROID && !UNITY_EDITOR
  20. d = CurrentActivity.Call<double>("GetaudioPeer", consumerId);
  21. #endif
  22. return d;
  23. }
  24. SDKCallbackListener sdk;
  25. //增加监听
  26. public void addListener()
  27. {
  28. if (sdk == null)
  29. {
  30. sdk = new SDKCallbackListener();
  31. UnityEngine.Debug.Log("addListener");
  32. #if UNITY_ANDROID&& !UNITY_EDITOR
  33. CurrentActivity.Call("initSDK", sdk);
  34. #endif
  35. Debug.Log("addListenerEND"); ;
  36. }
  37. }
  38. override public void send(Queue<JsonData> jsondata)
  39. {
  40. JsonData data;
  41. if (jsondata.Count > 0)
  42. {
  43. Debug.Log("close22222333");
  44. data = jsondata.Dequeue();
  45. Debug.Log("close22222" + data["action"].ToString());
  46. switch (data["action"].ToString())
  47. {
  48. case "InitRTC":
  49. #if UNITY_ANDROID && !UNITY_EDITOR
  50. addListener();
  51. 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()));
  52. CurrentActivity.Call("InitSocket", data["data"]["Url"].ToString(), int.Parse(data["data"]["Post"].ToString()));
  53. #endif
  54. break;
  55. case "changeVideo":
  56. #if UNITY_ANDROID && !UNITY_EDITOR
  57. CurrentActivity.Call("changeVideo",int.Parse(data["data"]["w"].ToString()),int.Parse(data["data"]["h"].ToString()),int.Parse(data["data"]["fps"].ToString()));
  58. #endif
  59. break;
  60. case "setMute":
  61. #if UNITY_ANDROID && !UNITY_EDITOR
  62. CurrentActivity.Call("setMute",bool.Parse(data["data"]["boo"].ToString()));
  63. #endif
  64. break;
  65. case "sendVideo":
  66. #if UNITY_ANDROID && !UNITY_EDITOR
  67. CurrentActivity.Call("sendVideo",bool.Parse(data["data"]["boo"].ToString()));
  68. #endif
  69. break;
  70. case "enableVideoOnly":
  71. #if UNITY_ANDROID && !UNITY_EDITOR
  72. CurrentActivity.Call("enableVideoOnly",bool.Parse(data["data"]["boo"].ToString()));
  73. #endif
  74. break;
  75. case "enableAudioOnly":
  76. #if UNITY_ANDROID && !UNITY_EDITOR
  77. CurrentActivity.Call("enableAudioOnly",bool.Parse(data["data"]["boo"].ToString()));
  78. #endif
  79. break;
  80. case "openSpeaker":
  81. #if UNITY_ANDROID && !UNITY_EDITOR
  82. CurrentActivity.Call("openSpeaker",bool.Parse(data["data"]["boo"].ToString()));
  83. #endif
  84. break;
  85. case "closeSpeaker":
  86. #if UNITY_ANDROID && !UNITY_EDITOR
  87. CurrentActivity.Call("closeSpeaker",bool.Parse(data["data"]["boo"].ToString()));
  88. #endif
  89. break;
  90. case "setVolume":
  91. #if UNITY_ANDROID && !UNITY_EDITOR
  92. CurrentActivity.Call("setVolume",int.Parse(data["data"]["i"].ToString()));
  93. #endif
  94. break;
  95. case "sendMic":
  96. #if UNITY_ANDROID && !UNITY_EDITOR
  97. CurrentActivity.Call("sendMic",bool.Parse(data["data"]["boo"].ToString()));
  98. #endif
  99. break;
  100. case "openRev":
  101. #if UNITY_ANDROID && !UNITY_EDITOR
  102. CurrentActivity.Call("openRev",data["data"]["consumerId"].ToString());
  103. #endif
  104. break;
  105. case "closeRev":
  106. #if UNITY_ANDROID && !UNITY_EDITOR
  107. CurrentActivity.Call("closeRev",data["data"]["consumerId"].ToString());
  108. #endif
  109. break;
  110. case "Close":
  111. Debug.Log("退出房间Start");
  112. #if UNITY_ANDROID && !UNITY_EDITOR
  113. CurrentActivity.Call("close");
  114. #endif
  115. Debug.Log("退出房间End");
  116. SCRtcFactory.Instance.isClose = true;
  117. break;
  118. case "addTextureID":
  119. #if UNITY_ANDROID && !UNITY_EDITOR
  120. CurrentActivity.Call("addTextureID", data["data"]["peerId"].ToString(), int.Parse(data["data"]["textureID"].ToString()));
  121. #endif
  122. break;
  123. case "audioPeerChange":
  124. #if UNITY_ANDROID && !UNITY_EDITOR
  125. CurrentActivity.Call("audioPeerChange", data["data"]["consumerId"].ToString(), double.Parse(data["data"]["d"].ToString()));
  126. #endif
  127. break;
  128. case "audioMeChange":
  129. #if UNITY_ANDROID && !UNITY_EDITOR
  130. CurrentActivity.Call("audioMeChange", double.Parse(data["data"]["d"].ToString()));
  131. #endif
  132. break;
  133. case "changePeerVideo":
  134. #if UNITY_ANDROID && !UNITY_EDITOR
  135. CurrentActivity.Call("changePeerVideo", data["data"]["consumerId"].ToString(), int.Parse(data["data"]["fps"].ToString()));
  136. #endif
  137. break;
  138. case "changeName":
  139. #if UNITY_ANDROID && !UNITY_EDITOR
  140. CurrentActivity.Call("changeName", data["data"]["name"].ToString());
  141. #endif
  142. break;
  143. case "joinRoom":
  144. #if UNITY_ANDROID && !UNITY_EDITOR
  145. CurrentActivity.Call("joinRoom", data["data"]["req"].ToString());
  146. #endif
  147. break;
  148. case "GetaudioMe":
  149. #if UNITY_ANDROID && !UNITY_EDITOR
  150. CurrentActivity.Call("GetaudioMe");
  151. #endif
  152. break;
  153. case "GetaudioPeer":
  154. #if UNITY_ANDROID && !UNITY_EDITOR
  155. CurrentActivity.Call("GetaudioPeer");
  156. #endif
  157. break;
  158. }
  159. }
  160. }
  161. }