fix:调整对讲接听逻辑

This commit is contained in:
liyi 2024-12-09 11:06:35 +08:00
parent 4e0fdd6f29
commit 661ba90f08
7 changed files with 137 additions and 84 deletions

View File

@ -10,40 +10,28 @@ import '../../start_chart_manage.dart';
class UdpTalkAcceptHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
@override
void handleReq(ScpMessage scpMessage) {
// TODO:
print('收到同意接听请求');
//
startChartManage.sendGenericRespSuccessMessage(
ToPeerId: scpMessage.FromPeerId!,
FromPeerId: scpMessage.ToPeerId!,
PayloadType: scpMessage.PayloadType!,
);
}
@override
void handleResp(ScpMessage scpMessage) {
// TODO:
//
final GenericResp genericResp = scpMessage.Payload;
if (checkGenericRespSuccess(genericResp)) {
//
//
startChartManage.sendGenericRespSuccessMessage(
ToPeerId: scpMessage.FromPeerId!,
FromPeerId: scpMessage.ToPeerId!,
PayloadType: scpMessage.PayloadType!,
);
//
startChartManage.startTalkPingMessageTimer();
//
talkePingOverTimeTimerManager.startTimer();
//
talkePingOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
});
//
talkDataOverTimeTimerManager.startTimer();
//
talkDataOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
});
//
_handleStartTalkPing();
//
_handleCheckTalkDataTimer();
//
_handleStartSendTalkExpectDataRequest();
}
}
@ -53,8 +41,42 @@ class UdpTalkAcceptHandler extends ScpMessageBaseHandle
}
@override
void handleRealTimeData(ScpMessage scpMessage
) {
void handleRealTimeData(ScpMessage scpMessage) {
// TODO: implement handleRealTimeData
}
//
void _handleStartTalkPing() {
//
startChartManage.startTalkPingMessageTimer();
// x秒内没有收到通话保持则执行的操作
talkePingOverTimeTimerManager.startTimer();
//
talkePingOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话异常中断', duration: 2000.milliseconds);
//
startChartManage.stopTalkPingMessageTimer();
startChartManage.stopTalkExpectMessageTimer();
startChartManage.changeCallingStatus(false);
});
}
/// x秒内是否收到通话数据
void _handleCheckTalkDataTimer() {
//
talkDataOverTimeTimerManager.startTimer();
//
talkDataOverTimeTimerManager.setOnTimeout(() {
EasyLoading.showToast('通话连接失败', duration: 2000.milliseconds);
startChartManage.stopTalkPingMessageTimer();
startChartManage.stopTalkExpectMessageTimer();
startChartManage.changeCallingStatus(false);
});
}
///
void _handleStartSendTalkExpectDataRequest() {
//
startChartManage.startTalkExpectTimer();
}
}

View File

