Commit 409444ee by patpat

增加每10分钟自动发送心跳包

parent 5a0b75db
...@@ -4,6 +4,7 @@ public enum ActionEnum { ...@@ -4,6 +4,7 @@ public enum ActionEnum {
// 检查设备 // 检查设备
CHECK_DEVICE, CHECK_DEVICE,
AUTO_CHECK_DEVICE,
// 支付 // 支付
PAY_, PAY_,
......
...@@ -48,6 +48,7 @@ public class MainWebSocket extends WebSocketClient { ...@@ -48,6 +48,7 @@ public class MainWebSocket extends WebSocketClient {
private static MainWebSocket sInstance; private static MainWebSocket sInstance;
private static String sDeviceSN; private static String sDeviceSN;
private static int sReconnectTimes = 0; private static int sReconnectTimes = 0;
private static int sAutoCheckCount = 0;
public static void initialize() { public static void initialize() {
if (sInstance == null) { if (sInstance == null) {
...@@ -72,6 +73,20 @@ public class MainWebSocket extends WebSocketClient { ...@@ -72,6 +73,20 @@ public class MainWebSocket extends WebSocketClient {
NetworkManager.INSTANCE.switchNetwork(); NetworkManager.INSTANCE.switchNetwork();
EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CHANGE_NETWORK)); EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CHANGE_NETWORK));
} }
sAutoCheckCount = 0;
} else {
// 每10分钟发一次心跳包给后端
sAutoCheckCount -= 2;
if (sAutoCheckCount < 0) {
sAutoCheckCount = 10 * 60;
try {
JSONObject data = new JSONObject();
data.put(FieldEnum.equipmentId.name(), sDeviceSN);
action(ActionEnum.AUTO_CHECK_DEVICE.name(), data, null);
} catch (Exception e) {
}
}
} }
} }
}, 2000, -1, 2000); }, 2000, -1, 2000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment