mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
add task manager
This commit is contained in:
1
lib/utils/websocket.dart
Normal file
1
lib/utils/websocket.dart
Normal file
@@ -0,0 +1 @@
|
||||
export './websocket_io.dart' if (dart.library.html) './websocket_web.dart';
|
||||
25
lib/utils/websocket_io.dart
Normal file
25
lib/utils/websocket_io.dart
Normal 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);
|
||||
}
|
||||
6
lib/utils/websocket_web.dart
Normal file
6
lib/utils/websocket_web.dart
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user