version:m40se 2.9.3
fix:修复m40se 管控写反失效问题 update:
This commit is contained in:
@@ -24,12 +24,13 @@ import android.util.Log;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fuying.sn.BuildConfig;
|
||||
import com.fuying.sn.KeepAliveConnection;
|
||||
import com.fuying.sn.utils.JGYUtils;
|
||||
import com.fuying.sn.utils.ServiceAliveUtils;
|
||||
import com.fuying.sn.utils.Utils;
|
||||
import com.fuying.sn.websocket.JWebSocketClient;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
Log.i("JWebSocketClientService", "网络已连接");
|
||||
connect();
|
||||
// connect();
|
||||
}
|
||||
|
||||
//用于Activity和service通讯
|
||||
@@ -141,6 +142,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
case Intent.ACTION_BOOT_COMPLETED:
|
||||
case Intent.ACTION_USER_PRESENT:
|
||||
case Intent.ACTION_SCREEN_ON:
|
||||
mHandler.post(heartBeatRunnable);//开启心跳检测
|
||||
sendMsg(1);
|
||||
break;
|
||||
case Intent.ACTION_SCREEN_OFF:
|
||||
@@ -191,7 +193,9 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
Log.i("JWebSocketClientService", "websocket连接关闭:" + reason);
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,7 +204,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
Log.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage());
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
} else {
|
||||
Log.i("JWebSocketClientService", "postDelayed off");
|
||||
}
|
||||
}
|
||||
};
|
||||
connect();
|
||||
@@ -223,6 +231,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +285,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
}
|
||||
|
||||
// -------------------------------------websocket心跳检测------------------------------------------------
|
||||
private static final long HEART_BEAT_RATE = 60 * 1000;//每隔50秒进行一次对长连接的心跳检测
|
||||
private static final long HEART_BEAT_RATE = 30 * 1000;//每隔50秒进行一次对长连接的心跳检测
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable heartBeatRunnable = new Runnable() {
|
||||
@Override
|
||||
@@ -288,7 +297,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
sendMsg();
|
||||
} else if (client.isClosed()) {
|
||||
Log.i("JWebSocketClientService", "websocket重连中");
|
||||
reconnectWs();
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
reconnectWs();
|
||||
} else {
|
||||
Log.i("JWebSocketClientService", "reconnectWs off");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//如果client已为空,重新初始化连接
|
||||
@@ -296,7 +309,11 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
initSocketClient();
|
||||
}
|
||||
//每隔一定的时间,对长连接进行一次心跳检测
|
||||
mHandler.postDelayed(this, HEART_BEAT_RATE);
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
mHandler.postDelayed(this, HEART_BEAT_RATE);
|
||||
} else {
|
||||
Log.i("JWebSocketClientService", "websocket息屏不重连");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user