123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- using LitJson;
- using rtc;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.Util;
- public class LangChaoRTC : MonoSingleton<LangChaoRTC>
- {
- //自己账号
- 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<zhanghao> zh = new List<zhanghao>();
- 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<InviteUserConfig> InvitingUnionIdList = new List<InviteUserConfig>();//已经邀请了还没同意或者拒绝
- public List<InviteUserConfig> InviteUnionIdList = new List<InviteUserConfig>();//选择还未被邀请
- 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<InviteUserConfig> inviteUserConfigList = new List<InviteUserConfig>();
- 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";
- }
- }
|