mirror of
https://github.com/WuKongIM/WuKongIMFlutterSDK
synced 2025-05-24 02:42:20 +00:00
fix: 优化在未收到服务端心跳消息时主动断开重连
This commit is contained in:
parent
d701e293f4
commit
c0bb596c6a
@ -123,4 +123,6 @@
|
||||
### 1.6.1
|
||||
* fix: 修复网络切换时有时无法连接问题
|
||||
### 1.6.2
|
||||
* fix: 修改数据库解码错误数据导致oom
|
||||
* fix: 修改数据库解码错误数据导致oom
|
||||
### 1.6.3
|
||||
* fix: 优化在未收到服务端心跳消息时主动断开重连
|
@ -81,6 +81,7 @@ class WKConnectionManager {
|
||||
Timer? checkNetworkTimer;
|
||||
final heartIntervalSecond = const Duration(seconds: 60);
|
||||
final checkNetworkSecond = const Duration(seconds: 1);
|
||||
int unReceivePongCount = 0;
|
||||
final LinkedHashMap<int, SendingMsg> _sendingMsgMap = LinkedHashMap();
|
||||
HashMap<String, Function(int, int?, ConnectionInfo?)>? _connectionListenerMap;
|
||||
_WKSocket? _socket;
|
||||
@ -229,6 +230,7 @@ class WKConnectionManager {
|
||||
var packetType = b >> 4;
|
||||
if (PacketType.values[(b >> 4)] == PacketType.pong) {
|
||||
Logs.debug('pong');
|
||||
unReceivePongCount = 0;
|
||||
Uint8List bytes = lastMsgBytes.sublist(1, lastMsgBytes.length);
|
||||
_cacheData = lastMsgBytes = bytes;
|
||||
} else {
|
||||
@ -273,6 +275,7 @@ class WKConnectionManager {
|
||||
_decodePacket(Uint8List data) {
|
||||
var packet = WKIM.shared.options.proto.decode(data);
|
||||
Logs.debug('解码出包->$packet');
|
||||
unReceivePongCount = 0;
|
||||
if (packet.header.packetType == PacketType.connack) {
|
||||
var connackPacket = packet as ConnackPacket;
|
||||
if (connackPacket.reasonCode == 1) {
|
||||
@ -414,7 +417,14 @@ class WKConnectionManager {
|
||||
_startHeartTimer() {
|
||||
_stopHeartTimer();
|
||||
heartTimer = Timer.periodic(heartIntervalSecond, (timer) {
|
||||
if (unReceivePongCount > 0) {
|
||||
Logs.debug('心跳包未收到pong,重连中...');
|
||||
isReconnection = false;
|
||||
connect();
|
||||
return;
|
||||
}
|
||||
Logs.info('ping...');
|
||||
unReceivePongCount++;
|
||||
_sendPacket(PingPacket());
|
||||
});
|
||||
}
|
||||
|
16
pubspec.lock
16
pubspec.lock
@ -549,22 +549,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web_socket
|
||||
sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.6"
|
||||
web_socket_channel:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: web_socket_channel
|
||||
sha256: "0b8e2457400d8a859b7b2030786835a28a8e80836ef64402abef392ff4f1d0e5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
x25519:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -15,7 +15,7 @@ description: wukong IM flutter sdk
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.6.2
|
||||
version: 1.6.3
|
||||
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
|
||||
|
||||
environment:
|
||||
@ -41,7 +41,6 @@ dependencies:
|
||||
hex: ^0.2.0
|
||||
crypto: ^3.0.6
|
||||
uuid: ^4.3.3
|
||||
web_socket_channel: ^3.0.1
|
||||
dio: ^5.3.2
|
||||
shared_preferences: ^2.2.0
|
||||
sqflite: ^2.4.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user