|
|
@@ -11,6 +11,7 @@ import 'package:chat/generated/i18n.dart'; |
|
|
|
import 'package:chat/proto/all.pbserver.dart';
|
|
|
|
import 'package:chat/utils/LoadingDialog.dart';
|
|
|
|
import 'package:chat/utils/net_state_util.dart';
|
|
|
|
import 'package:chat/utils/screen.dart';
|
|
|
|
import 'package:chat/utils/upload_util.dart';
|
|
|
|
import 'package:oktoast/oktoast.dart';
|
|
|
|
import 'package:protobuf/protobuf.dart';
|
|
|
@@ -60,7 +61,10 @@ class NetWork { |
|
|
|
Timer heartTimer;
|
|
|
|
Timer sendTimer;
|
|
|
|
Timer connectServerTimer; //尝试连接服务器
|
|
|
|
Timer loginTimer; //登录计时器
|
|
|
|
Timer loginTimer; //登录
|
|
|
|
|
|
|
|
// 计时器
|
|
|
|
Timer iosBgTimer; //登录计时器
|
|
|
|
|
|
|
|
bool isInit = false;
|
|
|
|
|
|
|
@@ -78,9 +82,6 @@ class NetWork { |
|
|
|
HttpUtil().post('/service/config', data: data).then((res) {
|
|
|
|
print('获取聊天服务器地址成功');
|
|
|
|
res = json.decode(res.toString());
|
|
|
|
if (res == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (res['code'] == 0) {
|
|
|
|
var config = res['data'][0];
|
|
|
|
|
|
|
@@ -159,7 +160,7 @@ class NetWork { |
|
|
|
loginTimer?.cancel();
|
|
|
|
MsgHandler.flushCacheMsg();
|
|
|
|
UploadUtil().setUploadUrl(msgContent.httpAddr);
|
|
|
|
GroupInfoMgr().checkGroupValid();
|
|
|
|
GroupInfoMgr().checkGroupValid();
|
|
|
|
} else {
|
|
|
|
_stateBloc.addState(ChatState.loginFailed);
|
|
|
|
print('登录失败${msgContent.errorCode}');
|
|
|
@@ -303,37 +304,43 @@ class NetWork { |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reallySingOut() {
|
|
|
|
print('用户登出');
|
|
|
|
//清缓存
|
|
|
|
|
|
|
|
isNormalClose = true;
|
|
|
|
reallyClose();
|
|
|
|
}
|
|
|
|
reallyClose() {
|
|
|
|
|
|
|
|
reallyClose() async{
|
|
|
|
print('清除连接状态');
|
|
|
|
isNormalClose=true;
|
|
|
|
isConnecting = false;
|
|
|
|
isConnect = false;
|
|
|
|
isLogin = false;
|
|
|
|
heartOutCount = 0;
|
|
|
|
sendTimer?.cancel();
|
|
|
|
heartTimer?.cancel();
|
|
|
|
if(iosBgTimer==null){
|
|
|
|
debugPrint('#### ios bg 没有计时器--计时器你启动');
|
|
|
|
iosBgTimer = Timer(Duration(seconds: 20), () async{
|
|
|
|
debugPrint('#### ios bg ios后台关闭socket连接');
|
|
|
|
isNormalClose=true;
|
|
|
|
isConnecting = false;
|
|
|
|
isConnect = false;
|
|
|
|
isLogin = false;
|
|
|
|
heartOutCount = 0;
|
|
|
|
sendTimer?.cancel();
|
|
|
|
heartTimer?.cancel();
|
|
|
|
|
|
|
|
loginTimer?.cancel();
|
|
|
|
print('清除计时器');
|
|
|
|
connectServerTimer?.cancel();
|
|
|
|
loginTimer?.cancel();
|
|
|
|
connectServerTimer?.cancel();
|
|
|
|
|
|
|
|
if (channel != null) {
|
|
|
|
var result = await channel.sink.close();
|
|
|
|
print('result: $result');
|
|
|
|
channel = null;
|
|
|
|
if (channel != null) {
|
|
|
|
await channel.sink.close();
|
|
|
|
channel = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
debugPrint('#### ios bg 已有计时器');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkConnect() {
|
|
|
|
debugPrint(' ios bg 取消计时器');
|
|
|
|
iosBgTimer?.cancel();
|
|
|
|
|
|
|
|
if (isInit && !isConnect && !isConnecting) {
|
|
|
|
reconnect();
|
|
|
|
} else {
|
|
|
@@ -408,7 +415,7 @@ class NetWork { |
|
|
|
//清缓存
|
|
|
|
ChatDataMgr().logout();
|
|
|
|
MsgHandler.clear();
|
|
|
|
|
|
|
|
|
|
|
|
isNormalClose = true;
|
|
|
|
close();
|
|
|
|
}
|
|
|
|