Skip to content

Commit df9f08a

Browse files
committed
refactor: improve connection handling and file service logic
- remove handleTokenCheck - rename /chenk_token to /ping - replace file_selector with file_picker on Android - rename ChatServer back to ChatService - simplify FileService port handling - fix device connection and JoinMessage logic - support mouse back navigation - request Android file management permission
1 parent debf9f7 commit df9f08a

25 files changed

Lines changed: 641 additions & 551 deletions

android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="com.nightmare.fastshare">
34

45
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
7+
tools:ignore="AllFilesAccessPolicy,ScopedStorage" />
58
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
69
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
710
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

lib/common/config.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ class Config {
33
// 下面两个端口是单个文件部署用到的端口
44
static int shelfPortRangeStart = 13000;
55
static int shelfPortRangeEnd = 13010;
6-
// 下面两个端口是文件服务器用到的端口,主要用来web上传文件到客户端
7-
static int filePortRangeStart = 13010;
8-
static int filePortRangeEnd = 13020;
96
// 下面两个是聊天服务器的端口
107
static int chatPortRangeStart = 12000;
118
static int chatPortRangeEnd = 12010;

lib/common/device.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'device_type.dart';
2+
3+
class Device {
4+
Device(
5+
this.id, {
6+
this.deviceType,
7+
this.deviceName,
8+
this.url,
9+
this.messagePort,
10+
});
11+
String? id;
12+
DeviceType? deviceType;
13+
String? deviceName;
14+
// url prefix
15+
String? url;
16+
int? messagePort;
17+
bool isAlive = true;
18+
19+
/// 当一个新的设备连接到当前设备的时候,需要回一个连接消息。
20+
///
21+
/// 用来处理 UDP 广播只有 A -> B,没有 B -> A 的情况,
22+
/// 导致 A 的连接列表没有 B。
23+
///
24+
/// 这个在设备心跳包没有收到的情况下,会再次置为 false。
25+
///
26+
/// 保证:
27+
/// A 启动 -> B 启动 -> A 连过 B -> A 关闭 -> A 再打开
28+
/// 即使只有 B 连过 A,B 依然会主动给 A 发送连接消息。
29+
///
30+
/// When a new device connects to the current device, a connection message needs to be sent back.
31+
///
32+
/// This is used to handle the situation where there is only A -> B in UDP broadcast, and no B -> A, which leads to A's connection list not having B.
33+
/// This will be set to false again when the device heartbeat is not received.
34+
///
35+
/// Ensure:
36+
/// A starts -> B starts -> A connects to B -> A closes -> A opens again
37+
/// Even if only B connects to A, B will still actively send a connection message to A.
38+
bool sendedJoinMessage = false;
39+
40+
/// 防止重复发送,因为时序的问题,A 可能会收到两次 B 的 JoinMessage
41+
///
42+
/// Prevent duplicate sending, because of the timing issue, A may receive B's JoinMessage twice.
43+
bool sendedHistoryMessage = false;
44+
45+
@override
46+
int get hashCode => id.hashCode;
47+
48+
@override
49+
bool operator ==(Object other) {
50+
if (other is Device) {
51+
return id == other.id;
52+
}
53+
return false;
54+
}
55+
56+
@override
57+
String toString() {
58+
return 'id:$id deviceType:$deviceType deviceName:$deviceName address:$url';
59+
}
60+
}

0 commit comments

Comments
 (0)