WSUserHandler.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LitJson;
  5. public class WSUserHandler {
  6. public delegate void OnLoginDelegate(JsonData data);
  7. public delegate void OnLogoutDelegate(JsonData data);
  8. public delegate void OnConnectedDelegate(JsonData data);
  9. public delegate void OnScreenshotDelegate(JsonData data);
  10. public OnLoginDelegate OnLogin;
  11. public OnLoginDelegate OnlogOut;
  12. public OnConnectedDelegate OnConnected;
  13. public OnScreenshotDelegate OnScreenshot;
  14. //token登录
  15. public void Login()
  16. {
  17. JsonData message = new JsonData ();
  18. JsonData data = new JsonData ();
  19. message["action"] = "10101";
  20. message["user_token"] = UserInfo.Token;
  21. message["app_id"] = UserInfo.AppID;
  22. // message ["data"] = data;
  23. Debug.Log("Login_token====>"+ UserInfo.Token);
  24. WSHandler.SendMessage (message);
  25. }
  26. //退出 立刻执行关闭链接操作
  27. public void LogOut()
  28. {
  29. JsonData message = new JsonData();
  30. JsonData data = new JsonData();
  31. message["action"] = "20100";
  32. message["user_token"] = UserInfo.User_Token;
  33. message["app_id"] = UserInfo.AppID;
  34. WSHandler.SendMessage(message);
  35. }
  36. //添加联系人 rtc_id 通讯录列表的用户id postscript 备注信息 notice_status 通知状态
  37. public void AddUser(string rtc_id, string msg, string notice_status="")
  38. {
  39. JsonData message = new JsonData();
  40. JsonData data = new JsonData();
  41. message["action"] = "20201";
  42. message["user_token"] = UserInfo.User_Token;
  43. message["app_id"] = UserInfo.AppID;
  44. message["rtc_id"] = rtc_id;
  45. message["postscript"] = msg;
  46. WSHandler.SendMessage(message);
  47. }
  48. //添加通知 notice_type 通知类型1:通话记录通知 2:联系人通知 3:文件通知 document 分享文件 (当通知类型为3必传)
  49. //receive_uid 通知接收用户id notice_status 通知状态1:未处理 2:已读未处理 3:已读已处理
  50. //call_duration 通话时长,单位:秒 postscript 备注信息(当通知类型为2,可传可不传)
  51. public void AddNotice(string notice_type,string receive_uid,string call_duration, string notice_status="", string postscript="", string document="")
  52. {
  53. JsonData message = new JsonData();
  54. JsonData data = new JsonData();
  55. message["action"] = "20301";
  56. message["user_token"] = UserInfo.User_Token;
  57. message["app_id"] = UserInfo.AppID;
  58. message["notice_type"] = notice_type;
  59. message["receive_uid"] = receive_uid;
  60. message["call_duration"] = call_duration;
  61. message["notice_status"] = notice_status;
  62. message["postscript"] = postscript;
  63. message["document"] = document;
  64. WSHandler.SendMessage(message);
  65. }
  66. //回执通知 notice_id 消息id operation 好友请求操作状态 1:同意 2:拒绝
  67. public void ReceivedUser(string notice_id, string operation)
  68. {
  69. JsonData message = new JsonData();
  70. JsonData data = new JsonData();
  71. message["action"] = "20302";
  72. message["user_token"] = UserInfo.User_Token;
  73. message["app_id"] = UserInfo.AppID;
  74. message["notice_id"] = notice_id;
  75. message["operation"] = operation;
  76. WSHandler.SendMessage(message);
  77. }
  78. //创建通话 log_type通话记录类型 1 电话 2视频
  79. public void CreateChat(string log_type)
  80. {
  81. JsonData message = new JsonData();
  82. JsonData data = new JsonData();
  83. message["action"] = "20413";
  84. message["user_token"] = UserInfo.User_Token;
  85. message["app_id"] = UserInfo.AppID;
  86. message["log_type"] = log_type;
  87. WSHandler.SendMessage(message);
  88. }
  89. //邀请通话 log_type通话记录类型 1 电话 2视频 rtc_id 通讯录列表的用户id room_num 房间号
  90. public void InviteChat(string log_type, string rtc_id, string room_num)
  91. {
  92. JsonData message = new JsonData();
  93. JsonData data = new JsonData();
  94. message["action"] = "20414";
  95. message["user_token"] = UserInfo.User_Token;
  96. message["app_id"] = UserInfo.AppID;
  97. message["log_type"] = log_type;
  98. message["rtc_id"] = rtc_id;
  99. message["room_num"] = room_num;
  100. WSHandler.SendMessage(message);
  101. }
  102. //创建并且邀请通话 log_type通话记录类型 1 电话 2视频 rtc_id 通讯录列表的用户id call_type 通话记录类型 //0查询列表时传参 全部通话记录 1:呼出 2:呼入 3:未接
  103. public void CreateAndInviteChat(string log_type, string rtc_id, string call_type)
  104. {
  105. JsonData message = new JsonData();
  106. JsonData data = new JsonData();
  107. message["action"] = "20415";
  108. message["user_token"] = UserInfo.User_Token;
  109. message["app_id"] = UserInfo.AppID;
  110. message["log_type"] = log_type;
  111. message["rtc_id"] = rtc_id;
  112. message["call_type"] = call_type;
  113. WSHandler.SendMessage(message);
  114. }
  115. //加入房间通话 room_num 房间号
  116. public void JoinChat(string room_num)
  117. {
  118. JsonData message = new JsonData();
  119. JsonData data = new JsonData();
  120. message["action"] = "30001";
  121. message["user_token"] = UserInfo.User_Token;
  122. message["app_id"] = UserInfo.AppID;
  123. message["room_num"] = room_num;
  124. WSHandler.SendMessage(message);
  125. }
  126. //结束通话 room_num 房间号 call_time 通话时间
  127. public void ExitChat()
  128. {
  129. JsonData message = new JsonData();
  130. JsonData data = new JsonData();
  131. message["action"] = "30002";
  132. message["user_token"] = UserInfo.User_Token;
  133. message["app_id"] = UserInfo.AppID;
  134. WSHandler.SendMessage(message);
  135. }
  136. public void test(Vector3 pos, Vector3 eul, Vector3 scal,string id)
  137. {
  138. JsonData message = new JsonData();
  139. JsonData data = new JsonData();
  140. message["notification"] = true;
  141. message["method"] = "transmit";
  142. message["data"] = data;
  143. data["data2"]=new JsonData();
  144. data["action"] = "test";
  145. data["id"] = id;
  146. data["pos"] = pos.x + "_" + pos.y + "_" + pos.z;
  147. data["eul"] = eul.x + "_" + eul.y + "_" + eul.z;
  148. data["scal"] = scal.x + "_" + scal.y + "_" + scal.z;
  149. JsonData data2 = new JsonData();
  150. data2["notification"] = true;
  151. data2["method"] = "transmit";
  152. JsonData data3 = new JsonData();
  153. data2["data"] = data3;
  154. data3["action"] = "test";
  155. data3["id"] = id;
  156. data3["pos"] = pos.x + "_" + pos.y + "_" + pos.z;
  157. data3["eul"] = eul.x + "_" + eul.y + "_" + eul.z;
  158. data3["scal"] = scal.x + "_" + scal.y + "_" + scal.z;
  159. for (int i = 0; i < 2; i++)
  160. {
  161. data["data2"].Add(data2);
  162. }
  163. WSHandler.SendMessage(message);
  164. }
  165. public void testLogin(string id)
  166. {
  167. JsonData message = new JsonData();
  168. JsonData data = new JsonData();
  169. message["Request"] = true;
  170. message["method"] = "transmit";
  171. data["id"] = id;
  172. message["data"] = data;
  173. WSHandler.SendMessage(message);
  174. }
  175. public void OnMessageReceived(JsonData data)
  176. {
  177. LoginReceived(data);
  178. }
  179. private void Screenshoted(JsonData data)
  180. {
  181. if (OnScreenshot != null)
  182. {
  183. OnScreenshot(data);
  184. }
  185. }
  186. private void LoginReceived(JsonData data)
  187. {
  188. if (OnLogin != null) {
  189. OnLogin (data);
  190. }
  191. }
  192. private void LogoutReceived(JsonData data)
  193. {
  194. if (OnlogOut != null) {
  195. OnlogOut (data);
  196. }
  197. }
  198. private void ConnectedReceived(JsonData data)
  199. {
  200. if (OnConnected != null) {
  201. OnConnected (data);
  202. }
  203. }
  204. }