Browse Source

socketclient remove reconnect time

wr_202303
zsw 4 months ago
parent
commit
0fb67d8cf0
  1. 32
      lib/im/SocketClient.dart

32
lib/im/SocketClient.dart

@ -66,10 +66,12 @@ class SocketClient {
}).catchError((error) {
debugPrint("socket-connect-error: $error");
showDebugToast("socket-connect-error: $error");
reconnectTime = 1500;
_socket = null;
reconnect();
});
// checkConnect();
}
showDebugToast(text) {
@ -89,17 +91,19 @@ class SocketClient {
timer.cancel();
return;
}
_socket.add(proto2.toBytes());
try {
_socket.add(proto2.toBytes());
} catch (e) {
debugPrint("socket-send-error: ${e.toString()}");
showDebugToast("socket-send-error: ${e.toString()}");
reconnect();
}
});
}
int reconnectTime = 1500;
reconnect() {
Future.delayed(Duration(milliseconds: reconnectTime), () {
dispose();
connect();
});
dispose();
connect();
}
Map<String, Function(Message message)> callbacks = <String, Function(Message message)>{};
@ -149,14 +153,22 @@ class SocketClient {
Uint8List data = utf8.encode(content);
MsgData msgData = MsgData(to: toId, from: userId, type: MsgType.TEXT, data: data);
final proto2 = Proto(5, 1, msgData.writeToBuffer());
_socket.add(proto2.toBytes());
try {
_socket.add(proto2.toBytes());
} catch (e) {
hxDatabase.update({"id": id, "state": 3}).catchError((error) {
debugPrint("insertMessage: ${error.toString()}");
});
debugPrint("socket-send-error: ${e.toString()}");
showDebugToast("socket-send-error: ${e.toString()}");
reconnect();
}
debugPrint("sendMessage: ${message["id"]}");
return Message.fromJson(message);
}
checkSocket() {
if (_socket == null) {
reconnectTime = 1000;
reconnect();
return false;
}

Loading…
Cancel
Save