socket 增加链接状态监听
This commit is contained in:
@@ -27,7 +27,7 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
// socket-for-sdk 长链 http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48956182 外部SDK版本
|
||||
api 'com.zhidao.socket:built-in-socket:1.0.22'
|
||||
api 'com.zhidao.socket:built-in-socket:1.0.23-SNAPSHOT'
|
||||
// 上报位置 http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48956200
|
||||
implementation 'com.zhidao.locupload:loc-upload-sdk:1.1.9'
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.cloud.socket;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.cloud.socket.entity.MsgBody;
|
||||
import com.zhidao.socket.ConnectionLifecycleListener;
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,18 @@ public interface IMogoCloudSocketManager {
|
||||
*/
|
||||
void unregisterOnMessageListener(int msgType, IMogoCloudSocketOnMessageListener listener);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
void registerSocketConnCallback(ConnectionLifecycleListener listener);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
void unregisterSocketConnCallback(ConnectionLifecycleListener listener);
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.mogo.cloud.socket.internal.InternalSocketManager;
|
||||
import com.mogo.cloud.socket.third.ThirdSocketManager;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
|
||||
import com.zhidao.socket.ConnectionLifecycleListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -105,6 +106,20 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSocketConnCallback(ConnectionLifecycleListener listener) {
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().registerSocketConnCallback(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterSocketConnCallback(ConnectionLifecycleListener listener) {
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().unregisterSocketConnCallback(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg(String appId, int headerType, MsgBody body, IMogoCloudSocketMsgAckListener listener) {
|
||||
Logger.d(TAG, "sendMsg msgId : " + body.getMsgId());
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.zhidao.locupload.Platform;
|
||||
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.SocketClient;
|
||||
import com.zhidao.socket.SocketConfig;
|
||||
|
||||
@@ -19,7 +20,7 @@ import static com.mogo.cloud.socket.SocketServicesConstants.SOCKET_CHANNEL_ID;
|
||||
import static com.mogo.cloud.socket.SocketServicesConstants.TAG;
|
||||
import static com.mogo.cloud.socket.SocketServicesConstants.getEnvironment;
|
||||
|
||||
public class ThirdSocketManager implements Callback {
|
||||
public class ThirdSocketManager extends ConnectionLifecycleListener implements Callback {
|
||||
|
||||
private static volatile ThirdSocketManager mInstance;
|
||||
private final MoGoAiCloudClientConfig cloudClientConfig;
|
||||
@@ -52,6 +53,7 @@ public class ThirdSocketManager implements Callback {
|
||||
.setAuthPubKey(cloudClientConfig.getAuthPubKey())
|
||||
.setDebug(cloudClientConfig.isShowDebugLog());
|
||||
SocketClient.getInstance().registerSocketCallback(this);
|
||||
SocketClient.getInstance().registerSocketConnCallback(this);
|
||||
SocketClient.getInstance().start(context);
|
||||
}
|
||||
|
||||
@@ -81,4 +83,30 @@ public class ThirdSocketManager implements Callback {
|
||||
SocketClient.getInstance().stop();
|
||||
mInstance = null;
|
||||
}
|
||||
|
||||
public void registerSocketConnCallback(ConnectionLifecycleListener listener){
|
||||
SocketClient.getInstance().registerSocketConnCallback(listener);
|
||||
}
|
||||
|
||||
public void unregisterSocketConnCallback(ConnectionLifecycleListener listener){
|
||||
SocketClient.getInstance().registerSocketConnCallback(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectLost(boolean reconnect) {
|
||||
Logger.d(TAG,"ThirdSocketManager onConnectLost");
|
||||
super.onConnectLost(reconnect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectFailure() {
|
||||
Logger.d(TAG,"ThirdSocketManager onConnectFailure");
|
||||
super.onConnectFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectSuccess() {
|
||||
Logger.d(TAG,"ThirdSocketManager onConnectSuccess");
|
||||
super.onConnectSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user