add task manager

This commit is contained in:
2024-02-17 15:22:26 +08:00
parent 02b211ab99
commit 7cec3fd320
17 changed files with 430 additions and 21 deletions

1
lib/utils/websocket.dart Normal file
View File

@@ -0,0 +1 @@
export './websocket_io.dart' if (dart.library.html) './websocket_web.dart';

View File

@@ -0,0 +1,25 @@
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import '../globals.dart';
Future<WebSocketChannel> connectWebSocket(Uri uri) async {
final Map<String, String> headers = {};
final jar = cookieJar;
if (jar != null) {
final nuri =Uri(
scheme: uri.scheme == "wss" ? "https" : "http",
userInfo: uri.userInfo,
host: uri.host,
port: uri.port,
path: uri.path,
query: uri.query,
);
final cookies = await jar.loadForRequest(nuri);
final list = <String>[];
for (var cookie in cookies) {
list.add('${cookie.name}=${cookie.value}');
}
headers['cookie'] = list.join('; ');
}
return IOWebSocketChannel.connect(uri, headers: headers);
}

View File

@@ -0,0 +1,6 @@
import 'package:web_socket_channel/html.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
Future<WebSocketChannel> connectWebSocket(Uri uri) async {
return HtmlWebSocketChannel.connect(uri, binaryType: BinaryType.list);
}