Commit 39176743 authored by sheteng's avatar sheteng

链接重新链接发消息逻辑

parent bf1b3988
......@@ -50,7 +50,7 @@ public class LoginViewModel extends ViewModel {
public void onSocketDisconnection(int code) {
System.out.println("onSocketDisconnection");
//重连
login(context, appKey, appsecret, username, userId, ip, port);
// login(context, appKey, appsecret, username, userId, ip, port);
}
});
......
......@@ -146,11 +146,13 @@ public class NotificationsFragment extends Fragment {
public void onSuccess(Long aLong) {
//获取剪贴板管理器:
loginViewModel.addChannelId(aLong);
if (getContext() != null) {
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newPlainText("Label", aLong.toString());
cm.setPrimaryClip(mClipData);
ToastUtil.show(getContext(), "create success,id copy success");
}
}
@Override
public void onFailed(int errorCode) {
......
......@@ -14,7 +14,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:text="19"
android:text="20"
android:inputType="textEmailAddress"
android:selectAllOnFocus="true"
app:layout_constraintEnd_toEndOf="parent"
......@@ -27,7 +27,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="UserId"
android:text="19"
android:text="20"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionDone"
android:selectAllOnFocus="true"
......
......@@ -56,7 +56,7 @@ public class CCIMClient {
private Long lastSendTimemillis = 0L; //上次发送消息时间,用于时间间隔
private int maxSendMsgInterval = 0;
private int maxAudioDuration = 0;
private int minAudioDuration = 500;
private final int minAudioDuration = 500;
private String downloadPrefix;
private String cachePath;
......@@ -115,13 +115,13 @@ public class CCIMClient {
@Override
public void onSocketReConnection() {
isConnected = false;
// isConnected = false;
}
@Override
public void onSocketDisconnection(int code) {
isConnected = false;
logger.info("disconnection");
logger.info("disconnection " + code);
resultCallback.onSocketDisconnection(code);
}
......
......@@ -9,7 +9,6 @@ import com.ccwangluo.ccim.CCIMClient;
import com.ccwangluo.ccim.listener.MessageListener;
import com.ccwangluo.ccim.util.ErrorCode;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
......@@ -41,8 +40,6 @@ public class NettyChatClient implements SocketClient {
private Bootstrap bootstrap;
private Context context;
EventLoopGroup group = new NioEventLoopGroup();
private ExecutorService executor = Executors.newSingleThreadExecutor();
ScheduledExecutorService timerExcutor;
......@@ -76,21 +73,18 @@ public class NettyChatClient implements SocketClient {
@Override
public void connect(MessageListener msglistner) {
this.msglitener = msglistner;
connect();
connectSync();
}
private void connect() {
executor.execute(() -> {
private void connectSync() {
try {
channelFuture = bootstrap.connect(ip, port).sync();
} catch (Exception e) {
e.printStackTrace();
if (msglitener != null){
if (msglitener != null) {
msglitener.onServerDisConnect(ErrorCode.NET_ERROR);
}
}
});
}
......@@ -114,12 +108,11 @@ public class NettyChatClient implements SocketClient {
if (channelFuture == null) {
return;
}
executor.execute(() -> {
channelFuture.channel().writeAndFlush(msg);
if (!channelFuture.channel().isActive()) {
connect();
connectSync();
} else {
channelFuture.channel().writeAndFlush(msg);
}
});
}
......@@ -138,7 +131,7 @@ public class NettyChatClient implements SocketClient {
if (channelFuture != null && channelFuture.channel().isActive()) {
return true;
}
connect();
connectSync();
return false;
}
......@@ -158,7 +151,7 @@ public class NettyChatClient implements SocketClient {
} else {
try {
logger.info("reconnect");
connect();
connectSync();
} catch (Exception e) {
e.printStackTrace();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment