AVOSCloud.setRegion(AVOSCloud.REGION.EastChina);
AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);
AVOSCloud.initialize(this.appId, this.appKey);
AVIMOptions.getGlobalOptions().setTimeoutInSecs(30);
AVConnectionManager manager = AVConnectionManager.getInstance();
manager.autoConnection();
manager.startConnection(new AVCallback() {
@Override
protected void internalDone0(Object o, AVException e) {
if (e == null) {
log.info("成功建立 WebSocket 链接");
} else {
log.info("建立 WebSocket 链接失败:" + e.getMessage());
}
}
});
AVIMClient.setClientEventHandler(ZxbClientEventHandler.getInstance());
AVIMMessageManager.setConversationEventHandler(new ZxbIntelConversationEventHandler());
AVIMMessageManager.registerDefaultMessageHandler(new ZxbIntelMessageHandler());
AVIMOptions.getGlobalOptions().setMessageQueryCacheEnabled(false);
-------------------------------handler 如下所示--------------------------------
package com.zbintel.zxb.service.imms.biz.handler;
import cn.leancloud.im.v2.AVIMClient;
import cn.leancloud.im.v2.AVIMClientEventHandler;
public class ZxbClientEventHandler extends AVIMClientEventHandler {
private static ZxbClientEventHandler eventHandler;
public static synchronized ZxbClientEventHandler getInstance() {
if (null == eventHandler) {
eventHandler = new ZxbClientEventHandler();
}
return eventHandler;
}
private ZxbClientEventHandler() {
}
private volatile boolean connect = false;
/**
* 是否连上聊天服务
*
* @return
*/
public boolean isConnect() {
return connect;
}
@Override
public void onConnectionPaused(AVIMClient avimClient) {
System.out.println("下线"+avimClient.getClientId());
}
@Override
public void onConnectionResume(AVIMClient avimClient) {
System.out.println("上线"+avimClient.getClientId());
}
@Override
public void onClientOffline(AVIMClient avimClient, int i) {
System.out.println("下线"+avimClient.getClientId());
}
}
您好,我还有一个问题请教一下。我是纯JAVA环境。初始化方法如上所示,网络断开的时候可以接收到onConnectionPaused()方法的回调请求。然后我恢复网络,等了几分钟,一直没有接收到onConnectionResume()方法的回调。 麻烦看一下我的初始化代码是否存在问题。