add func of socket error msg

This commit is contained in:
zhongchao
2022-08-16 21:05:32 +08:00
parent f5026c189a
commit a7517f9639
5 changed files with 72 additions and 15 deletions

View File

@@ -0,0 +1,9 @@
package com.mogo.cloud.socket;
/**
* 长链错误消息监听
*/
public interface IMogoCloudSocketErrorListener {
void onError(int code, String msg);
}

View File

@@ -44,6 +44,10 @@ public interface IMogoCloudSocketManager {
*/
void unregisterSocketConnCallback(ConnectionLifecycleListener listener);
void registerSocketErrorCallback(String tag,IMogoCloudSocketErrorListener listener);
void unregisterSocketErrorCallback(String tag);
/**
* 发送消息
*

View File

@@ -4,9 +4,12 @@ package com.mogo.cloud.socket;
import static com.mogo.cloud.socket.SocketServicesConstants.getTag;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.elegant.log.simplelog.Logger;
import com.elegant.network.utils.GsonUtil;
@@ -20,6 +23,7 @@ import com.mogo.cloud.socket.internal.InternalSocketManager;
import com.mogo.cloud.socket.third.ThirdSocketManager;
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
import com.zhidao.socket.ConnectionLifecycleListener;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Iterator;
@@ -67,6 +71,7 @@ public class SocketManager implements IMogoCloudSocketManager {
*/
private final Map<Long, IMogoCloudSocketMsgAckListener> mAckListeners = new ConcurrentHashMap<>();
private final Map<String, IMogoCloudSocketErrorListener> mErrorListeners = new ConcurrentHashMap<>();
public static final int MAX_CAP = 64; //保证充足的容量应对非常延时的推送
private final ArrayList<Long> mReceivedMsgId = new ArrayList<>(MAX_CAP);
@@ -126,6 +131,31 @@ public class SocketManager implements IMogoCloudSocketManager {
}
}
@Override
public void registerSocketErrorCallback(String tag, IMogoCloudSocketErrorListener listener) {
if (listener == null || tag == null || TextUtils.isEmpty(tag)) {
return;
}
if (mErrorListeners.containsKey(tag)) {
if (SocketBuildConfig.isPrintLog) {
Logger.w(getTag(), "Type %d is exist.", tag);
}
return;
}
mErrorListeners.put(tag, listener);
}
@Override
public void unregisterSocketErrorCallback(String tag) {
if (tag == null || TextUtils.isEmpty(tag)) {
return;
}
if (!mErrorListeners.containsKey(tag)) {
return;
}
mErrorListeners.remove(tag);
}
@Override
public void sendMsg(String appId, int headerType, MsgBody body, IMogoCloudSocketMsgAckListener listener) {
if (SocketBuildConfig.isPrintLog) {
@@ -169,7 +199,7 @@ public class SocketManager implements IMogoCloudSocketManager {
Constructor c = clz.getDeclaredConstructor();
if (c != null) {
c.setAccessible(true);
MessageLiteOrBuilder o = (MessageLiteOrBuilder)c.newInstance();
MessageLiteOrBuilder o = (MessageLiteOrBuilder) c.newInstance();
obj = o.getDefaultInstanceForType().getParserForType().parseFrom(p);
}
} catch (Throwable t) {
@@ -222,6 +252,15 @@ public class SocketManager implements IMogoCloudSocketManager {
}
}
public void onError(int code, String msg) {
for (Map.Entry<String, IMogoCloudSocketErrorListener> entry : mErrorListeners.entrySet()) {
IMogoCloudSocketErrorListener listener = entry.getValue();
if(listener != null){
listener.onError(code, msg);
}
}
}
/**
* 将byte数组转换成PB数据
*

View File

@@ -6,7 +6,6 @@ import static com.mogo.cloud.socket.SocketServicesConstants.getTag;
import static com.zhidao.socket.location.MLocation.GCJ02;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -20,11 +19,12 @@ import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
import com.zhidao.socket.Callback;
import com.zhidao.socket.CallbackManager;
import com.zhidao.socket.ConnectionLifecycleListener;
import com.zhidao.socket.ErrorCallback;
import com.zhidao.socket.SocketClient;
import com.zhidao.socket.SocketConfig;
import com.zhidao.socket.location.MLocation;
public class ThirdSocketManager implements Callback {
public class ThirdSocketManager implements Callback, ErrorCallback {
private static volatile ThirdSocketManager mInstance;
private final MoGoAiCloudClientConfig cloudClientConfig;
@@ -63,6 +63,7 @@ public class ThirdSocketManager implements Callback {
.setDebug(cloudClientConfig.isShowDebugLog())
.setLocation(mLocation);
SocketClient.getInstance().registerSocketCallback(this);
SocketClient.getInstance().registerErrorCallback(this);
SocketClient.getInstance().start(context);
}
@@ -106,4 +107,8 @@ public class ThirdSocketManager implements Callback {
SocketClient.getInstance().unregisterSocketConnCallback(listener);
}
@Override
public void onError(int code, String msg) {
SocketManager.getInstance().onError(code, msg);
}
}

View File

@@ -36,26 +36,26 @@ PASSWORD=xintai2018
RELEASE=false
# AI CLOUD 云平台
# 工具类
MOGO_UTILS_VERSION=1.4.3.16
MOGO_UTILS_VERSION=1.4.3.17
# 网络请求
MOGO_NETWORK_VERSION=1.4.3.16
MOGO_NETWORK_VERSION=1.4.3.17
# 网络DNS
MOGO_HTTPDNS_VERSION=1.4.3.16
MOGO_HTTPDNS_VERSION=1.4.3.17
# 鉴权
MOGO_PASSPORT_VERSION=1.4.3.16
MOGO_PASSPORT_VERSION=1.4.3.17
# 常链接
MOGO_SOCKET_VERSION=1.4.3.16
MOGO_SOCKET_VERSION=1.4.3.17
# 数据采集
MOGO_REALTIME_VERSION=1.4.3.16
MOGO_REALTIME_VERSION=1.4.3.17
# 探路,道路事件发布,获取
MOGO_TANLU_VERSION=1.4.3.16
MOGO_TANLU_VERSION=1.4.3.17
# 直播推流
MOGO_LIVE_VERSION=1.4.3.16
MOGO_LIVE_VERSION=1.4.3.17
# 直播拉流
MOGO_TRAFFICLIVE_VERSION=1.4.3.16
MOGO_TRAFFICLIVE_VERSION=1.4.3.17
# 定位服务
MOGO_LOCATION_VERSION=1.4.3.16
MOGO_LOCATION_VERSION=1.4.3.17
# 远程通讯模块
MOGO_TELEMATIC_VERSION=1.4.3.16
MOGO_TELEMATIC_VERSION=1.4.3.17
# v2x
MOGO_V2X_VERSION=1.4.3.16
MOGO_V2X_VERSION=1.4.3.17