fix:调整挂断后的逻辑、增加账号未登录时不初始化星图逻辑、增加修改预期接收数据方法

This commit is contained in:
liyi 2025-01-02 10:27:40 +08:00
parent 13e3839d67
commit 25bbd0cd19

View File

@ -9,6 +9,7 @@ import 'package:get/get.dart';
import 'package:pointycastle/export.dart' as pc;
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/login/login/entity/LoginData.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/network/start_chart_api.dart';
@ -24,6 +25,9 @@ import 'package:star_lock/talk/startChart/entity/report_information_data.dart';
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
import 'package:star_lock/talk/startChart/entity/star_chart_register_node_entity.dart';
import 'package:star_lock/talk/startChart/exception/start_chart_message_exception.dart';
import 'package:star_lock/talk/startChart/handle/other/talke_data_over_time_timer_manager.dart';
import 'package:star_lock/talk/startChart/handle/other/talke_ping_over_time_timer_manager.dart';
import 'package:star_lock/talk/startChart/handle/other/talke_request_over_time_timer_manager.dart';
import 'package:star_lock/talk/startChart/handle/scp_message_handle.dart';
import 'package:star_lock/talk/startChart/handle/scp_message_handler_factory.dart';
import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart';
@ -44,6 +48,12 @@ class StartChartManage {
//
static final StartChartManage _instance = StartChartManage._internal();
final TalkeRequestOverTimeTimerManager talkeRequestOverTimeTimerManager =
TalkeRequestOverTimeTimerManager();
final TalkePingOverTimeTimerManager talkePingOverTimeTimerManager =
TalkePingOverTimeTimerManager();
final TalkDataOverTimeTimerManager talkDataOverTimeTimerManager =
TalkDataOverTimeTimerManager();
//
factory StartChartManage() {
@ -80,6 +90,7 @@ class StartChartManage {
Timer? talkPingTimer; //
int talkExpectIntervalTime = 1; // (s)
Timer? talkExpectTimer; //
Timer? talkAcceptTimer; //
int talkDataIntervalTime = 10; // (ms)
Timer? talkDataTimer; //
@ -101,12 +112,15 @@ class StartChartManage {
//
Future<void> init() async {
if (isOnlineStartChartServer && _udpSocket != null) {
//
final loginData = await Storage.getLoginData();
if ((isOnlineStartChartServer && _udpSocket != null) || loginData == null) {
// 线
return;
}
//
await _clientRegister();
await _clientRegister(loginData);
//
await _relayQuery();
// udp服务
@ -116,12 +130,10 @@ class StartChartManage {
}
///
Future<void> _clientRegister() async {
final StarChartRegisterNodeEntity? registerNodeEntity =
await Storage.getStarChartRegisterNodeInfo();
if (registerNodeEntity != null && registerNodeEntity.peer?.id != null) {
_log(text: '获取到星图注册节点信息:$registerNodeEntity');
FromPeerId = registerNodeEntity.peer!.id ?? '';
Future<void> _clientRegister(LoginData? loginData) async {
if (loginData?.starchart?.starchartId != null) {
_log(text: '获取到星图注册节点信息:${loginData?.starchart}');
FromPeerId = loginData?.starchart?.starchartId ?? '';
} else {
_log(text: '开始注册客户端');
final StarChartRegisterNodeEntity requestStarChartRegisterNode =
@ -143,6 +155,8 @@ class StartChartManage {
starchartPeerPublicKey: registerNodeEntity?.peer?.publicKey ?? '',
starchartPeerPrivateKey: registerNodeEntity?.peer?.privateKey ?? '',
);
registerNodeEntity?.peer?.id = entity.data?.starchart?.starchartId;
await Storage.saveStarChartRegisterNodeInfo(registerNodeEntity!);
if (entity.errorCode!.codeIsSuccessful) {
AppLog.log('绑定成功');
} else {
@ -237,7 +251,7 @@ class StartChartManage {
//
Future<void> sendCallRequestMessage({required String ToPeerId}) async {
if (talkStatus.status == TalkStatus.duringCall) {
if (talkStatus.status == TalkStatus.answeredSuccessfully) {
_log(text: '已经在通话中,请勿重复发送对讲请求');
return;
}
@ -364,23 +378,13 @@ class StartChartManage {
//
void sendTalkAcceptMessage() async {
if (talkStatus.status == TalkStatus.duringCall) {
_log(text: '已经在通话中,请勿重复发送同意接听消息');
return;
}
if (talkStatus.status != TalkStatus.waitingAnswer) {
_log(text: '当前未处于等待接听状态, 无法发送同意接听消息');
return;
}
final message = MessageCommand.talkAcceptMessage(
ToPeerId: ToPeerId,
FromPeerId: FromPeerId,
MessageId: MessageCommand.getNextMessageId(ToPeerId, increment: true),
);
await _sendMessage(message: message);
//
talkStatus.setWaitingAnswer();
// _log(text: '发送同意接听消息');
stopTalkExpectMessageTimer();
}
//
@ -400,6 +404,11 @@ class StartChartManage {
StartChartTalkStatus.instance.setRejected();
//
AudioPlayerManager().stopRingtone();
//
stopTalkExpectMessageTimer();
stopTalkPingMessageTimer();
//
talkePingOverTimeTimerManager.cancel();
}
//
@ -456,7 +465,7 @@ class StartChartManage {
//
Future<void> sendTalkHangupMessage() async {
if (talkStatus.status != TalkStatus.duringCall) {
if (talkStatus.status != TalkStatus.answeredSuccessfully) {
_log(text: '当前未处于接听状态, 无法发送通话中挂断消息');
return;
}
@ -471,6 +480,11 @@ class StartChartManage {
StartChartTalkStatus.instance.setHangingUpDuring();
//
AudioPlayerManager().stopRingtone();
//
stopTalkExpectMessageTimer();
stopTalkPingMessageTimer();
//
talkePingOverTimeTimerManager.cancel();
}
// 线
@ -799,17 +813,21 @@ class StartChartManage {
///
Future<String> getPublicKey() async {
//
final StarChartRegisterNodeEntity? starChartRegisterNodeInfo =
await Storage.getStarChartRegisterNodeInfo();
return starChartRegisterNodeInfo?.peer?.publicKey ?? '';
// final StarChartRegisterNodeEntity? starChartRegisterNodeInfo =
// await Storage.getStarChartRegisterNodeInfo();
// return starChartRegisterNodeInfo?.peer?.publicKey ?? '';
final loginData = await Storage.getLoginData();
return loginData?.starchart?.starchartPeerPublicKey ?? '';
}
///
Future<String> getPrivateKey() async {
//
final StarChartRegisterNodeEntity? starChartRegisterNodeInfo =
await Storage.getStarChartRegisterNodeInfo();
return starChartRegisterNodeInfo?.peer?.privateKey ?? '';
// final StarChartRegisterNodeEntity? starChartRegisterNodeInfo =
// await Storage.getStarChartRegisterNodeInfo();
// return starChartRegisterNodeInfo?.peer?.privateKey ?? '';
final loginData = await Storage.getLoginData();
return loginData?.starchart?.starchartPeerPrivateKey ?? '';
}
//
@ -895,6 +913,23 @@ class StartChartManage {
);
}
///
void startTalkAcceptTimer() {
talkAcceptTimer ??= Timer.periodic(
Duration(
seconds: talkExpectIntervalTime,
),
(Timer timer) {
sendTalkAcceptMessage();
},
);
}
void stopTalkAcceptTimer() {
talkAcceptTimer?.cancel();
talkAcceptTimer = null; //
}
///
void startTalkDataTimer() async {
//
@ -1010,22 +1045,44 @@ class StartChartManage {
}
///
void changeTalkExpectDataType({required TalkExpectReq talkExpect}) {
void changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(
{required TalkExpectReq talkExpect}) {
_defaultTalkExpect = talkExpect;
reStartTalkExpectMessageTimer();
}
///
void sendOnlyImageVideoTalkExpectData() {
final talkExpectReq = TalkExpectReq(
videoType: [VideoTypeE.IMAGE],
audioType: [],
);
changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(
talkExpect: talkExpectReq);
}
///
void sendImageVideoAndG711AudioTalkExpectData() {
final talkExpectReq = TalkExpectReq(
videoType: [VideoTypeE.IMAGE],
audioType: [AudioTypeE.G711],
);
changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(
talkExpect: talkExpectReq);
}
///
void destruction() async {
isOnlineStartChartServer = false;
stopHeartbeat();
stopTalkExpectMessageTimer();
stopTalkPingMessageTimer();
stopHeartbeat();
stopReStartOnlineStartChartServer();
stopTalkDataTimer();
_resetData();
// await Storage.removerRelayInfo();
// await Storage.removerStarChartRegisterNodeInfo();
await Storage.removerRelayInfo();
await Storage.removerStarChartRegisterNodeInfo();
}
void _resetData() {