123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using LitJson;
- using XRTool.Util;
- using System;
- public class WSOfficeHandler{
- public delegate void OnInitDelegate(JsonData data);
- public delegate void OnSearchRoomDelegate(JsonData data);
- public delegate void OnGetSelfRoomListDelegate(JsonData data);
- public delegate void OnRoomChangeDelegate(JsonData data);
- public delegate void OnJionRoomDelegate(JsonData data);
- public delegate void OnGetRoomIdDelegate(JsonData data);
- public delegate void OnJoinRoomDelegate(JsonData data);
- public OnInitDelegate OnInit;
- public OnSearchRoomDelegate OnSearchRoom;
- public OnGetSelfRoomListDelegate OnGetSelfRoomList;
- public OnGetRoomIdDelegate OnGetRoomIdReveived;
- public OnJoinRoomDelegate OnJoinRoomReveived;
- public OnRoomChangeDelegate OnRoomChange;
- public event Action<JsonData> OnUserSearch;
- public event Action<JsonData> OnInviteUsers;
- public event Action<JsonData> OnRefuse;
- public event Action<JsonData> OnTimeout;
- public event Action<JsonData> OnInvitee;
- public event Action<JsonData> OnCallRecordsList;
- public event Action<JsonData> OnAcceptInviteSuccess;
- public event Action<JsonData> OnRefuseInviteSuccess;
- private Dictionary<string,string> idList = new Dictionary<string, string>();
- public void GetRoomID()
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "getRoomId";
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "获取房间号...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- public void GetRecordsList()
- {
- JsonData message = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "callRecordsList";
- WSHandler.SendMessage(message);
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- public void UserSearch(string search)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "userSearch";
- data["search"] = search;
- message["data"] = data;
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "搜索中...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- //邀请用户
- public void InviteUsers(string roomId, List<InviteUserConfig> unionIds)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "inviteUsers";
- data["roomId"] = roomId;
- data["users"] = new JsonData();
- for (int i = 0; i < unionIds.Count; i++)
- {
- if (!string.IsNullOrEmpty(unionIds[i].UnionId))
- {
- JsonData user = new JsonData();
- user["unionId"] = unionIds[i].UnionId;
- data["users"].Add(user);
- }
- }
- message["data"] = data;
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "邀请中...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- public void ChangeUserType(string type)
- {
- JsonData message = new JsonData();
- message["notification"] = true;
- message["method"] = type;
- WSHandler.SendMessage(message);
- }
- //接受邀请
- public void AcceptInvite()
- {
- JsonData message = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "invite:accept";
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "接受邀请...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- //拒绝邀请
- public void RefuseInvite()
- {
- JsonData message = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "invite:refuse";
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "拒绝邀请...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- public void JoinRoom(string roomId)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["request"] = true;
- message["id"] = UnityEngine.Random.Range(10000000, 99999999);
- message["method"] = "joinRoom";
- message["data"] = new JsonData();
- message["data"]["roomId"] = roomId;
- WSHandler.SendMessage(message);
- CommonMethod.ShowNetLoading(WSHandler._client.name, "检测房间号...");
- idList.Add(message["id"].ToString(), message["method"].ToString());
- }
- public void OnMessageReceived(JsonData data)
- {
- if (data.Keys.Contains("response"))
- {
- CommonMethod.HideNetLoading(WSHandler._client.name);
- }
- if (data.Keys.Contains("errorCode"))
- {
- CommonMethod.HideLoading();
- return;
- }
- if (data.Keys.Contains("method"))
- {
- switch (data["method"].ToString())
- {
- case "connect":
- InitReceived(data);
- break;
- case "repeat":
- //ShowLogin.Instance.loginType = LoginType.INIT;
- //ScenesManager.Instance.showWindow(SceneType.ShowLogin);
- //PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, RtcStrConfig.otherLogin,"返回登录");
- WSHandler.roomRtcCloes();
- WSHandler.clientClosed();
- break;
- case "invite:refuse":
- OnRefuse?.Invoke(data);
- break;
- case "invite:timeout":
- OnTimeout?.Invoke(data);
- break;
- case "invitee":
- OnInvitee?.Invoke(data);
- break;
- default:
- break;
- }
- }
- if (data.Keys.Contains("id"))
- {
- if (idList.ContainsKey(data["id"].ToString()))
- {
- switch (idList[data["id"].ToString()])
- {
- case "selfRoomList":
- GetSelfRoomListReveived(data);
- break;
- case "searchRoom":
- OnSearchRoomReveived(data);
- break;
- case "getRoomId":
- OnGetRoomIdReveived(data);
- break;
- case "joinRoom":
- OnJoinRoomReveived(data);
- break;
- case "userSearch":
- OnUserSearch?.Invoke(data);
- break;
- case "inviteUsers":
- OnInviteUsers?.Invoke(data);
- break;
- case "callRecordsList":
- OnCallRecordsList?.Invoke(data);
- break;
- case "invite:refuse":
- OnRefuseInviteSuccess?.Invoke(data);
- break;
- case "invite:accept":
- OnAcceptInviteSuccess?.Invoke(data);
- break;
- default:
- break;
- }
- idList.Remove(data["id"].ToString());
- }
- }
- }
- private void InitReceived(JsonData data)
- {
- if (OnInit != null)
- {
- OnInit(data);
- }
- }
- public void GetSelfRoomListReveived(JsonData data)
- {
- if (OnGetSelfRoomList != null)
- {
- OnGetSelfRoomList(data);
- }
- }
- public void OnSearchRoomReveived(JsonData data)
- {
- if (OnSearchRoom != null)
- {
- OnSearchRoom(data);
- }
- }
- }
|