@ -10,8 +10,6 @@ import '../../start_chart_manage.dart';
class UdpTalkDataHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
@override
void handleReq(ScpMessage scpMessage) {
// TODO:
@ -21,6 +19,8 @@ class UdpTalkDataHandler extends ScpMessageBaseHandle
void handleResp(ScpMessage scpMessage) {
// TODO:
print('收到音视频数据');
//
talkDataOverTimeTimerManager.receiveMessage();
}
@override

View File

@ -10,8 +10,6 @@ import '../../start_chart_manage.dart';
class UdpTalkExpectHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
@override
void handleReq(ScpMessage scpMessage) {
// TODO:
@ -19,7 +17,11 @@ class UdpTalkExpectHandler extends ScpMessageBaseHandle
@override
void handleResp(ScpMessage scpMessage) {
// TODO:
//
final GenericResp genericResp = scpMessage.Payload;
if (checkGenericRespSuccess(genericResp)) {
print('收到预期数据成功');
}
}
@override

View File

@ -14,14 +14,13 @@ class UdpTalkPingHandler extends ScpMessageBaseHandle
@override
void handleResp(ScpMessage scpMessage) {
// TODO:
//
final GenericResp genericResp = scpMessage.Payload;
if (checkGenericRespSuccess(genericResp)) {
//
//
talkePingOverTimeTimerManager.receiveMessage();
//
startChartManage.changeCallingStatus(true);
}
}

View File

@ -10,11 +10,6 @@ import '../../start_chart_manage.dart';
class UdpTalkRejectHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
@override
void handle(ScpMessage scpMessage) {
print('收到接听拒绝');
}
@override
void handleReq(ScpMessage scpMessage) {
// TODO:
@ -22,7 +17,8 @@ class UdpTalkRejectHandler extends ScpMessageBaseHandle
@override
void handleResp(ScpMessage scpMessage) {
// TODO:
//
EasyLoading.showToast('对方已经拒绝接听', duration: 2000.milliseconds);
}
@override

View File

@ -15,52 +15,24 @@ import '../../start_chart_manage.dart';
class UdpTalkRequestHandler extends ScpMessageBaseHandle
implements ScpMessageHandler {
//
void _talkRequestEvent() {
playRingtone();
_showTalkRequestNotification();
//
Get.toNamed(
Routers.lockMonitoringPage,
arguments: <String, String>{'lockId': '111'},
);
}
//
Future<void> _showTalkRequestNotification() async {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('1', 'flutter_channel',
importance: Importance.max,
priority: Priority.high,
playSound: true,
ticker: 'ticker');
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
//
String? getLockName = await Storage.getString(saveLockAlias);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
//
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
'${'收到来自'.tr}($getLockName)${'锁的呼叫'.tr}', platformChannelSpecifics,
payload: 'item x');
}
@override
void handleReq(ScpMessage scpMessage) {
//
print('收到对讲请求:${scpMessage}');
final TalkReq talkReq = scpMessage.Payload;
//
//
startChartManage.sendGenericRespSuccessMessage(
ToPeerId: scpMessage.FromPeerId!,
FromPeerId: scpMessage.ToPeerId!,
PayloadType: scpMessage.PayloadType!,
);
startChartManage.FromPeerId = scpMessage.ToPeerId!;
startChartManage.ToPeerId = scpMessage.FromPeerId!;
//
_talkRequestEvent();
// _talkRequestEvent(talkObjectName: talkReq.callerName);
Future.delayed(Duration(seconds: 1), () {
startChartManage.sendTalkAcceptMessage();
});
}
@override
@ -81,4 +53,36 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
void handleRealTimeData(ScpMessage scpMessage) {
// TODO: implement handleRealTimeData
}
//
void _talkRequestEvent({required String talkObjectName}) {
playRingtone();
_showTalkRequestNotification(talkObjectName: talkObjectName);
//
Get.toNamed(
Routers.lockMonitoringPage,
arguments: <String, String>{'lockId': '111'},
);
}
//
Future<void> _showTalkRequestNotification(
{required String talkObjectName}) async {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('1', 'flutter_channel',
importance: Importance.max,
priority: Priority.high,
playSound: true,
ticker: 'ticker');
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
//
// String? getLockName = await Storage.getString(saveLockAlias);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
//
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
'${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}', platformChannelSpecifics,
payload: 'item x');
}
}

View File

@ -64,9 +64,16 @@ class StartChartManage {
Timer? reStartOnlineStartChartServerTimer; // 线
int talkPingIntervalTime = 1; // (s)
Timer? talkPingTimer; //
int talkExpectIntervalTime = 1; // (s)
Timer? talkExpectTimer; //
//
TalkExpect defaultTalkExpect = TalkExpect(
videoType: [TalkExpect_VideoTypeE.H264],
audioType: [TalkExpect_AudioTypeE.G711],
);
String relayPeerId = ''; // peerId
bool _calling = false; //
//
@ -255,14 +262,11 @@ class StartChartManage {
}
//
void sendTalkExpectMessage() async {
void sendTalkExpectMessage({required TalkExpect talkExpect}) async {
final message = MessageCommand.talkExpectMessage(
ToPeerId: ToPeerId,
FromPeerId: FromPeerId,
talkExpect: TalkExpect(
videoType: [TalkExpect_VideoTypeE.H264],
audioType: [TalkExpect_AudioTypeE.G711],
),
talkExpect: talkExpect,
);
await _sendMessage(message: message);
}
@ -707,4 +711,30 @@ class StartChartManage {
talkPingTimer?.cancel();
talkPingTimer = null; //
}
///
void startTalkExpectTimer() {
talkExpectTimer ??= Timer.periodic(
Duration(
seconds: talkExpectIntervalTime,
),
(Timer timer) {
//
sendTalkExpectMessage(
talkExpect: defaultTalkExpect,
);
},
);
}
//
void stopTalkExpectMessageTimer() {
talkExpectTimer?.cancel();
talkExpectTimer = null; //
}
///
void changeTalkExpectDataType({required TalkExpect talkExpect}) {
defaultTalkExpect = talkExpect;
}
}