fix bug of websocket DNS and wait for ws: server online to replace httpUrl

This commit is contained in:
unknown
2020-11-25 11:09:46 +08:00
parent 4c112bb797
commit 8b4893b40e
3 changed files with 22 additions and 18 deletions

View File

@@ -5,13 +5,14 @@ import com.mogo.commons.debug.DebugConfig;
public class WebSocketConstant {
private static final String HOST_DEV = "ws://62.234.196.121:14001/ws";
private static final String HOST_QA = "ws://62.234.196.121:14001/ws";
private static final String HOST_DEMO = "ws://62.234.196.121:14001/ws";
private static final String HOST_RELEASE = "ws://62.234.196.121:14001/ws";
private static final String HOST_DEV = "ws://62.234.196.121";
private static final String HOST_QA = "ws://62.234.196.121";
private static final String HOST_DEMO = "ws://62.234.196.121";
private static final String HOST_RELEASE = "ws://62.234.196.121";
private static final String PORT = ":14001/ws";
public static String getSocketServer(){
switch (DebugConfig.getNetMode()){
public static String getSocketServer() {
switch (DebugConfig.getNetMode()) {
case DebugConfig.NET_MODE_DEV:
return HOST_DEV;
case DebugConfig.NET_MODE_QA:
@@ -21,7 +22,10 @@ public class WebSocketConstant {
case DebugConfig.NET_MODE_RELEASE:
default:
return HOST_RELEASE;
}
}
public static String getSocketPort() {
return PORT;
}
}

View File

@@ -30,7 +30,7 @@ public class WebSocketDnsManager {
ThreadPoolService.execute(() -> mogoHttpDns.getHttpDnsIp(WebSocketConstant.getSocketServer(), true, ip -> {
Logger.d(TAG, "getHttpDnsIp ip : " + ip + " , 得到Dns IP,准备回调 初始化webSocket");
this.cacheIp = ip;
this.webSocketDns.getDnsIp(cacheIp != null ? cacheIp : WebSocketConstant.getSocketServer());
this.webSocketDns.getDnsIp((cacheIp != null ? cacheIp : WebSocketConstant.getSocketServer() + WebSocketConstant.getSocketPort()));
}));
mogoHttpDns.addHttpDnsTtlCallback(WebSocketConstant.getSocketServer(), () -> {
Logger.d(TAG, "ttl callBack ,ready to getCache Dns IP");
@@ -40,15 +40,15 @@ public class WebSocketDnsManager {
}
Logger.d(TAG, "获取缓存Dns IP : " + dnsCacheIp + " , 原缓存 IP " + cacheIp);
if (cacheIp != null && !cacheIp.equals(dnsCacheIp)) {
this.webSocketDns.ttlIp(dnsCacheIp);
this.webSocketDns.ttlIp(dnsCacheIp + WebSocketConstant.getSocketPort());
}
});
}
public interface WebSocketDns {
void getDnsIp(String ip);
void getDnsIp(String url);
void ttlIp(String ip);
void ttlIp(String url);
}
}

View File

@@ -70,18 +70,18 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
public void init(Context context, String appId) {
WebSocketDnsManager.getInstance().getHttpDnsIp(new WebSocketDnsManager.WebSocketDns() {
@Override
public void getDnsIp(String ip) {
Logger.d(TAG,"getDnsIp ip : " + ip);
initWebSocket(ip);
public void getDnsIp(String url) {
Logger.d(TAG,"getDnsIp url : " + url);
initWebSocket(url);
}
@Override
public void ttlIp(String ip) {
Logger.d(TAG,"ttlIp ip : " + ip);
public void ttlIp(String url) {
Logger.d(TAG,"ttlIp url : " + url);
SocketClient.getInstance().getClientProxy().stop();
SocketClient.getInstance().getClientProxy().disConnect();
Logger.d(TAG,"ready to re initWebSocket : " + ip);
initWebSocket(ip);
Logger.d(TAG,"ready to re initWebSocket : " + url);
initWebSocket(url);
}
});
}