LangChaoRTC.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using LitJson;
  2. using rtc;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XRTool.Util;
  8. public class LangChaoRTC : MonoSingleton<LangChaoRTC>
  9. {
  10. //自己账号
  11. zhanghao my = new zhanghao();
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. Debug.Log("HJJLANGCHAORTC 开始登录");
  16. // StartCoroutine(init(0));
  17. }
  18. public void showRTC(int index)
  19. {
  20. StartCoroutine(init(index));
  21. }
  22. public IEnumerator init(int index)
  23. {
  24. yield return new WaitForSeconds(1f);
  25. //登录
  26. List<zhanghao> zh = new List<zhanghao>();
  27. zhanghao zh1 = new zhanghao();
  28. #if UNITY_EDITOR
  29. zh1.zh = "test05";
  30. zh1.mm = "123456Aa";
  31. zhanghao zh2 = new zhanghao();
  32. zh2.zh = "test06";
  33. zh2.mm = "123456Aa";
  34. zh.Add(zh1);
  35. zh.Add(zh2);
  36. my.zh = "test07";
  37. my.mm = "123456Aa";
  38. #else
  39. zh1.zh = "test02";
  40. zh1.mm = "123456Aa";
  41. zhanghao zh2 = new zhanghao();
  42. zh2.zh = "test03";
  43. zh2.mm = "123456Aa";
  44. zh.Add(zh1);
  45. zh.Add(zh2);
  46. my.zh = "test01";
  47. my.mm = "123456Aa";
  48. #endif
  49. if (UserInfo.User_Token!="")
  50. {
  51. OnCreateRoom();
  52. }
  53. else
  54. {
  55. NetWorkHeaders.YuLogin(my.zh, my.mm, YuLoginOk, LoginFail);
  56. }
  57. yield return null;
  58. }
  59. private void LoginFail(string obj)
  60. {
  61. }
  62. private void YuLoginOk(JsonData js)
  63. {
  64. if (js["code"].ToString() == "200")
  65. {
  66. Debug.Log("HJJLANGCHAORTC 登录成功登录");
  67. NetWorkHeaders.Login(my.zh, my.mm, LoginOk, LoginFail);
  68. }
  69. }
  70. private void LoginOk(JsonData js)
  71. {
  72. Debug.Log("HJJLANGCHAORTC yu登录成功");
  73. LoginInitRTC.Instance.InitRTC();
  74. UserInfo.isSN = false;
  75. UserInfo.UnionId = js["data"]["unionId"].ToString();
  76. UserInfo.User_Token = js["data"]["token"].ToString();
  77. UserInfo.Account = my.zh;
  78. UserInfo.PassWord = my.mm;
  79. NetWorkHeaders.GetUserInfo((JsonData sData) => {
  80. Debug.Log("HJJLANGCHAORTC 获取用户信息");
  81. UserInfo.phone = sData["data"]["phone"].ToString();
  82. UserInfo.userName = sData["data"]["nickName"].ToString();
  83. if (UserInfo.userName == "")
  84. {
  85. UserInfo.userName = my.zh;
  86. //UserInfo.userName = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length - 4);
  87. }
  88. UserInfo.activateType = int.Parse(sData["data"]["activateType"].ToString());
  89. UserInfo.indate = double.Parse(sData["data"]["indate"].ToString());
  90. CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString());
  91. CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString());
  92. CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString());
  93. switch (CustomInfo.camIndex - 1)
  94. {
  95. case 0:
  96. CustomInfo.mWidth = 1920;
  97. CustomInfo.mHight = 1080;
  98. break;
  99. case 1:
  100. CustomInfo.mWidth = 1280;
  101. CustomInfo.mHight = 720;
  102. break;
  103. case 2:
  104. CustomInfo.mWidth = 640;
  105. CustomInfo.mHight = 360;
  106. break;
  107. }
  108. CustomInfo.mWidth = 1920;
  109. CustomInfo.mHight = 1080;
  110. NetWorkHeaders.GetUserAvater((JsonData aData) =>
  111. {
  112. NetWorkHeaders.Instance.getNetTexture(aData["data"]["user"][0].ToString(), null, (Texture tex) => {
  113. UserInfo.defaulttextIcon = tex;
  114. });
  115. UserInfo.defaultavatar = aData["data"]["user"][0].ToString();
  116. });
  117. if (sData["data"]["avatar"].ToString() == "")
  118. {
  119. UserInfo.textIcon = UserInfo.defaulttextIcon;
  120. UserInfo.avatar = UserInfo.defaultavatar;
  121. NetWorkHeaders.SetUserInfo();
  122. }
  123. else
  124. {
  125. UserInfo.avatar = sData["data"]["avatar"].ToString();
  126. NetWorkHeaders.Instance.getNetTexture(sData["data"]["avatar"].ToString(), null, (Texture tex) => {
  127. UserInfo.textIcon = tex;
  128. });
  129. }
  130. WSHandler.Office.OnInit -= Init;
  131. WSHandler.Office.OnInit += Init;
  132. WSHandler.init();
  133. }, (string failStr) => {
  134. });
  135. }
  136. private void Init(JsonData data)
  137. {
  138. WSHandler.Office.OnInit -= Init;
  139. OnCreateRoom();
  140. }
  141. public List<InviteUserConfig> InvitingUnionIdList = new List<InviteUserConfig>();//已经邀请了还没同意或者拒绝
  142. public List<InviteUserConfig> InviteUnionIdList = new List<InviteUserConfig>();//选择还未被邀请
  143. private void InviteUsers(JsonData data)
  144. {
  145. if (data["data"]["code"].ToString() == "200")
  146. {
  147. for (int i = 0; i < InviteUnionIdList.Count; i++)
  148. {
  149. InvitingUnionIdList.Add(InviteUnionIdList[i]);
  150. }
  151. InviteUnionIdList.Clear();
  152. RoomOtherUser.Instance.UpdateList();
  153. }
  154. }
  155. public void HideHistory()
  156. {
  157. }
  158. private List<InviteUserConfig> inviteUserConfigList = new List<InviteUserConfig>();
  159. private void UserSearch(JsonData data)
  160. {
  161. Debug.Log("11111111111111111111111 "+data.ToJson());
  162. switch (data["data"]["code"].ToString())
  163. {
  164. case "200":
  165. HideHistory();
  166. if (inviteUserConfigList.Count > 0)
  167. {
  168. inviteUserConfigList.Clear();
  169. }
  170. if (data["data"]["data"].Count > 0)
  171. {
  172. for (int i = 0; i < data["data"]["data"].Count; i++)
  173. {
  174. if(data["data"]["data"][i]["online"].ToString() == "1")
  175. {
  176. InviteUserConfig inviteUserConfig = new InviteUserConfig(data["data"]["data"][i]["unionId"].ToString(), data["data"]["data"][i]["phone"].ToString(), data["data"]["data"][i]["avatar"].ToString(), data["data"]["data"][i]["nickName"].ToString(), data["data"]["data"][i]["online"].ToString());
  177. inviteUserConfigList.Add(inviteUserConfig);
  178. Debug.Log("11111111111111111 邀请中" + inviteUserConfig.UnionId);
  179. }
  180. }
  181. TimerMgr.Instance.CreateTimer(()=> {
  182. if(inviteUserConfigList.Count>0)
  183. {
  184. WSHandler.Office.InviteUsers(RoomMainInfo.roomNum, inviteUserConfigList);
  185. inviteUserConfigList.Clear();
  186. }
  187. },1);
  188. WSHandler.Office.OnUserSearch -= UserSearch;
  189. WSHandler.Office.OnInviteUsers -= InviteUsers;
  190. }
  191. else
  192. {
  193. }
  194. break;
  195. case "5001":
  196. HideHistory();
  197. break;
  198. default:
  199. break;
  200. }
  201. }
  202. public void OnCreateRoom()
  203. {
  204. WSHandler.Office.OnGetRoomIdReveived -= getRoomId;
  205. WSHandler.Office.OnGetRoomIdReveived += getRoomId;
  206. WSHandler.Office.GetRoomID();
  207. }
  208. private void getRoomId(JsonData data)
  209. {
  210. //Debug.Log("");
  211. //Debug.Log(JsonConvert.SerializeObject(data));
  212. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  213. RoomMainInfo.CreateRoom();
  214. RoomMainInfo.roomNum = data["data"]["roomId"].ToString();
  215. WSHandler.roomRtcinit(RoomMainInfo.roomNum);
  216. WSHandler.Office.OnGetRoomIdReveived -= getRoomId;
  217. WSHandler.Office.OnUserSearch -= UserSearch;
  218. WSHandler.Office.OnInviteUsers -= InviteUsers;
  219. WSHandler.Office.OnUserSearch += UserSearch;
  220. WSHandler.Office.OnInviteUsers += InviteUsers;
  221. WSHandler.Office.UserSearch("test02");
  222. }
  223. public void OnJoinRoom(string roomId)
  224. {
  225. Debug.Log("RoomMainInfo.roomNum......" + RoomMainInfo.roomNum);
  226. RoomMainInfo.roomNum = roomId;
  227. WSHandler.Office.OnJoinRoomReveived -= joinRoom;
  228. WSHandler.Office.OnJoinRoomReveived += joinRoom;
  229. WSHandler.Office.JoinRoom(roomId);
  230. //AgoraVideoAudioManager.Instance.SetChinnelName(roomId);
  231. }
  232. private void joinRoom(JsonData data)
  233. {
  234. switch (data["data"]["code"].ToString())
  235. {
  236. case "200":
  237. RoomMainInfo.CreateRoom();
  238. //Debug.Log("RoomMainInfo.roomNum"+ RoomMainInfo.roomNum);
  239. WSHandler.roomRtcinit(RoomMainInfo.roomNum);
  240. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  241. break;
  242. case "1000":
  243. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间号无效");
  244. SetClick();
  245. break;
  246. case "1001":
  247. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, "房间人数已满", "知道了", GameStart.actionok);
  248. SetClick();
  249. break;
  250. case "1003":
  251. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在");
  252. SetClick();
  253. break;
  254. default:
  255. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在");
  256. SetClick();
  257. break;
  258. }
  259. WSHandler.Office.OnJoinRoomReveived -= joinRoom;
  260. }
  261. public void SetClick()
  262. {
  263. if (JoinRoom.Instance)
  264. {
  265. JoinRoom.Instance.isClick = false;
  266. }
  267. }
  268. public class zhanghao
  269. {
  270. public string zh = "test01";
  271. public string mm = "123456Aa";
  272. }
  273. }