fix:调整定时器超时逻辑
This commit is contained in:
parent
63501088e1
commit
13e3839d67
7
lib/talk/startChart/constant/talk_constant.dart
Normal file
7
lib/talk/startChart/constant/talk_constant.dart
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class TalkConstant {
|
||||||
|
// TalkPing 未收到回复超时时间(s)
|
||||||
|
static const int talkePingOverTime = 6;
|
||||||
|
static const int talkeDataOverTime = 6;
|
||||||
|
// 收到TalkRequest 未处理超时时间(s)
|
||||||
|
static const int talkeRequestOverTime = 30;
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|||||||
import 'package:flutter_pcm_sound/flutter_pcm_sound.dart';
|
import 'package:flutter_pcm_sound/flutter_pcm_sound.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:star_lock/talk/startChart/constant/message_type_constant.dart';
|
import 'package:star_lock/talk/startChart/constant/message_type_constant.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_status.dart';
|
||||||
import 'package:star_lock/talk/startChart/entity/scp_message.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_base_handle.dart';
|
||||||
import 'package:star_lock/talk/startChart/handle/scp_message_handle.dart';
|
import 'package:star_lock/talk/startChart/handle/scp_message_handle.dart';
|
||||||
@ -24,24 +25,26 @@ class UdpTalkAcceptHandler extends ScpMessageBaseHandle
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void handleResp(ScpMessage scpMessage) {
|
void handleResp(ScpMessage scpMessage) {
|
||||||
|
if (talkStatus.status != TalkStatus.waitingAnswer) {
|
||||||
|
// 如果不是等待接听状态,则不处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 收到同意接听回复
|
// 收到同意接听回复
|
||||||
final GenericResp genericResp = scpMessage.Payload;
|
final GenericResp genericResp = scpMessage.Payload;
|
||||||
if (checkGenericRespSuccess(genericResp)) {
|
if (checkGenericRespSuccess(genericResp)) {
|
||||||
Future.delayed(Duration(seconds: 1), () {
|
// 启动通话保持定时器
|
||||||
// 启动通话保持定时器
|
_handleStartTalkPing();
|
||||||
_handleStartTalkPing();
|
// 启动发送预期数据请求
|
||||||
// 启动发送预期数据请求
|
_handleStartSendTalkExpectDataRequest();
|
||||||
_handleStartSendTalkExpectDataRequest();
|
// 启动通话数据检查的定时器
|
||||||
// 启动通话数据检查的定时器
|
// _handleCheckTalkDataTimer();
|
||||||
_handleCheckTalkDataTimer();
|
|
||||||
});
|
|
||||||
// 停止播放铃声
|
// 停止播放铃声
|
||||||
stopRingtone();
|
stopRingtone();
|
||||||
// 设置状态为接听成功
|
// 设置状态为接听成功
|
||||||
talkStatus.setAnsweredSuccessfully();
|
talkStatus.setAnsweredSuccessfully();
|
||||||
// 同意接听之后,停止对讲请求超时监听定时器
|
// // 同意接听之后,停止对讲请求超时监听定时器
|
||||||
talkeRequestOverTimeTimerManager.receiveMessage();
|
// talkeRequestOverTimeTimerManager.renewTimer();
|
||||||
talkeRequestOverTimeTimerManager.dispose();
|
// talkeRequestOverTimeTimerManager.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,30 +83,13 @@ class UdpTalkAcceptHandler extends ScpMessageBaseHandle
|
|||||||
// 启动通话保持
|
// 启动通话保持
|
||||||
startChartManage.startTalkPingMessageTimer();
|
startChartManage.startTalkPingMessageTimer();
|
||||||
// 启动通话保持监听定时器(用来判断如果x秒内没有收到通话保持则执行的操作)
|
// 启动通话保持监听定时器(用来判断如果x秒内没有收到通话保持则执行的操作)
|
||||||
talkePingOverTimeTimerManager.startTimer();
|
talkePingOverTimeTimerManager.start();
|
||||||
// 设置通话保持超时后的事件
|
|
||||||
talkePingOverTimeTimerManager.setOnTimeout(() {
|
|
||||||
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
|
|
||||||
// 停止发送通话保持的命令
|
|
||||||
startChartManage.stopTalkPingMessageTimer();
|
|
||||||
startChartManage.stopTalkExpectMessageTimer();
|
|
||||||
talkStatus.setNotTalkPing();
|
|
||||||
talkStatus.setEnd();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 启动通话数据的检查,判断x秒内是否收到通话数据
|
/// 启动通话数据的检查,判断x秒内是否收到通话数据
|
||||||
void _handleCheckTalkDataTimer() {
|
void _handleCheckTalkDataTimer() {
|
||||||
// 启动对讲数据监听定时器
|
// 启动通话保持监听定时器(用来判断如果x秒内没有收到通话保持则执行的操作)
|
||||||
talkDataOverTimeTimerManager.startTimer();
|
talkDataOverTimeTimerManager.start();
|
||||||
// 设置对讲数据超时后的事件
|
|
||||||
talkDataOverTimeTimerManager.setOnTimeout(() {
|
|
||||||
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
|
|
||||||
startChartManage.stopTalkPingMessageTimer();
|
|
||||||
startChartManage.stopTalkExpectMessageTimer();
|
|
||||||
talkStatus.setNotTalkData();
|
|
||||||
talkStatus.setEnd();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 启动发送预期数据请求
|
/// 启动发送预期数据请求
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class UdpTalkDataHandler extends ScpMessageBaseHandle
|
|||||||
@override
|
@override
|
||||||
void handleRealTimeData(ScpMessage scpMessage) {
|
void handleRealTimeData(ScpMessage scpMessage) {
|
||||||
// 收到数据后调用更新,防止定时器超时
|
// 收到数据后调用更新,防止定时器超时
|
||||||
talkDataOverTimeTimerManager.receiveMessage();
|
// talkDataOverTimeTimerManager.renew();
|
||||||
if (scpMessage.Payload != null) {
|
if (scpMessage.Payload != null) {
|
||||||
final TalkData talkData = scpMessage.Payload;
|
final TalkData talkData = scpMessage.Payload;
|
||||||
// 处理音视频数据
|
// 处理音视频数据
|
||||||
|
|||||||
@ -41,8 +41,8 @@ class UdpTalkHangUpHandler extends ScpMessageBaseHandle
|
|||||||
stopRingtone();
|
stopRingtone();
|
||||||
|
|
||||||
// 拒绝接听之后,停止对讲请求超时监听定时器
|
// 拒绝接听之后,停止对讲请求超时监听定时器
|
||||||
talkeRequestOverTimeTimerManager.receiveMessage();
|
// talkeRequestOverTimeTimerManager.renewTimer();
|
||||||
talkeRequestOverTimeTimerManager.dispose();
|
// talkeRequestOverTimeTimerManager.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -13,17 +13,18 @@ class UdpTalkPingHandler extends ScpMessageBaseHandle
|
|||||||
implements ScpMessageHandler {
|
implements ScpMessageHandler {
|
||||||
@override
|
@override
|
||||||
void handleReq(ScpMessage scpMessage) {
|
void handleReq(ScpMessage scpMessage) {
|
||||||
// TODO: 收到通话保持请求
|
// 收到通话保持请求,回复成功消息
|
||||||
replySuccessMessage(scpMessage);
|
replySuccessMessage(scpMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void handleResp(ScpMessage scpMessage) {
|
void handleResp(ScpMessage scpMessage) {
|
||||||
// 收到通话保持回复
|
// 收到通话保持回复
|
||||||
|
// print('收到通话保持回复');
|
||||||
final GenericResp genericResp = scpMessage.Payload;
|
final GenericResp genericResp = scpMessage.Payload;
|
||||||
if (checkGenericRespSuccess(genericResp)) {
|
if (checkGenericRespSuccess(genericResp)) {
|
||||||
// 收到消息,重新触发定时器
|
// 收到消息,续签定时器
|
||||||
talkePingOverTimeTimerManager.receiveMessage();
|
talkePingOverTimeTimerManager.renew();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class UdpTalkPingHandler extends ScpMessageBaseHandle
|
|||||||
deserializePayload(
|
deserializePayload(
|
||||||
{required int payloadType,
|
{required int payloadType,
|
||||||
required int messageType,
|
required int messageType,
|
||||||
required List<int> byte,
|
required List<int> byte,
|
||||||
int? offset,
|
int? offset,
|
||||||
int? PayloadLength,
|
int? PayloadLength,
|
||||||
int? spTotal,
|
int? spTotal,
|
||||||
|
|||||||
@ -35,8 +35,8 @@ class UdpTalkRejectHandler extends ScpMessageBaseHandle
|
|||||||
|
|
||||||
|
|
||||||
// 拒绝接听之后,停止对讲请求超时监听定时器
|
// 拒绝接听之后,停止对讲请求超时监听定时器
|
||||||
talkeRequestOverTimeTimerManager.receiveMessage();
|
// talkeRequestOverTimeTimerManager.renewTimer();
|
||||||
talkeRequestOverTimeTimerManager.dispose();
|
// talkeRequestOverTimeTimerManager.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -36,14 +36,14 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|||||||
_talkRequestEvent(talkObjectName: talkReq.callerName);
|
_talkRequestEvent(talkObjectName: talkReq.callerName);
|
||||||
|
|
||||||
// 启动对讲请求超时定时器
|
// 启动对讲请求超时定时器
|
||||||
talkeRequestOverTimeTimerManager.startTimer();
|
// talkeRequestOverTimeTimerManager.startTimer();
|
||||||
talkeRequestOverTimeTimerManager.setOnTimeout(() {
|
// talkeRequestOverTimeTimerManager.setOnTimeout(() {
|
||||||
if (talkStatus.status == TalkStatus.waitingAnswer) {
|
// if (talkStatus.status == TalkStatus.waitingAnswer) {
|
||||||
// 超时未接听,发送挂断请求
|
// // 超时未接听,发送挂断请求
|
||||||
startChartManage.sendTalkRejectMessage();
|
// startChartManage.sendTalkRejectMessage();
|
||||||
Get.back();
|
// Get.back();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
typedef TimeoutCallback = void Function();
|
|
||||||
|
|
||||||
class OverTimeTimerManager {
|
|
||||||
// 构造函数,接受超时时间
|
|
||||||
OverTimeTimerManager({required this.timeoutInSeconds});
|
|
||||||
|
|
||||||
// 定义一个可取消的 Timer
|
|
||||||
Timer? _timer;
|
|
||||||
|
|
||||||
// 超时时间(以秒为单位),是 final 的,因此必须在构造函数中初始化
|
|
||||||
final int timeoutInSeconds;
|
|
||||||
|
|
||||||
// 超时回调函数
|
|
||||||
TimeoutCallback? _onTimeout;
|
|
||||||
|
|
||||||
// 启动计时器
|
|
||||||
void startTimer() {
|
|
||||||
_cancelTimer(); // 取消任何已存在的计时器
|
|
||||||
_timer = Timer(Duration(seconds: timeoutInSeconds), () {
|
|
||||||
// 超时回调方法
|
|
||||||
_onTimeout?.call();
|
|
||||||
// 清除定时器
|
|
||||||
_cancelTimer();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 接收到消息时调用此方法
|
|
||||||
void receiveMessage() {
|
|
||||||
startTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置超时回调函数
|
|
||||||
void setOnTimeout(TimeoutCallback? callback) {
|
|
||||||
_onTimeout = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 取消计时器
|
|
||||||
void _cancelTimer() {
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理资源
|
|
||||||
void dispose() {
|
|
||||||
_cancelTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_constant.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_status.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
|
|
||||||
|
class TalkDataOverTimeTimerManager {
|
||||||
|
// 单例实例
|
||||||
|
static final TalkDataOverTimeTimerManager _instance =
|
||||||
|
TalkDataOverTimeTimerManager._internal();
|
||||||
|
|
||||||
|
factory TalkDataOverTimeTimerManager() => _instance;
|
||||||
|
|
||||||
|
// 获取 StartChartTalkStatus 的唯一实例
|
||||||
|
static StartChartTalkStatus talkStatus = StartChartTalkStatus.instance;
|
||||||
|
final Duration timeout;
|
||||||
|
final void Function() onTimeout;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
// 私有构造函数
|
||||||
|
TalkDataOverTimeTimerManager._internal()
|
||||||
|
: timeout = const Duration(seconds: TalkConstant.talkeDataOverTime),
|
||||||
|
onTimeout = _handleTalkeDataOverTime;
|
||||||
|
|
||||||
|
// 超时处理函数
|
||||||
|
static void _handleTalkeDataOverTime() {
|
||||||
|
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
|
||||||
|
StartChartManage().stopTalkPingMessageTimer();
|
||||||
|
StartChartManage().stopTalkExpectMessageTimer();
|
||||||
|
talkStatus.setNotTalkData();
|
||||||
|
talkStatus.setEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动定时器
|
||||||
|
void start() {
|
||||||
|
_timer = Timer(timeout, onTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 续签定时器
|
||||||
|
void renew() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消定时器
|
||||||
|
void cancel() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_constant.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_status.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
|
|
||||||
|
class TalkePingOverTimeTimerManager {
|
||||||
|
// 单例实例
|
||||||
|
static final TalkePingOverTimeTimerManager _instance =
|
||||||
|
TalkePingOverTimeTimerManager._internal();
|
||||||
|
|
||||||
|
factory TalkePingOverTimeTimerManager() => _instance;
|
||||||
|
|
||||||
|
// 获取 StartChartTalkStatus 的唯一实例
|
||||||
|
static StartChartTalkStatus talkStatus = StartChartTalkStatus.instance;
|
||||||
|
final Duration timeout;
|
||||||
|
final void Function() onTimeout;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
// 私有构造函数
|
||||||
|
TalkePingOverTimeTimerManager._internal()
|
||||||
|
: timeout = const Duration(seconds: TalkConstant.talkePingOverTime),
|
||||||
|
onTimeout = _handleTalkePingOverTime;
|
||||||
|
|
||||||
|
// 超时处理函数
|
||||||
|
static void _handleTalkePingOverTime() {
|
||||||
|
if (talkStatus.status == TalkStatus.duringCall) {
|
||||||
|
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
|
||||||
|
// 停止发送通话保持的命令
|
||||||
|
StartChartManage().stopTalkPingMessageTimer();
|
||||||
|
StartChartManage().stopTalkExpectMessageTimer();
|
||||||
|
// 如果通话异常,则发送通话中挂断
|
||||||
|
StartChartManage().sendTalkHangupMessage();
|
||||||
|
talkStatus.setNotTalkPing();
|
||||||
|
talkStatus.setEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动定时器
|
||||||
|
void start() {
|
||||||
|
_timer = Timer(timeout, onTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 续签定时器
|
||||||
|
void renew() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消定时器
|
||||||
|
void cancel() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_constant.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/constant/talk_status.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
|
|
||||||
|
class TalkeRequestOverTimeTimerManager {
|
||||||
|
// 单例实例
|
||||||
|
static final TalkeRequestOverTimeTimerManager _instance =
|
||||||
|
TalkeRequestOverTimeTimerManager._internal();
|
||||||
|
|
||||||
|
factory TalkeRequestOverTimeTimerManager() => _instance;
|
||||||
|
|
||||||
|
// 获取 StartChartTalkStatus 的唯一实例
|
||||||
|
static StartChartTalkStatus talkStatus = StartChartTalkStatus.instance;
|
||||||
|
final Duration timeout;
|
||||||
|
final void Function() onTimeout;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
// 私有构造函数
|
||||||
|
TalkeRequestOverTimeTimerManager._internal()
|
||||||
|
: timeout = const Duration(seconds: TalkConstant.talkeRequestOverTime),
|
||||||
|
onTimeout = _handleTalkeRequestOverTime;
|
||||||
|
|
||||||
|
// 超时处理函数
|
||||||
|
static void _handleTalkeRequestOverTime() {
|
||||||
|
if (talkStatus.status == TalkStatus.waitingAnswer) {
|
||||||
|
// 超时未接听,发送挂断请求
|
||||||
|
StartChartManage().sendTalkRejectMessage();
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动定时器
|
||||||
|
void start() {
|
||||||
|
_timer = Timer(timeout, onTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 续签定时器
|
||||||
|
void renew() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消定时器
|
||||||
|
void cancel() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,15 +3,21 @@ import 'dart:convert';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
import 'package:star_lock/app_settings/app_settings.dart';
|
import 'package:star_lock/app_settings/app_settings.dart';
|
||||||
import 'package:star_lock/talk/other/audio_player_manager.dart';
|
import 'package:star_lock/talk/other/audio_player_manager.dart';
|
||||||
import 'package:star_lock/talk/startChart/constant/payload_type_constant.dart';
|
import 'package:star_lock/talk/startChart/constant/payload_type_constant.dart';
|
||||||
|
|
||||||
import 'package:star_lock/talk/startChart/constant/udp_constant.dart';
|
import 'package:star_lock/talk/startChart/constant/udp_constant.dart';
|
||||||
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
||||||
import 'package:star_lock/talk/startChart/handle/other/overtime_timer_manger.dart';
|
|
||||||
import 'package:star_lock/talk/startChart/handle/other/talk_data_repository.dart';
|
import 'package:star_lock/talk/startChart/handle/other/talk_data_repository.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/proto/generic.pb.dart';
|
import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
|
||||||
import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart';
|
import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart';
|
||||||
@ -19,8 +25,16 @@ import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
|||||||
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
|
|
||||||
class ScpMessageBaseHandle {
|
class ScpMessageBaseHandle {
|
||||||
|
/// 使用单例 TimerManager
|
||||||
|
/// 超时处理
|
||||||
|
final TalkeRequestOverTimeTimerManager talkeRequestOverTimeTimerManager =
|
||||||
|
TalkeRequestOverTimeTimerManager();
|
||||||
|
final TalkePingOverTimeTimerManager talkePingOverTimeTimerManager =
|
||||||
|
TalkePingOverTimeTimerManager();
|
||||||
|
final TalkDataOverTimeTimerManager talkDataOverTimeTimerManager =
|
||||||
|
TalkDataOverTimeTimerManager();
|
||||||
|
|
||||||
final startChartManage = StartChartManage();
|
final startChartManage = StartChartManage();
|
||||||
final List<int> _buffer = [];
|
|
||||||
|
|
||||||
/// 分包缓冲区
|
/// 分包缓冲区
|
||||||
// 存储每个 messageId 对应的分包数据
|
// 存储每个 messageId 对应的分包数据
|
||||||
@ -36,21 +50,6 @@ class ScpMessageBaseHandle {
|
|||||||
|
|
||||||
final audioManager = AudioPlayerManager();
|
final audioManager = AudioPlayerManager();
|
||||||
|
|
||||||
// 通话请求超时未处理监听定时器管理
|
|
||||||
final talkeRequestOverTimeTimerManager = OverTimeTimerManager(
|
|
||||||
timeoutInSeconds: 8,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 通话保持超时监听定时器管理
|
|
||||||
final talkePingOverTimeTimerManager = OverTimeTimerManager(
|
|
||||||
timeoutInSeconds: 5,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 通话数据超时定时器
|
|
||||||
final talkDataOverTimeTimerManager = OverTimeTimerManager(
|
|
||||||
timeoutInSeconds: 30,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 回复成功消息
|
// 回复成功消息
|
||||||
void replySuccessMessage(ScpMessage scpMessage) {
|
void replySuccessMessage(ScpMessage scpMessage) {
|
||||||
startChartManage.sendGenericRespSuccessMessage(
|
startChartManage.sendGenericRespSuccessMessage(
|
||||||
@ -142,4 +141,11 @@ class ScpMessageBaseHandle {
|
|||||||
_packetBuffer.remove(key);
|
_packetBuffer.remove(key);
|
||||||
_packetTimers.remove(key)?.cancel();
|
_packetTimers.remove(key)?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理通话请求未处理超时
|
||||||
|
void _handleTalkeRequestOverTime() {}
|
||||||
|
|
||||||
|
void _handleTalkePingOverTime() {}
|
||||||
|
|
||||||
|
void _handleTalkDataOverTime() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -451,7 +451,7 @@ class StartChartManage {
|
|||||||
MessageId: MessageCommand.getNextMessageId(ToPeerId, increment: true),
|
MessageId: MessageCommand.getNextMessageId(ToPeerId, increment: true),
|
||||||
);
|
);
|
||||||
await _sendMessage(message: message);
|
await _sendMessage(message: message);
|
||||||
_log(text: '发送通话保持');
|
// _log(text: '发送通话保持');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送通话中挂断消息
|
// 发送通话中挂断消息
|
||||||
|
|||||||
@ -30,13 +30,14 @@ import '../../../../tools/baseGetXController.dart';
|
|||||||
class TalkViewLogic extends BaseGetXController {
|
class TalkViewLogic extends BaseGetXController {
|
||||||
final TalkViewState state = TalkViewState();
|
final TalkViewState state = TalkViewState();
|
||||||
|
|
||||||
Timer? _syncTimer;
|
Timer? _syncTimer; // 音视频播放刷新率定时器
|
||||||
int _startTime = 0;
|
int _startTime = 0; // 开始播放时间戳,用于判断帧数据中的时间戳位置
|
||||||
final int bufferSize = 20; // 缓冲区大小(以帧为单位)
|
final int bufferSize = 8; // 缓冲区大小(以帧为单位)
|
||||||
final List<int> frameTimestamps = []; // 帧时间戳用于计算 FPS
|
final List<int> frameTimestamps = []; // 帧时间戳用于计算 FPS
|
||||||
int frameIntervalMs = 45; // 初始帧间隔设置为45毫秒(约22FPS)
|
int frameIntervalMs = 45; // 初始帧间隔设置为45毫秒(约22FPS)
|
||||||
int minFrameIntervalMs = 30; // 最小帧间隔(约33 FPS)
|
int minFrameIntervalMs = 30; // 最小帧间隔(约33 FPS)
|
||||||
int maxFrameIntervalMs = 100; // 最大帧间隔(约10 FPS)
|
int maxFrameIntervalMs = 500; // 最大帧间隔(约2 FPS)
|
||||||
|
// int maxFrameIntervalMs = 100; // 最大帧间隔(约10 FPS)
|
||||||
|
|
||||||
/// 初始化音频播放器
|
/// 初始化音频播放器
|
||||||
void _initFlutterPcmSound() {
|
void _initFlutterPcmSound() {
|
||||||
@ -82,7 +83,7 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
|
|
||||||
// 监听音视频数据流
|
// 监听音视频数据流
|
||||||
void _startListenTalkData() {
|
void _startListenTalkData() {
|
||||||
state.talkDataRepository.talkDataStream.listen((talkData) {
|
state.talkDataRepository.talkDataStream.listen((TalkData talkData) {
|
||||||
final contentType = talkData.contentType;
|
final contentType = talkData.contentType;
|
||||||
final currentTimestamp = DateTime.now().millisecondsSinceEpoch;
|
final currentTimestamp = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
|
||||||
@ -97,11 +98,14 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
if (state.audioBuffer.length < bufferSize) {
|
if (state.audioBuffer.length < bufferSize) {
|
||||||
state.audioBuffer.add(talkData);
|
state.audioBuffer.add(talkData);
|
||||||
}
|
}
|
||||||
|
// print('收到音频数据');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TalkData_ContentTypeE.Image:
|
case TalkData_ContentTypeE.Image:
|
||||||
if (state.videoBuffer.length < bufferSize) {
|
if (state.videoBuffer.length < bufferSize) {
|
||||||
state.videoBuffer.add(talkData);
|
state.videoBuffer.add(talkData);
|
||||||
}
|
}
|
||||||
|
print('talkData durationMs-->:${talkData.durationMs}');
|
||||||
|
|
||||||
/// 更新网络状态
|
/// 更新网络状态
|
||||||
updateNetworkStatus(currentTimestamp);
|
updateNetworkStatus(currentTimestamp);
|
||||||
@ -257,7 +261,6 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
} else {
|
} else {
|
||||||
state.networkStatus.value = NetworkStatus.normal;
|
state.networkStatus.value = NetworkStatus.normal;
|
||||||
state.alertCount.value = 0; // 重置计数器
|
state.alertCount.value = 0; // 重置计数器
|
||||||
EasyLoading.dismiss(); // 网络恢复正常时关闭提示
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.lastFrameTimestamp.value = currentTimestamp;
|
state.lastFrameTimestamp.value = currentTimestamp;
|
||||||
@ -340,6 +343,7 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
_stopPlayG711Data();
|
_stopPlayG711Data();
|
||||||
state.listData.value = Uint8List(0);
|
state.listData.value = Uint8List(0);
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
|
_syncTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 处理无效通话状态
|
/// 处理无效通话状态
|
||||||
|
|||||||
@ -199,8 +199,10 @@ class _TalkViewPageState extends State<TalkViewPage>
|
|||||||
if (state.talkStatus.value == TalkStatus.duringCall) {
|
if (state.talkStatus.value == TalkStatus.duringCall) {
|
||||||
if (state.isRecordingScreen.value) {
|
if (state.isRecordingScreen.value) {
|
||||||
await logic.stopRecording();
|
await logic.stopRecording();
|
||||||
|
print('停止录屏');
|
||||||
} else {
|
} else {
|
||||||
await logic.startRecording();
|
await logic.startRecording();
|
||||||
|
print('开始录屏');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user