Reconnect when handling connection errors

This commit is contained in:
SL 2023-08-19 20:26:26 +08:00
parent ab8abdfbbd
commit 6a64a7f145
5 changed files with 15 additions and 6 deletions

View File

@ -1,2 +1,6 @@
### 1.0.0 ### 1.0.0
* first commint * first commint
### 1.0.1
* update connection
### 1.0.2
* Reconnect when handling connection errors

View File

@ -10,7 +10,7 @@
#### 安装 #### 安装
``` ```
dependencies: dependencies:
wukongimfluttersdk: ^1.0.1 wukongimfluttersdk: ^1.0.2
``` ```
#### 引入 #### 引入
```dart ```dart

View File

@ -499,7 +499,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "1.0.1" version: "1.0.2"
x25519: x25519:
dependency: transitive dependency: transitive
description: description:

View File

@ -32,11 +32,12 @@ class _WKSocket {
} }
} }
void listen(void Function(Uint8List data) onData) { void listen(void Function(Uint8List data) onData, void Function() error) {
_socket.listen(onData, onError: (err) { _socket.listen(onData, onError: (err) {
Logs.debug('socket断开了${err.toString()}'); Logs.debug('socket断开了${err.toString()}');
}, onDone: () { }, onDone: () {
Logs.debug('socketonDone'); Logs.debug('socketonDone');
error();
}); });
} }
} }
@ -126,6 +127,11 @@ class WKConnectionManager {
_socket?.listen((Uint8List data) { _socket?.listen((Uint8List data) {
_cutDatas(data); _cutDatas(data);
// _decodePacket(data); // _decodePacket(data);
}, () {
isReconnection = true;
Future.delayed(const Duration(milliseconds: 1500), () {
connect();
});
}); });
// //
_sendConnectPacket(); _sendConnectPacket();
@ -205,7 +211,6 @@ class WKConnectionManager {
} }
_decodePacket(Uint8List data) { _decodePacket(Uint8List data) {
Logs.debug("收到数据->$data");
var packet = WKIM.shared.options.proto.decode(data); var packet = WKIM.shared.options.proto.decode(data);
Logs.debug('解码出包->$packet'); Logs.debug('解码出包->$packet');
if (packet.header.packetType == PacketType.connack) { if (packet.header.packetType == PacketType.connack) {

View File

@ -15,7 +15,7 @@ description: wukong IM flutter sdk
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # 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 # 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. # of the product and file versions while build-number is used as the build suffix.
version: 1.0.1 version: 1.0.2
homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK
environment: environment: