123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using LitJson;
- public class WSUserHandler {
- public delegate void OnLoginDelegate(JsonData data);
- public delegate void OnLogoutDelegate(JsonData data);
- public delegate void OnConnectedDelegate(JsonData data);
- public delegate void OnScreenshotDelegate(JsonData data);
- public OnLoginDelegate OnLogin;
- public OnLoginDelegate OnlogOut;
- public OnConnectedDelegate OnConnected;
- public OnScreenshotDelegate OnScreenshot;
- //token登录
-
- public void Login()
- {
- JsonData message = new JsonData ();
- JsonData data = new JsonData ();
- message["action"] = "10101";
- message["user_token"] = UserInfo.Token;
- message["app_id"] = UserInfo.AppID;
- // message ["data"] = data;
- Debug.Log("Login_token====>"+ UserInfo.Token);
- WSHandler.SendMessage (message);
- }
- //退出 立刻执行关闭链接操作
- public void LogOut()
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20100";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- WSHandler.SendMessage(message);
- }
- //添加联系人 rtc_id 通讯录列表的用户id postscript 备注信息 notice_status 通知状态
- public void AddUser(string rtc_id, string msg, string notice_status="")
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20201";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["rtc_id"] = rtc_id;
- message["postscript"] = msg;
- WSHandler.SendMessage(message);
- }
- //添加通知 notice_type 通知类型1:通话记录通知 2:联系人通知 3:文件通知 document 分享文件 (当通知类型为3必传)
- //receive_uid 通知接收用户id notice_status 通知状态1:未处理 2:已读未处理 3:已读已处理
- //call_duration 通话时长,单位:秒 postscript 备注信息(当通知类型为2,可传可不传)
- public void AddNotice(string notice_type,string receive_uid,string call_duration, string notice_status="", string postscript="", string document="")
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20301";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["notice_type"] = notice_type;
- message["receive_uid"] = receive_uid;
- message["call_duration"] = call_duration;
- message["notice_status"] = notice_status;
- message["postscript"] = postscript;
- message["document"] = document;
- WSHandler.SendMessage(message);
- }
- //回执通知 notice_id 消息id operation 好友请求操作状态 1:同意 2:拒绝
- public void ReceivedUser(string notice_id, string operation)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20302";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["notice_id"] = notice_id;
- message["operation"] = operation;
- WSHandler.SendMessage(message);
- }
- //创建通话 log_type通话记录类型 1 电话 2视频
- public void CreateChat(string log_type)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20413";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["log_type"] = log_type;
- WSHandler.SendMessage(message);
- }
- //邀请通话 log_type通话记录类型 1 电话 2视频 rtc_id 通讯录列表的用户id room_num 房间号
- public void InviteChat(string log_type, string rtc_id, string room_num)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20414";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["log_type"] = log_type;
- message["rtc_id"] = rtc_id;
- message["room_num"] = room_num;
- WSHandler.SendMessage(message);
- }
- //创建并且邀请通话 log_type通话记录类型 1 电话 2视频 rtc_id 通讯录列表的用户id call_type 通话记录类型 //0查询列表时传参 全部通话记录 1:呼出 2:呼入 3:未接
- public void CreateAndInviteChat(string log_type, string rtc_id, string call_type)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "20415";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["log_type"] = log_type;
- message["rtc_id"] = rtc_id;
- message["call_type"] = call_type;
- WSHandler.SendMessage(message);
- }
- //加入房间通话 room_num 房间号
- public void JoinChat(string room_num)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "30001";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- message["room_num"] = room_num;
- WSHandler.SendMessage(message);
- }
- //结束通话 room_num 房间号 call_time 通话时间
- public void ExitChat()
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["action"] = "30002";
- message["user_token"] = UserInfo.User_Token;
- message["app_id"] = UserInfo.AppID;
- WSHandler.SendMessage(message);
- }
- public void test(Vector3 pos, Vector3 eul, Vector3 scal,string id)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["notification"] = true;
- message["method"] = "transmit";
- message["data"] = data;
- data["data2"]=new JsonData();
- data["action"] = "test";
- data["id"] = id;
- data["pos"] = pos.x + "_" + pos.y + "_" + pos.z;
- data["eul"] = eul.x + "_" + eul.y + "_" + eul.z;
- data["scal"] = scal.x + "_" + scal.y + "_" + scal.z;
- JsonData data2 = new JsonData();
- data2["notification"] = true;
- data2["method"] = "transmit";
- JsonData data3 = new JsonData();
- data2["data"] = data3;
- data3["action"] = "test";
- data3["id"] = id;
- data3["pos"] = pos.x + "_" + pos.y + "_" + pos.z;
- data3["eul"] = eul.x + "_" + eul.y + "_" + eul.z;
- data3["scal"] = scal.x + "_" + scal.y + "_" + scal.z;
- for (int i = 0; i < 2; i++)
- {
- data["data2"].Add(data2);
- }
- WSHandler.SendMessage(message);
- }
- public void testLogin(string id)
- {
- JsonData message = new JsonData();
- JsonData data = new JsonData();
- message["Request"] = true;
- message["method"] = "transmit";
- data["id"] = id;
- message["data"] = data;
- WSHandler.SendMessage(message);
- }
- public void OnMessageReceived(JsonData data)
- {
- LoginReceived(data);
- }
- private void Screenshoted(JsonData data)
- {
- if (OnScreenshot != null)
- {
- OnScreenshot(data);
- }
- }
- private void LoginReceived(JsonData data)
- {
- if (OnLogin != null) {
- OnLogin (data);
- }
- }
- private void LogoutReceived(JsonData data)
- {
- if (OnlogOut != null) {
- OnlogOut (data);
- }
- }
- private void ConnectedReceived(JsonData data)
- {
- if (OnConnected != null) {
- OnConnected (data);
- }
- }
- }
|