using LitJson; using rtc; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; public class LangChaoRTC : MonoSingleton { //自己账号 zhanghao my = new zhanghao(); // Start is called before the first frame update void Start() { Debug.Log("HJJLANGCHAORTC 开始登录"); // StartCoroutine(init(0)); } public void showRTC(int index) { StartCoroutine(init(index)); } public IEnumerator init(int index) { yield return new WaitForSeconds(1f); //登录 List zh = new List(); zhanghao zh1 = new zhanghao(); #if UNITY_EDITOR zh1.zh = "test05"; zh1.mm = "123456Aa"; zhanghao zh2 = new zhanghao(); zh2.zh = "test06"; zh2.mm = "123456Aa"; zh.Add(zh1); zh.Add(zh2); my.zh = "test07"; my.mm = "123456Aa"; #else zh1.zh = "test02"; zh1.mm = "123456Aa"; zhanghao zh2 = new zhanghao(); zh2.zh = "test03"; zh2.mm = "123456Aa"; zh.Add(zh1); zh.Add(zh2); my.zh = "test01"; my.mm = "123456Aa"; #endif if (UserInfo.User_Token!="") { OnCreateRoom(); } else { NetWorkHeaders.YuLogin(my.zh, my.mm, YuLoginOk, LoginFail); } yield return null; } private void LoginFail(string obj) { } private void YuLoginOk(JsonData js) { if (js["code"].ToString() == "200") { Debug.Log("HJJLANGCHAORTC 登录成功登录"); NetWorkHeaders.Login(my.zh, my.mm, LoginOk, LoginFail); } } private void LoginOk(JsonData js) { Debug.Log("HJJLANGCHAORTC yu登录成功"); LoginInitRTC.Instance.InitRTC(); UserInfo.isSN = false; UserInfo.UnionId = js["data"]["unionId"].ToString(); UserInfo.User_Token = js["data"]["token"].ToString(); UserInfo.Account = my.zh; UserInfo.PassWord = my.mm; NetWorkHeaders.GetUserInfo((JsonData sData) => { Debug.Log("HJJLANGCHAORTC 获取用户信息"); UserInfo.phone = sData["data"]["phone"].ToString(); UserInfo.userName = sData["data"]["nickName"].ToString(); if (UserInfo.userName == "") { UserInfo.userName = my.zh; //UserInfo.userName = "YCKJ" + UserInfo.Account.Substring(UserInfo.Account.Length - 4); } UserInfo.activateType = int.Parse(sData["data"]["activateType"].ToString()); UserInfo.indate = double.Parse(sData["data"]["indate"].ToString()); CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString()); CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString()); CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString()); switch (CustomInfo.camIndex - 1) { case 0: CustomInfo.mWidth = 1920; CustomInfo.mHight = 1080; break; case 1: CustomInfo.mWidth = 1280; CustomInfo.mHight = 720; break; case 2: CustomInfo.mWidth = 640; CustomInfo.mHight = 360; break; } CustomInfo.mWidth = 1920; CustomInfo.mHight = 1080; NetWorkHeaders.GetUserAvater((JsonData aData) => { NetWorkHeaders.Instance.getNetTexture(aData["data"]["user"][0].ToString(), null, (Texture tex) => { UserInfo.defaulttextIcon = tex; }); UserInfo.defaultavatar = aData["data"]["user"][0].ToString(); }); if (sData["data"]["avatar"].ToString() == "") { UserInfo.textIcon = UserInfo.defaulttextIcon; UserInfo.avatar = UserInfo.defaultavatar; NetWorkHeaders.SetUserInfo(); } else { UserInfo.avatar = sData["data"]["avatar"].ToString(); NetWorkHeaders.Instance.getNetTexture(sData["data"]["avatar"].ToString(), null, (Texture tex) => { UserInfo.textIcon = tex; }); } WSHandler.Office.OnInit -= Init; WSHandler.Office.OnInit += Init; WSHandler.init(); }, (string failStr) => { }); } private void Init(JsonData data) { WSHandler.Office.OnInit -= Init; OnCreateRoom(); } public List InvitingUnionIdList = new List();//已经邀请了还没同意或者拒绝 public List InviteUnionIdList = new List();//选择还未被邀请 private void InviteUsers(JsonData data) { if (data["data"]["code"].ToString() == "200") { for (int i = 0; i < InviteUnionIdList.Count; i++) { InvitingUnionIdList.Add(InviteUnionIdList[i]); } InviteUnionIdList.Clear(); RoomOtherUser.Instance.UpdateList(); } } public void HideHistory() { } private List inviteUserConfigList = new List(); private void UserSearch(JsonData data) { Debug.Log("11111111111111111111111 "+data.ToJson()); switch (data["data"]["code"].ToString()) { case "200": HideHistory(); if (inviteUserConfigList.Count > 0) { inviteUserConfigList.Clear(); } if (data["data"]["data"].Count > 0) { for (int i = 0; i < data["data"]["data"].Count; i++) { if(data["data"]["data"][i]["online"].ToString() == "1") { 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()); inviteUserConfigList.Add(inviteUserConfig); Debug.Log("11111111111111111 邀请中" + inviteUserConfig.UnionId); } } TimerMgr.Instance.CreateTimer(()=> { if(inviteUserConfigList.Count>0) { WSHandler.Office.InviteUsers(RoomMainInfo.roomNum, inviteUserConfigList); inviteUserConfigList.Clear(); } },1); WSHandler.Office.OnUserSearch -= UserSearch; WSHandler.Office.OnInviteUsers -= InviteUsers; } else { } break; case "5001": HideHistory(); break; default: break; } } public void OnCreateRoom() { WSHandler.Office.OnGetRoomIdReveived -= getRoomId; WSHandler.Office.OnGetRoomIdReveived += getRoomId; WSHandler.Office.GetRoomID(); } private void getRoomId(JsonData data) { //Debug.Log(""); //Debug.Log(JsonConvert.SerializeObject(data)); WSHandler.Office.ChangeUserType(UserInfo.BusyType); RoomMainInfo.CreateRoom(); RoomMainInfo.roomNum = data["data"]["roomId"].ToString(); WSHandler.roomRtcinit(RoomMainInfo.roomNum); WSHandler.Office.OnGetRoomIdReveived -= getRoomId; WSHandler.Office.OnUserSearch -= UserSearch; WSHandler.Office.OnInviteUsers -= InviteUsers; WSHandler.Office.OnUserSearch += UserSearch; WSHandler.Office.OnInviteUsers += InviteUsers; WSHandler.Office.UserSearch("test02"); } public void OnJoinRoom(string roomId) { Debug.Log("RoomMainInfo.roomNum......" + RoomMainInfo.roomNum); RoomMainInfo.roomNum = roomId; WSHandler.Office.OnJoinRoomReveived -= joinRoom; WSHandler.Office.OnJoinRoomReveived += joinRoom; WSHandler.Office.JoinRoom(roomId); //AgoraVideoAudioManager.Instance.SetChinnelName(roomId); } private void joinRoom(JsonData data) { switch (data["data"]["code"].ToString()) { case "200": RoomMainInfo.CreateRoom(); //Debug.Log("RoomMainInfo.roomNum"+ RoomMainInfo.roomNum); WSHandler.roomRtcinit(RoomMainInfo.roomNum); WSHandler.Office.ChangeUserType(UserInfo.BusyType); break; case "1000": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间号无效"); SetClick(); break; case "1001": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, "房间人数已满", "知道了", GameStart.actionok); SetClick(); break; case "1003": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在"); SetClick(); break; default: PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在"); SetClick(); break; } WSHandler.Office.OnJoinRoomReveived -= joinRoom; } public void SetClick() { //if (JoinRoom.Instance) //{ // JoinRoom.Instance.isClick = false; //} } public class zhanghao { public string zh = "test01"; public string mm = "123456Aa"; } }