socket divide origin and new
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.mogo.cloud.socket.third.core;
|
||||
|
||||
import static com.mogo.cloud.socket.third.core.SocketConstants.DEFAULT_AUTH_ORIGIN_PUB_KEY;
|
||||
import static com.mogo.cloud.socket.third.core.SocketConstants.DEFAULT_AUTH_PUB_KEY;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.cloud.TelephoneUtil;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
|
||||
public class SocketConfig {
|
||||
@@ -13,7 +17,9 @@ public class SocketConfig {
|
||||
|
||||
private Context appContext;
|
||||
|
||||
/**Need to be registered by server before it can be applied*/
|
||||
/**
|
||||
* Need to be registered by server before it can be applied
|
||||
*/
|
||||
private String channelId;
|
||||
|
||||
private Environment environment;
|
||||
@@ -22,7 +28,9 @@ public class SocketConfig {
|
||||
|
||||
private boolean openAnalytics;
|
||||
|
||||
/**Customized sn can be set*/
|
||||
/**
|
||||
* Customized sn can be set
|
||||
*/
|
||||
private String sn;
|
||||
|
||||
private String uid;
|
||||
@@ -96,12 +104,16 @@ public class SocketConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**Retrieve sn of current device, and return customized sn first*/
|
||||
/**
|
||||
* Retrieve sn of current device, and return customized sn first
|
||||
*/
|
||||
public String getSn() {
|
||||
return TextUtils.isEmpty(sn) ? TelephoneUtil.getSerialNumber() : sn;
|
||||
}
|
||||
|
||||
/**The third-party device can set a customized sn*/
|
||||
/**
|
||||
* The third-party device can set a customized sn
|
||||
*/
|
||||
public SocketConfig setSn(String sn) {
|
||||
this.sn = sn;
|
||||
return this;
|
||||
@@ -126,8 +138,12 @@ public class SocketConfig {
|
||||
}
|
||||
|
||||
public String getAuthPubKey() {
|
||||
if(TextUtils.isEmpty(authPubKey)){
|
||||
authPubKey = SocketConstants.DEFAULT_AUTH_PUB_KEY;
|
||||
if (TextUtils.isEmpty(authPubKey)) {
|
||||
if (MoGoAiCloudClientConfig.getInstance().isUseOriginSocket()) {
|
||||
authPubKey = DEFAULT_AUTH_ORIGIN_PUB_KEY;
|
||||
} else {
|
||||
authPubKey = DEFAULT_AUTH_PUB_KEY;
|
||||
}
|
||||
}
|
||||
return authPubKey;
|
||||
}
|
||||
|
||||
@@ -19,4 +19,6 @@ public interface SocketConstants {
|
||||
|
||||
String DEFAULT_AUTH_PUB_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1En+aK8zhDRI2495gwmFYuIAHJxFV8MQuBWSY+xRJMtNq6UITx72NgfMWxmxzoxrvv6T1mb3HMVpIto1H3mliPg9LbZ48GAuDRWXHxLxNR69W45okhGAkDxU1GmlRPzEplwwfbar5Bdv3Bd24ABpGQhzozfEK5T5Ej9KrT/a7YwIDAQAB";
|
||||
|
||||
String DEFAULT_AUTH_ORIGIN_PUB_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCLe57ORPgOnBrcWmGac3esB4PtIyI0rAHiyk5QoCRTnTyanwWLfstu7mz2MSHD3YuveNWDiIY8vtRvFNE4M/yA7eb4Mct01VKhKFI/JqwyXgNaSh5YCfmv0vg9687c7IUjTEAg+ReC/bSLDqEB3a0vuP95Txtj9smMlx1e37XFYQIDAQAB";
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.elegant.network.RequestOptions;
|
||||
import com.elegant.network.utils.GsonUtil;
|
||||
import com.elegant.network.utils.NetworkSdkUtils;
|
||||
import com.elegant.utils.CommonUtils;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.third.core.SocketConfig;
|
||||
import com.mogo.cloud.socket.third.core.network.model.MessageCallbackData;
|
||||
import com.mogo.cloud.socket.third.core.network.model.SocketAddressData;
|
||||
@@ -20,6 +21,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import rx.Observable;
|
||||
|
||||
public class RequestManager {
|
||||
|
||||
@@ -42,19 +44,19 @@ public class RequestManager {
|
||||
@Override
|
||||
protected void onFailure(int code, String message) {
|
||||
super.onFailure(code, message);
|
||||
Logger.d(TAG,"socket message callback failed");
|
||||
Logger.d(TAG, "socket message callback failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSuccess(BaseResp o) {
|
||||
super.onSuccess(o);
|
||||
Logger.d(TAG,"socket message callback succeeded");
|
||||
Logger.d(TAG, "socket message callback succeeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNetworkLost() {
|
||||
super.onNetworkLost();
|
||||
Logger.d(TAG,"request socket message callback, network is not available.");
|
||||
Logger.d(TAG, "request socket message callback, network is not available.");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -76,8 +78,13 @@ public class RequestManager {
|
||||
.append("versionName", CommonUtils.getVersionName(SocketConfig.instance().getAppContext()))
|
||||
.build();
|
||||
|
||||
ServiceFactory.newTechApiService().requestSocketAddress(params)
|
||||
.compose(NetworkSdkUtils.transformer())
|
||||
Observable<SocketAddressData> observable;
|
||||
if (MoGoAiCloudClientConfig.getInstance().isUseOriginSocket()) {
|
||||
observable = ServiceFactory.newTechOriginApiService().requestSocketAddress(params);
|
||||
} else {
|
||||
observable = ServiceFactory.newTechApiService().requestSocketAddress(params);
|
||||
}
|
||||
observable.compose(NetworkSdkUtils.transformer())
|
||||
.subscribe(new DefSubscriberImpl<SocketAddressData>(RequestOptions.of(context)) {
|
||||
@Override
|
||||
protected void onSuccess(SocketAddressData o) {
|
||||
@@ -110,6 +117,7 @@ public class RequestManager {
|
||||
|
||||
public interface SocketAddressCallback {
|
||||
void onGetSocketAddressSuccess(SocketAddressData data);
|
||||
|
||||
void onGetSocketAddressFailed(int code, String msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ public class ServiceFactory extends SimpleServiceFactory {
|
||||
return newService(getTechUrl(), TechApiService.class);
|
||||
}
|
||||
|
||||
public static synchronized TechOriginApiService newTechOriginApiService() {
|
||||
return newService(getTechOriginUrl(), TechOriginApiService.class);
|
||||
}
|
||||
|
||||
private static String getTechUrl(){
|
||||
final Environment environment = SocketConfig.instance().getEnvironment();
|
||||
|
||||
@@ -30,6 +34,18 @@ public class ServiceFactory extends SimpleServiceFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getTechOriginUrl(){
|
||||
final Environment environment = SocketConfig.instance().getEnvironment();
|
||||
|
||||
if(environment == Environment.release){
|
||||
return "http://tech.zhidaohulian.com/";
|
||||
}else if(environment == Environment.qa){
|
||||
return "http://tech-qa.zhidaohulian.com/";
|
||||
}else{
|
||||
return "http://tech-dev.zhidaohulian.com/";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getUrl(){
|
||||
final Environment environment = SocketConfig.instance().getEnvironment();
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.cloud.socket.third.core.network;
|
||||
|
||||
|
||||
import com.mogo.cloud.socket.third.core.network.model.SocketAddressData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.QueryMap;
|
||||
import rx.Observable;
|
||||
|
||||
public interface TechOriginApiService {
|
||||
@GET("/alloc/connsvrAddr")
|
||||
Observable<SocketAddressData> requestSocketAddress(@QueryMap Map<String, Object> params);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
|
||||
USERNAME=xintai
|
||||
PASSWORD=xintai2018
|
||||
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
|
||||
RELEASE=true
|
||||
RELEASE=false
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.2.3
|
||||
|
||||
Reference in New Issue
Block a user