diff --git a/assets/talk.h264 b/assets/talk.h264 deleted file mode 100644 index 5a1f2802..00000000 Binary files a/assets/talk.h264 and /dev/null differ diff --git a/lib/login/login/starLock_login_page.dart b/lib/login/login/starLock_login_page.dart index 2f0dd0f1..ea62eec7 100755 --- a/lib/login/login/starLock_login_page.dart +++ b/lib/login/login/starLock_login_page.dart @@ -235,12 +235,6 @@ class _StarLockLoginPageState extends State { } } : null)), - SubmitBtn( - btnName: '跳转至通话', - onClick: () { - Get.toNamed(Routers.lockMonitoringPage); - }, - ), SizedBox(height: 50.w), Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/talk/startChart/handle/impl/udp_heart_beat_handler.dart b/lib/talk/startChart/handle/impl/udp_heart_beat_handler.dart index de843012..82b8843b 100644 --- a/lib/talk/startChart/handle/impl/udp_heart_beat_handler.dart +++ b/lib/talk/startChart/handle/impl/udp_heart_beat_handler.dart @@ -16,18 +16,22 @@ class UdpHeartBeatHandler extends ScpMessageBaseHandle @override void handleResp(ScpMessage scpMessage) { - // TODO: 收到心跳消息回复 final HeartbeatResponse heartbeatResponse = scpMessage.Payload; final statusCode = heartbeatResponse.statusCode; if (statusCode != null && statusCode != PayloadTypeConstant.heartHeatSuccessResponse) { - // 心跳响应失败,重新上线 + // 心跳回复失败,停止发送心跳 + startChartManage.stopHeartbeat(); + // 心跳响应失败,重新上线 + startChartManage.isOnlineStartChartServer = false; startChartManage.reStartOnlineStartChartServer(); + } else { + // 修改间隔为返回的心跳间隔 + startChartManage.heartbeatIntervalTime = + heartbeatResponse.nextPingTime ?? 1; + // 修改完间隔之后重新启动发送心跳 + startChartManage.reStartHeartBeat(); } - startChartManage.heartbeatIntervalTime = - heartbeatResponse.nextPingTime ?? 1; - // 修改完间隔之后重新启动发送心跳 - startChartManage.reStartHeartBeat(); } @override diff --git a/lib/talk/startChart/handle/impl/udp_talk_accept_handler.dart b/lib/talk/startChart/handle/impl/udp_talk_accept_handler.dart index fe51cd3f..3fae7d0a 100644 --- a/lib/talk/startChart/handle/impl/udp_talk_accept_handler.dart +++ b/lib/talk/startChart/handle/impl/udp_talk_accept_handler.dart @@ -28,6 +28,7 @@ class UdpTalkAcceptHandler extends ScpMessageBaseHandle if (checkGenericRespSuccess(genericResp)) { // 启动通话保持定时器 _handleStartTalkPing(); + // 延迟2秒后启动监听 Future.delayed(Duration(seconds: 2), () { // 启动发送预期数据请求 _handleStartSendTalkExpectDataRequest(); @@ -37,6 +38,7 @@ class UdpTalkAcceptHandler extends ScpMessageBaseHandle // 停止播放铃声 stopRingtone(); // 设置状态为接听中 + talkStatus.setAnsweredSuccessfully(); talkStatus.setDuringCall(); } } diff --git a/lib/talk/startChart/handle/impl/udp_talk_data_handler.dart b/lib/talk/startChart/handle/impl/udp_talk_data_handler.dart index 5bea2f1e..3e172271 100644 --- a/lib/talk/startChart/handle/impl/udp_talk_data_handler.dart +++ b/lib/talk/startChart/handle/impl/udp_talk_data_handler.dart @@ -51,12 +51,14 @@ class UdpTalkDataHandler extends ScpMessageBaseHandle } } + /// 处理h264协议的数据 void _handleVideoH264(TalkData talkData) { - final List content = talkData.content; - talkDataRepository.addTalkData(content); + talkDataRepository.addTalkData(talkData); } + /// 处理图片数据 void _handleVideoImage(TalkData talkData) {} + /// 处理g711音频数据 void _handleVideoG711(TalkData talkData) {} } diff --git a/lib/talk/startChart/handle/impl/udp_talk_hangup_handler.dart b/lib/talk/startChart/handle/impl/udp_talk_hangup_handler.dart index 38b07c3b..d590ee9c 100644 --- a/lib/talk/startChart/handle/impl/udp_talk_hangup_handler.dart +++ b/lib/talk/startChart/handle/impl/udp_talk_hangup_handler.dart @@ -22,6 +22,7 @@ class UdpTalkHangUpHandler extends ScpMessageBaseHandle // 停止发送通话保持的命令 startChartManage.stopTalkPingMessageTimer(); startChartManage.stopTalkExpectMessageTimer(); + talkStatus.setHangingUpDuring(); talkStatus.setEnd(); stopRingtone(); } @@ -32,6 +33,7 @@ class UdpTalkHangUpHandler extends ScpMessageBaseHandle // 停止发送通话保持的命令 startChartManage.stopTalkPingMessageTimer(); startChartManage.stopTalkExpectMessageTimer(); + talkStatus.setHangingUpDuring(); talkStatus.setEnd(); stopRingtone(); } diff --git a/lib/talk/startChart/handle/other/talk_data_repository.dart b/lib/talk/startChart/handle/other/talk_data_repository.dart index c84d58b1..a86382c7 100644 --- a/lib/talk/startChart/handle/other/talk_data_repository.dart +++ b/lib/talk/startChart/handle/other/talk_data_repository.dart @@ -13,13 +13,13 @@ class TalkDataRepository { static TalkDataRepository get instance => _instance; // 创建一个 StreamController - final StreamController> _talkDataStreamController = StreamController>.broadcast(); + final StreamController _talkDataStreamController = StreamController.broadcast(); // 提供一个方法来获取 Stream - Stream> get talkDataStream => _talkDataStreamController.stream; + Stream get talkDataStream => _talkDataStreamController.stream; // 提供一个方法来添加 TalkData 到 Stream - void addTalkData(List talkData) { + void addTalkData(TalkData talkData) { _talkDataStreamController.add(talkData); } diff --git a/lib/talk/startChart/start_chart_talk_status.dart b/lib/talk/startChart/start_chart_talk_status.dart index 504e6aae..4fd0a363 100644 --- a/lib/talk/startChart/start_chart_talk_status.dart +++ b/lib/talk/startChart/start_chart_talk_status.dart @@ -4,8 +4,10 @@ import 'package:star_lock/talk/startChart/events/talk_status_change_event.dart'; enum TalkStatus { waitingAnswer, // 等待接听 + answeredSuccessfully, // 接听成功 waitingData, // 等待数据 duringCall, // 通话中 + hangingUpDuring, // 通话中挂断 rejected, // 被拒绝 uninitialized, // 未初始化 initializationCompleted, // 初始化完成 @@ -104,6 +106,16 @@ class StartChartTalkStatus { // 可以在这里添加特定于 "error" 状态的逻辑 } + /// 设置状态为通话中挂断 + void setHangingUpDuring() { + _setStatus(TalkStatus.hangingUpDuring); + // 可以在这里添加特定于 "hangingUpDuring" 状态的逻辑 + } /// 设置状态为接听成功 + void setAnsweredSuccessfully() { + _setStatus(TalkStatus.answeredSuccessfully); + // 可以在这里添加特定于 "hangingUpDuring" 状态的逻辑 + } + /// 设置状态为结束 void setEnd() { _setStatus(TalkStatus.end); diff --git a/lib/talk/startChart/webView/h264_web_view.dart b/lib/talk/startChart/webView/h264_web_view.dart index a38e9bef..963a33c5 100644 --- a/lib/talk/startChart/webView/h264_web_view.dart +++ b/lib/talk/startChart/webView/h264_web_view.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart' show ByteData, Uint8List, rootBundle; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/talk/startChart/handle/other/talk_data_repository.dart'; +import 'package:star_lock/talk/startChart/proto/talk_data.pbserver.dart'; import 'package:star_lock/tools/titleAppBar.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -70,15 +71,16 @@ class _H264WebViewState extends State { current++; List frameData = byteData.sublist(start, end); if (frameData.length == 0) timer.cancel(); - talkDataRepository.addTalkData(frameData); + + talkDataRepository.addTalkData(TalkData(contentType: TalkData_ContentTypeE.H264,content: frameData)); start = end; }); } void _sendFramesToHtml() async { // 接收到流数据,保存到缓冲区 - talkDataRepository.talkDataStream.listen((event) async { - _buffer.addAll(event); + talkDataRepository.talkDataStream.listen((TalkData event) async { + _buffer.addAll(event.content); }); // 缓冲800ms的数据,定时发送 _sendTimer ??= Timer.periodic( diff --git a/pubspec.yaml b/pubspec.yaml index b62e9308..d1426507 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -299,7 +299,6 @@ flutter: - images/lockType/ - assets/ - assets/html/h264.html - - assets/talk.h264 - lan/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware