Merge remote-tracking branch 'origin/demo/shunyi_vr_map' into demo/shunyi_vr_map

This commit is contained in:
wangcongtao
2020-11-24 15:37:58 +08:00
3 changed files with 75 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ dependencies {
implementation project(":services:mogo-service-api")
implementation project(':modules:mogo-module-common')
}
implementation project(':foudations:httpdns-base')
}

View File

@@ -0,0 +1,54 @@
package com.mogo.base.websocket;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.httpdns.IMogoHttpDns;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.logger.Logger;
public class WebSocketDnsManager {
private static final String TAG = "WebSocketDnsManager";
private WebSocketDnsManager() {
}
private static final class Holder {
private static WebSocketDnsManager dnsManager = new WebSocketDnsManager();
}
public static WebSocketDnsManager getInstance() {
return Holder.dnsManager;
}
private WebSocketDns webSocketDns;
private String cacheIp;
public void getHttpDnsIp(WebSocketDns webSocketDns) {
this.webSocketDns = webSocketDns;
IMogoHttpDns mogoHttpDns = ARouter.getInstance().navigation(IMogoHttpDns.class);
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());
}));
mogoHttpDns.addHttpDnsTtlCallback(WebSocketConstant.getSocketServer(), () -> {
Logger.d(TAG, "ttl callBack ,ready to getCache Dns IP");
String dnsCacheIp = mogoHttpDns.getCachedHttpDnsIps(WebSocketConstant.getSocketServer());
if (dnsCacheIp == null) {
return;
}
Logger.d(TAG, "获取缓存Dns IP : " + dnsCacheIp + " , 原缓存 IP " + cacheIp);
if (cacheIp != null && !cacheIp.equals(dnsCacheIp)) {
this.webSocketDns.ttlIp(dnsCacheIp);
}
});
}
public interface WebSocketDns {
void getDnsIp(String ip);
void ttlIp(String ip);
}
}

View File

@@ -68,7 +68,26 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin
@Override
public void init(Context context, String appId) {
SocketClient.getInstance().getClientProxy().initSocketServer(WebSocketConstant.getSocketServer());
WebSocketDnsManager.getInstance().getHttpDnsIp(new WebSocketDnsManager.WebSocketDns() {
@Override
public void getDnsIp(String ip) {
Logger.d(TAG,"getDnsIp ip : " + ip);
initWebSocket(ip);
}
@Override
public void ttlIp(String ip) {
Logger.d(TAG,"ttlIp ip : " + ip);
SocketClient.getInstance().getClientProxy().stop();
SocketClient.getInstance().getClientProxy().disConnect();
Logger.d(TAG,"ready to re initWebSocket : " + ip);
initWebSocket(ip);
}
});
}
private void initWebSocket(String ip){
SocketClient.getInstance().getClientProxy().initSocketServer(ip);
SocketClient.getInstance().getClientProxy().getMessageSettings(this);
SocketClient.getInstance().getClientProxy().addISocketMsgCallBack(this);
SocketClient.getInstance().getClientProxy().startConnect();