public void Connect(string sceneName, KNodeCallback callback) { On(EventConfig.AR_ONLINE, callback); socket.Open(); Emit(EventConfig.ONLINE, JsonUtility.ToJson(new LocalDeviceRequest(sceneName))); //心跳检测 //Emit(EventConfig.REQUEST_HEART, JsonUtility.ToJson(new TargetDeviceRequest(true, GlobalManager.DeviceID, "1"))); }
/// <summary> /// 添加监听回调 /// </summary> /// <param name="response">回调事件名</param> /// <param name="callback">回调方法</param> public void AddListener(string response, KNodeCallback callback) { mySocket.On(response, (socket, packet, arg) => { Debug.Log(packet.Payload); JSONNode jRoot = JSON.Parse(packet.Payload)[1]; if (jRoot["status"] != "error") { //TODO; 数据的转换 JSONNode data = jRoot["data"]; callback(data, jRoot); } else { UIManager.ShowErrorMessage(jRoot["message"]); } }); }
public void StartRequestData(string request, string eventName, KNodeCallback callback) { socket.StartGetData(request, eventName, callback); }
/// <summary> /// 注册事件,回调函数为jsonnode数组,0是data,1是原始json {state:"",data:{},message:""} /// </summary> /// <param name="response">回调名称</param> /// <param name="callback">回调方法</param> public void On(string response, KNodeCallback callback) { socket.AddListener(response, callback); }
/// <summary> /// 获取动态数据 /// </summary> /// <param name="request">请求命令</param> /// <param name="eventName">回调事件名</param> /// <param name="callback">回调方法</param> public void StartGetData(string request, string eventName, KNodeCallback callback) { requestObj = new TargetDeviceRequest(true, GlobalManager.DeviceID, GlobalManager.CURRENT_TANKID); Request(request, JsonUtility.ToJson(requestObj)); AddListener(eventName, callback); }