Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-byte committed Dec 1, 2023
1 parent 8a555c4 commit 3a4d8aa
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 89 deletions.
25 changes: 0 additions & 25 deletions .vscode/launch.json

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"DockerRun.DisableDockerrc": true
}
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189

COCOAPODS: 1.11.2
COCOAPODS: 1.14.3
34 changes: 17 additions & 17 deletions example/lib/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,23 @@ class ChatListDataState extends State<ChatList> {
padding: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 5),
child: Row(
children: [
Container(
decoration: const BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(20)),
color: Color.fromARGB(255, 215, 80, 1)),
width: 50,
alignment: Alignment.center,
height: 50,
margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),
child: Text(
CommonUtils.getAvatar(uiMsg.wkMsg.fromUID),
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
// Container(
// decoration: const BoxDecoration(
// shape: BoxShape.rectangle,
// borderRadius: BorderRadius.all(Radius.circular(20)),
// color: Color.fromARGB(255, 215, 80, 1)),
// width: 50,
// alignment: Alignment.center,
// height: 50,
// margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),
// child: Text(
// CommonUtils.getAvatar(uiMsg.wkMsg.fromUID),
// style: const TextStyle(
// color: Colors.white,
// fontSize: 20,
// fontWeight: FontWeight.bold),
// ),
// ),
Expanded(
child: Container(
alignment: Alignment.centerLeft,
Expand Down
2 changes: 0 additions & 2 deletions example/lib/im.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ffi';

import 'package:example/const.dart';
import 'package:wukongimfluttersdk/common/options.dart';
import 'package:wukongimfluttersdk/entity/channel.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/lib/input_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _InputDialogState extends State<InputDialog> {
children: [
TextField(
controller: _textEditingController,
maxLength: 12,
maxLength: 120,
onChanged: (v) {
channelID = v;
},
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.11.2
COCOAPODS: 1.14.3
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
44 changes: 18 additions & 26 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.18.0"
version: "1.17.1"
connectivity:
dependency: transitive
description:
Expand Down Expand Up @@ -244,26 +244,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.16"
version: "0.12.15"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.0"
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
version: "1.9.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -385,10 +385,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
version: "1.9.1"
sqflite:
dependency: transitive
description:
Expand All @@ -409,18 +409,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -449,10 +449,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.1"
version: "0.5.1"
typed_data:
dependency: transitive
description:
Expand All @@ -477,14 +477,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -507,7 +499,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.8"
version: "1.1.9"
x25519:
dependency: transitive
description:
Expand All @@ -525,5 +517,5 @@ packages:
source: hosted
version: "1.0.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.0.6 <4.0.0"
flutter: ">=3.3.0"
45 changes: 31 additions & 14 deletions lib/manager/connect_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,44 @@ import '../proto/proto.dart';
import '../type/const.dart';

class _WKSocket {
final Socket _socket;
_WKSocket.newSocket(this._socket);
Socket? _socket; // 将 _socket 声明为可空类型
bool _isListening = false;
static _WKSocket? _instance;

_WKSocket._internal(this._socket);

factory _WKSocket.newSocket(Socket socket) {
_instance ??= _WKSocket._internal(socket);
return _instance!;
}

void close() {
_socket.close();
_socket?.close();
_isListening = false;
_socket = null; // 现在可以将 _socket 设置为 null
_instance = null;
}

void send(Uint8List data) {
try {
print('发消息');
_socket.add(data);
_socket.flush();
_socket?.add(data); // 使用安全调用操作符
_socket?.flush();
} catch (e) {
Logs.debug('发送消息错误');
Logs.debug('发送消息错误$e');
}
}

void listen(void Function(Uint8List data) onData, void Function() error) {
_socket.listen(onData, onError: (err) {
Logs.debug('socket断开了${err.toString()}');
}, onDone: () {
Logs.debug('socketonDone');
error();
});
if (!_isListening && _socket != null) {
_socket!.listen(onData, onError: (err) {
Logs.debug('socket断开了${err.toString()}');
}, onDone: () {
Logs.debug('socketonDone');
error();
close(); // 关闭和重置 Socket 连接
});
_isListening = true;
}
}
}

Expand Down Expand Up @@ -145,7 +160,7 @@ class WKConnectionManager {
return;
}
isReconnection = true;
Logs.error('发送消息失败');
Logs.error('发送消息失败$_isLogout');
Future.delayed(Duration(milliseconds: reconnMilliseconds), () {
connect();
});
Expand All @@ -155,7 +170,9 @@ class WKConnectionManager {
}

_connectFail(error) {
// _socket?.close();
Logs.error('连接失败:${error.toString()}');
print(error);
Future.delayed(Duration(milliseconds: reconnMilliseconds), () {
connect();
});
Expand Down

0 comments on commit 3a4d8aa

Please sign in to comment.