2024-12-24 10:50:32 +08:00
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
2024-12-04 15:00:56 +08:00
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
2024-12-24 10:50:32 +08:00
|
|
|
|
import 'package:star_lock/talk/startChart/constant/message_type_constant.dart';
|
2024-12-04 15:00:56 +08:00
|
|
|
|
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/startChart/handle/scp_message_base_handle.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/startChart/handle/scp_message_handle.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
|
|
|
|
|
import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
|
2024-12-24 10:50:32 +08:00
|
|
|
|
import 'package:star_lock/talk/startChart/proto/talk_accept.pb.dart';
|
2024-12-04 15:00:56 +08:00
|
|
|
|
|
|
|
|
|
|
import '../../start_chart_manage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class UdpTalkAcceptHandler extends ScpMessageBaseHandle
|
|
|
|
|
|
implements ScpMessageHandler {
|
2024-12-09 09:22:58 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void handleReq(ScpMessage scpMessage) {
|
2024-12-09 11:06:35 +08:00
|
|
|
|
print('收到同意接听请求');
|
|
|
|
|
|
// 回复同意接听消息
|
|
|
|
|
|
startChartManage.sendGenericRespSuccessMessage(
|
|
|
|
|
|
ToPeerId: scpMessage.FromPeerId!,
|
|
|
|
|
|
FromPeerId: scpMessage.ToPeerId!,
|
|
|
|
|
|
PayloadType: scpMessage.PayloadType!,
|
|
|
|
|
|
);
|
2024-12-09 09:22:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-04 15:00:56 +08:00
|
|
|
|
@override
|
2024-12-24 10:50:32 +08:00
|
|
|
|
void handleResp(ScpMessage scpMessage) {
|
2024-12-09 11:06:35 +08:00
|
|
|
|
// 收到同意接听回复
|
2024-12-04 15:00:56 +08:00
|
|
|
|
final GenericResp genericResp = scpMessage.Payload;
|
|
|
|
|
|
if (checkGenericRespSuccess(genericResp)) {
|
2024-12-24 15:38:36 +08:00
|
|
|
|
// 启动发送预期数据请求
|
|
|
|
|
|
_handleStartSendTalkExpectDataRequest();
|
2024-12-24 14:21:49 +08:00
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
2024-12-24 15:38:36 +08:00
|
|
|
|
print('启动定时器判断');
|
2024-12-19 14:48:19 +08:00
|
|
|
|
// 启动通话保持定时器
|
|
|
|
|
|
_handleStartTalkPing();
|
2024-12-12 11:41:54 +08:00
|
|
|
|
// 启动通话数据检查的定时器
|
|
|
|
|
|
_handleCheckTalkDataTimer();
|
|
|
|
|
|
});
|
2024-12-10 18:26:47 +08:00
|
|
|
|
// 停止播放铃声
|
|
|
|
|
|
stopRingtone();
|
2024-12-09 12:05:34 +08:00
|
|
|
|
// 设置状态为接听中
|
2024-12-16 16:04:41 +08:00
|
|
|
|
talkStatus.setAnsweredSuccessfully();
|
2024-12-09 12:05:34 +08:00
|
|
|
|
talkStatus.setDuringCall();
|
2024-12-04 15:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-09 09:22:58 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
2024-12-12 11:41:54 +08:00
|
|
|
|
void handleInvalidReq(ScpMessage scpMessage) {}
|
2024-12-09 09:22:58 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
2024-12-12 11:41:54 +08:00
|
|
|
|
void handleRealTimeData(ScpMessage scpMessage) {}
|
2024-12-09 11:06:35 +08:00
|
|
|
|
|
2024-12-24 10:50:32 +08:00
|
|
|
|
@override
|
|
|
|
|
|
deserializePayload(
|
|
|
|
|
|
{required int payloadType,
|
2024-12-24 14:21:49 +08:00
|
|
|
|
required int messageType,
|
|
|
|
|
|
required Uint8List byte,
|
|
|
|
|
|
int? offset,
|
|
|
|
|
|
int? PayloadLength,
|
|
|
|
|
|
int? spTotal,
|
|
|
|
|
|
int? spIndex,
|
|
|
|
|
|
int? messageId}) {
|
2024-12-24 10:50:32 +08:00
|
|
|
|
if (messageType == MessageTypeConstant.Resp) {
|
|
|
|
|
|
final GenericResp genericResp = GenericResp();
|
|
|
|
|
|
genericResp.mergeFromBuffer(byte);
|
|
|
|
|
|
return genericResp;
|
|
|
|
|
|
} else if (messageType == MessageTypeConstant.Req) {
|
|
|
|
|
|
final TalkAcceptReq talkAccept = TalkAcceptReq();
|
|
|
|
|
|
talkAccept.mergeFromBuffer(byte);
|
|
|
|
|
|
return talkAccept;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String payload = utf8.decode(byte);
|
|
|
|
|
|
return payload;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-24 15:38:36 +08:00
|
|
|
|
// 启动通话保持,判断x秒内是否收到通话保持
|
2024-12-09 11:06:35 +08:00
|
|
|
|
void _handleStartTalkPing() {
|
|
|
|
|
|
// 启动通话保持
|
|
|
|
|
|
startChartManage.startTalkPingMessageTimer();
|
|
|
|
|
|
// 启动通话保持监听定时器(用来判断如果x秒内没有收到通话保持则执行的操作)
|
|
|
|
|
|
talkePingOverTimeTimerManager.startTimer();
|
|
|
|
|
|
// 设置通话保持超时后的事件
|
|
|
|
|
|
talkePingOverTimeTimerManager.setOnTimeout(() {
|
|
|
|
|
|
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
|
|
|
|
|
|
// 停止发送通话保持的命令
|
|
|
|
|
|
startChartManage.stopTalkPingMessageTimer();
|
|
|
|
|
|
startChartManage.stopTalkExpectMessageTimer();
|
2024-12-09 12:05:34 +08:00
|
|
|
|
talkStatus.setNotTalkPing();
|
2024-12-11 09:32:51 +08:00
|
|
|
|
talkStatus.setEnd();
|
2024-12-09 11:06:35 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 启动通话数据的检查,判断x秒内是否收到通话数据
|
|
|
|
|
|
void _handleCheckTalkDataTimer() {
|
|
|
|
|
|
// 启动对讲数据监听定时器
|
|
|
|
|
|
talkDataOverTimeTimerManager.startTimer();
|
|
|
|
|
|
// 设置对讲数据超时后的事件
|
|
|
|
|
|
talkDataOverTimeTimerManager.setOnTimeout(() {
|
|
|
|
|
|
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
|
|
|
|
|
|
startChartManage.stopTalkPingMessageTimer();
|
|
|
|
|
|
startChartManage.stopTalkExpectMessageTimer();
|
2024-12-09 12:05:34 +08:00
|
|
|
|
talkStatus.setNotTalkData();
|
2024-12-11 09:32:51 +08:00
|
|
|
|
talkStatus.setEnd();
|
2024-12-09 11:06:35 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 启动发送预期数据请求
|
|
|
|
|
|
void _handleStartSendTalkExpectDataRequest() {
|
|
|
|
|
|
// 启动发送预期数据定时器
|
|
|
|
|
|
startChartManage.startTalkExpectTimer();
|
|
|
|
|
|
}
|
2024-12-04 15:00:56 +08:00
|
|
|
|
}
|