app-starlock/lib/talk/startChart/handle/impl/udp_talk_accept_handler.dart

87 lines
3.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
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';
import '../../start_chart_manage.dart';
class UdpTalkAcceptHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
@override
void handleReq(ScpMessage scpMessage) {
print('收到同意接听请求');
// 回复同意接听消息
startChartManage.sendGenericRespSuccessMessage(
ToPeerId: scpMessage.FromPeerId!,
FromPeerId: scpMessage.ToPeerId!,
PayloadType: scpMessage.PayloadType!,
);
}
@override
void handleResp(ScpMessage scpMessage) {
// 收到同意接听回复
final GenericResp genericResp = scpMessage.Payload;
if (checkGenericRespSuccess(genericResp)) {
// 启动通话保持定时器
_handleStartTalkPing();
Future.delayed(Duration(seconds: 2), () {
// 启动发送预期数据请求
_handleStartSendTalkExpectDataRequest();
// 启动通话数据检查的定时器
_handleCheckTalkDataTimer();
});
// 停止播放铃声
stopRingtone();
// 设置状态为接听中
talkStatus.setDuringCall();
}
}
@override
void handleInvalidReq(ScpMessage scpMessage) {}
@override
void handleRealTimeData(ScpMessage scpMessage) {}
// 启动通话保持
void _handleStartTalkPing() {
// 启动通话保持
startChartManage.startTalkPingMessageTimer();
// 启动通话保持监听定时器用来判断如果x秒内没有收到通话保持则执行的操作
talkePingOverTimeTimerManager.startTimer();
// 设置通话保持超时后的事件
talkePingOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
// 停止发送通话保持的命令
startChartManage.stopTalkPingMessageTimer();
startChartManage.stopTalkExpectMessageTimer();
talkStatus.setNotTalkPing();
talkStatus.setEnd();
});
}
/// 启动通话数据的检查判断x秒内是否收到通话数据
void _handleCheckTalkDataTimer() {
// 启动对讲数据监听定时器
talkDataOverTimeTimerManager.startTimer();
// 设置对讲数据超时后的事件
talkDataOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
startChartManage.stopTalkPingMessageTimer();
startChartManage.stopTalkExpectMessageTimer();
talkStatus.setNotTalkData();
talkStatus.setEnd();
});
}
/// 启动发送预期数据请求
void _handleStartSendTalkExpectDataRequest() {
// 启动发送预期数据定时器
startChartManage.startTalkExpectTimer();
}
}