Merge branch 'develop_liyi' of http://code.star-lock.cn/StarlockTeam/app-starlock into develop_liyi
# Conflicts: # lib/main/lockMian/lockMain/lockMain_page.dart
This commit is contained in:
commit
5b56557444
@ -12,6 +12,7 @@ import 'package:star_lock/mine/about/debug/debug_tool.dart';
|
||||
import 'package:star_lock/network/api_provider.dart';
|
||||
import 'package:star_lock/network/api_repository.dart';
|
||||
import 'package:star_lock/network/start_chart_api.dart';
|
||||
import 'package:star_lock/talk/startChart/appLifecycle_observer.dart';
|
||||
import 'package:star_lock/tools/bugly/bugly_tool.dart';
|
||||
import 'package:star_lock/tools/device_info_service.dart';
|
||||
import 'package:star_lock/tools/platform_info_services.dart';
|
||||
@ -29,6 +30,10 @@ FutureOr<void> main() async {
|
||||
FlutterBugly.postCatchedException(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// 创建并注册 AppLifecycleObserver(用于程序是否进入后台的监听)
|
||||
AppLifecycleObserver appLifecycleObserver = AppLifecycleObserver();
|
||||
WidgetsBinding.instance.addObserver(appLifecycleObserver);
|
||||
|
||||
await _setCommonServices();
|
||||
|
||||
// 设置国际化信息
|
||||
|
||||
@ -9,6 +9,7 @@ import 'package:star_lock/app_settings/app_colors.dart';
|
||||
import 'package:star_lock/blue/blue_manage.dart';
|
||||
import 'package:star_lock/main/lockMian/lockList/lockList_xhj_page.dart';
|
||||
import 'package:star_lock/main/lockMian/lockMain/lockMain_state.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/talk_request.pb.dart';
|
||||
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||
import 'package:star_lock/tools/noData.dart';
|
||||
import 'package:star_lock/tools/submitBtn.dart';
|
||||
@ -106,6 +107,13 @@ class _StarLockMainPageState extends State<StarLockMainPage>
|
||||
),
|
||||
onPressed: () {
|
||||
Scaffold.of(context).openDrawer();
|
||||
final writeToBuffer = TalkReq(
|
||||
callerName: 'T9A_d9904c8c47c8',
|
||||
callerType: TalkReq_CallerTypeE.Lock)
|
||||
.writeToBuffer();
|
||||
final talkReq = TalkReq.fromBuffer(writeToBuffer);
|
||||
|
||||
print('$talkReq\nwriteToBuffer:$writeToBuffer');
|
||||
},
|
||||
)),
|
||||
backgroundColor: AppColors.mainColor,
|
||||
|
||||
@ -2707,7 +2707,8 @@ class ApiProvider extends BaseProvider {
|
||||
'starchartPeerPublicKey': starchartPeerPublicKey,
|
||||
'starchartPeerPrivateKey': starchartPeerPrivateKey,
|
||||
}),
|
||||
isUnShowLoading: true);
|
||||
isUnShowLoading: true,
|
||||
isShowNetworkErrorMsg: false);
|
||||
}
|
||||
|
||||
extension ExtensionString on String {
|
||||
|
||||
42
lib/talk/startChart/appLifecycle_observer.dart
Normal file
42
lib/talk/startChart/appLifecycle_observer.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||
|
||||
class AppLifecycleObserver extends WidgetsBindingObserver {
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
|
||||
// 打印应用程序生命周期状态
|
||||
print('AppLifecycleState: $state');
|
||||
|
||||
// 根据应用程序状态执行相应的操作
|
||||
if (state == AppLifecycleState.paused) {
|
||||
// 应用程序进入后台
|
||||
onAppPaused();
|
||||
} else if (state == AppLifecycleState.resumed) {
|
||||
// 应用程序恢复到前台
|
||||
onAppResumed();
|
||||
} else if (state == AppLifecycleState.detached) {
|
||||
// 应用程序被杀死
|
||||
onAppDetached();
|
||||
}
|
||||
}
|
||||
|
||||
void onAppPaused() {
|
||||
// 处理应用程序进入后台的逻辑
|
||||
print('App has entered the background.');
|
||||
StartChartManage().destruction();
|
||||
}
|
||||
|
||||
void onAppResumed() {
|
||||
// 处理应用程序恢复到前台的逻辑
|
||||
StartChartManage().init();
|
||||
print('App has resumed to the foreground.');
|
||||
}
|
||||
|
||||
void onAppDetached() {
|
||||
// 处理应用程序被杀死的逻辑
|
||||
StartChartManage().destruction();
|
||||
print('App has been detached.');
|
||||
}
|
||||
}
|
||||
@ -260,7 +260,6 @@ class ScpMessage {
|
||||
} else {
|
||||
throw FormatException("Invalid PayloadLength length");
|
||||
}
|
||||
// print("message result: $message");
|
||||
|
||||
// 处理其他类型的Payload
|
||||
if (message.PayloadLength != null &&
|
||||
@ -526,36 +525,36 @@ class ScpMessage {
|
||||
required List<int> byte,
|
||||
required int payloadType,
|
||||
}) {
|
||||
// print(
|
||||
// '_handleFragmentedPayload spTotal:$spTotal spindex:$spIndex} byte:${byte.take(20)}');
|
||||
// 初始化分包列表
|
||||
if (!_packetBuffer.containsKey(messageId)) {
|
||||
_packetBuffer[messageId] = List.filled(spTotal, []);
|
||||
}
|
||||
|
||||
// 检查分包索引是否在合法范围内
|
||||
if (spIndex < 1 || spIndex > spTotal) {
|
||||
print('Invalid spIndex: $spIndex for messageId: $messageId');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 存储当前分包
|
||||
_packetBuffer[messageId]![spIndex - 1] = byte;
|
||||
|
||||
// 检查是否接收到所有分包
|
||||
if (_packetBuffer[messageId]!.every((packet) => packet.isNotEmpty)) {
|
||||
// 重组所有分包
|
||||
List<int> completePayload =
|
||||
_packetBuffer[messageId]!.expand((packet) => packet).toList();
|
||||
List<int> completePayload = _packetBuffer[messageId]!.expand((packet) => packet).toList();
|
||||
|
||||
// 清除已重组的分包数据
|
||||
_packetBuffer.remove(messageId);
|
||||
|
||||
// 解析完整的 payload
|
||||
if (payloadType == PayloadTypeConstant.talkData) {
|
||||
// 解析完整的 payload
|
||||
final TalkData talkData = TalkData.fromBuffer(completePayload);
|
||||
return talkData;
|
||||
} else {
|
||||
String payload = utf8.decode(completePayload);
|
||||
return payload;
|
||||
}
|
||||
|
||||
return completePayload;
|
||||
|
||||
// 解析完整的 payload
|
||||
// final TalkData talkData = TalkData.fromBuffer(completePayload);
|
||||
// String payload = utf8.decode(completePayload);
|
||||
} else {
|
||||
// 如果分包尚未接收完全,返回 null 或其他指示符
|
||||
return null;
|
||||
|
||||
@ -19,10 +19,11 @@ class UdpEchoTestHandler extends ScpMessageBaseHandle
|
||||
// TODO: 收到回声测试回复
|
||||
final List<int> payload = scpMessage.Payload;
|
||||
|
||||
talkDataRepository.addTalkData(
|
||||
TalkData(content: payload, contentType: TalkData_ContentTypeE.Image));
|
||||
if (payload is String) {
|
||||
EasyLoading.showToast(scpMessage.Payload, duration: 2000.milliseconds);
|
||||
} else {
|
||||
talkDataRepository.addTalkData(
|
||||
TalkData(content: payload, contentType: TalkData_ContentTypeE.Image));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ class StartChartManage {
|
||||
int talkDataIntervalTime = 10; // 通话数据的消息间隔(ms)
|
||||
Timer? talkDataTimer; // 发送通话数据消息定时器
|
||||
|
||||
final int _maxPayloadSize = 1 * 1024; // 分包大小
|
||||
final int _maxPayloadSize = 8 * 1024; // 分包大小
|
||||
|
||||
// 默认通话的期望数据格式
|
||||
TalkExpect defaultTalkExpect = TalkExpect(
|
||||
@ -126,6 +126,7 @@ class StartChartManage {
|
||||
FromPeerId = requestStarChartRegisterNode.peer!.id ?? '';
|
||||
bindUserStarchart();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//绑定星图配置
|
||||
@ -947,12 +948,13 @@ class StartChartManage {
|
||||
|
||||
/// 销毁资源
|
||||
void destruction() async {
|
||||
isOnlineStartChartServer = false;
|
||||
stopTalkExpectMessageTimer();
|
||||
stopTalkPingMessageTimer();
|
||||
stopHeartbeat();
|
||||
stopReStartOnlineStartChartServer();
|
||||
stopTalkDataTimer();
|
||||
await Storage.removerRelayInfo();
|
||||
await Storage.removerStarChartRegisterNodeInfo();
|
||||
// await Storage.removerRelayInfo();
|
||||
// await Storage.removerStarChartRegisterNodeInfo();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user