feat: 1,新增星图对讲协议逻辑类与原始图片流方式区分隔离处理
2,新增星图对讲接听指令具体细节逻辑处理
This commit is contained in:
parent
c7d26096fb
commit
23a9797e38
@ -23,6 +23,8 @@ class LockMonitoringLogic extends BaseGetXController {
|
|||||||
state.voiceProcessor = VoiceProcessor.instance;
|
state.voiceProcessor = VoiceProcessor.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
旧协议暂时不用
|
||||||
/// 收到UDP发送的状态
|
/// 收到UDP发送的状态
|
||||||
StreamSubscription? _getUDPStatusRefreshUIEvent;
|
StreamSubscription? _getUDPStatusRefreshUIEvent;
|
||||||
|
|
||||||
@ -55,6 +57,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//发起接听命令,每隔一秒钟发一次,六秒无应答则失败
|
//发起接听命令,每隔一秒钟发一次,六秒无应答则失败
|
||||||
void initiateUdpAnswerAction() {
|
void initiateUdpAnswerAction() {
|
||||||
@ -413,7 +416,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
|||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
|
|
||||||
_getUDPStatusRefreshUIAction();
|
// _getUDPStatusRefreshUIAction();
|
||||||
|
|
||||||
initRecorder();
|
initRecorder();
|
||||||
}
|
}
|
||||||
@ -427,7 +430,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
|||||||
void onClose() {
|
void onClose() {
|
||||||
CallTalk().finishAVData();
|
CallTalk().finishAVData();
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
_getUDPStatusRefreshUIEvent!.cancel();
|
// _getUDPStatusRefreshUIEvent!.cancel();
|
||||||
state.getTVDataRefreshUIEvent!.cancel();
|
state.getTVDataRefreshUIEvent!.cancel();
|
||||||
|
|
||||||
if (state.oneMinuteTimeTimer != null) {
|
if (state.oneMinuteTimeTimer != null) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
@ -11,16 +11,17 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:star_lock/main/lockDetail/monitoring/monitoring/lockMonitoring_state.dart';
|
import 'package:star_lock/app_settings/app_colors.dart';
|
||||||
|
import 'package:star_lock/app_settings/app_settings.dart';
|
||||||
|
import 'package:star_lock/main/lockDetail/monitoring/monitoring/star_chart_logic.dart';
|
||||||
import 'package:star_lock/talk/call/callTalk.dart';
|
import 'package:star_lock/talk/call/callTalk.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
import 'package:star_lock/talk/udp/udp_manage.dart';
|
import 'package:star_lock/talk/udp/udp_manage.dart';
|
||||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||||
|
import 'package:star_lock/tools/showTFView.dart';
|
||||||
|
|
||||||
import '../../../../app_settings/app_colors.dart';
|
|
||||||
import '../../../../app_settings/app_settings.dart';
|
|
||||||
import '../../../../login/selectCountryRegion/common/index.dart';
|
|
||||||
import '../../../../tools/showTFView.dart';
|
|
||||||
import 'lockMonitoring_logic.dart';
|
import 'lockMonitoring_logic.dart';
|
||||||
|
import 'lockMonitoring_state.dart';
|
||||||
|
|
||||||
class LockMonitoringPage extends StatefulWidget {
|
class LockMonitoringPage extends StatefulWidget {
|
||||||
const LockMonitoringPage({Key? key}) : super(key: key);
|
const LockMonitoringPage({Key? key}) : super(key: key);
|
||||||
@ -30,12 +31,13 @@ class LockMonitoringPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||||
final LockMonitoringLogic logic = Get.put(LockMonitoringLogic());
|
late final StarChartLogic logic;
|
||||||
final LockMonitoringState state = Get.find<LockMonitoringLogic>().state;
|
final LockMonitoringState state = Get.find<LockMonitoringLogic>().state;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
logic = Get.put<StarChartLogic>(StarChartLogic());
|
||||||
initAsync();
|
initAsync();
|
||||||
_getTVDataRefreshUIAction();
|
_getTVDataRefreshUIAction();
|
||||||
}
|
}
|
||||||
@ -47,234 +49,210 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: RepaintBoundary(
|
child: RepaintBoundary(
|
||||||
key: state.globalKey,
|
key: state.globalKey,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 1.sw,
|
width: 1.sw,
|
||||||
height: 1.sh,
|
height: 1.sh,
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Image.memory(
|
Image.memory(
|
||||||
state.listPhotoData.value,
|
state.listPhotoData.value,
|
||||||
gaplessPlayback: true,
|
gaplessPlayback: true,
|
||||||
width: 1.sw,
|
width: 1.sw,
|
||||||
height: 1.sh,
|
height: 1.sh,
|
||||||
fit: BoxFit.cover, //contain-原比例 none-原始图片
|
fit: BoxFit.cover,
|
||||||
filterQuality: FilterQuality.high,
|
filterQuality: FilterQuality.high,
|
||||||
errorBuilder: (BuildContext context, Object error, StackTrace? stackTrace) {
|
errorBuilder: (BuildContext context, Object error,
|
||||||
return Container(color: Colors.transparent);
|
StackTrace? stackTrace) {
|
||||||
},
|
return Container(color: Colors.transparent);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: ScreenUtil().statusBarHeight + 30.h,
|
||||||
|
width: 1.sw,
|
||||||
|
child: Obx(() {
|
||||||
|
final String sec = (state.oneMinuteTime.value % 60)
|
||||||
|
.toString()
|
||||||
|
.padLeft(2, '0');
|
||||||
|
final String min = (state.oneMinuteTime.value ~/ 60)
|
||||||
|
.toString()
|
||||||
|
.padLeft(2, '0');
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
Text('$min:$sec',
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 26.sp, color: Colors.white)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 10.w,
|
||||||
|
child: Container(
|
||||||
|
width: 1.sw - 30.w * 2,
|
||||||
|
margin: EdgeInsets.all(30.w),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xC83C3F41),
|
||||||
|
borderRadius: BorderRadius.circular(20.h),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
SizedBox(height: 20.h),
|
||||||
|
buildTopButtons(),
|
||||||
|
SizedBox(height: 20.h),
|
||||||
|
buildBottomButtons(),
|
||||||
|
SizedBox(height: 20.h),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
),
|
||||||
top: ScreenUtil().statusBarHeight + 30.h,
|
],
|
||||||
width: 1.sw,
|
|
||||||
child: Obx(() {
|
|
||||||
final String sec = (state.oneMinuteTime.value % 60)
|
|
||||||
.toString()
|
|
||||||
.padLeft(2, '0');
|
|
||||||
final String min = (state.oneMinuteTime.value ~/ 60)
|
|
||||||
.toString()
|
|
||||||
.padLeft(2, '0');
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Text('$min:$sec',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 26.sp, color: Colors.white)),
|
|
||||||
]);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: 10.w,
|
|
||||||
child: Container(
|
|
||||||
width: 1.sw - 30.w * 2,
|
|
||||||
// height: 300.h,
|
|
||||||
margin: EdgeInsets.all(30.w),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xC83C3F41),
|
|
||||||
borderRadius: BorderRadius.circular(20.h)),
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
SizedBox(height: 20.h),
|
|
||||||
bottomTopBtnWidget(),
|
|
||||||
SizedBox(height: 20.h),
|
|
||||||
bottomBottomBtnWidget(),
|
|
||||||
SizedBox(height: 20.h),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bottomTopBtnWidget() {
|
Widget buildTopButtons() {
|
||||||
return Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
return Row(
|
||||||
// 打开关闭声音
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
GestureDetector(
|
children: <Widget>[
|
||||||
onTap: () {
|
buildIconButton(
|
||||||
state.isOpenVoice.value = !state.isOpenVoice.value;
|
icon: state.isOpenVoice.value
|
||||||
},
|
? 'images/main/icon_lockDetail_monitoringCloseVoice.png'
|
||||||
child: Container(
|
: 'images/main/icon_lockDetail_monitoringOpenVoice.png',
|
||||||
width: 50.w,
|
onTap: () {
|
||||||
height: 50.w,
|
state.isOpenVoice.value = !state.isOpenVoice.value;
|
||||||
padding: EdgeInsets.all(5.w),
|
},
|
||||||
child: Obx(() => Image(
|
|
||||||
width: 40.w,
|
|
||||||
height: 40.w,
|
|
||||||
image: state.isOpenVoice.value
|
|
||||||
? const AssetImage(
|
|
||||||
'images/main/icon_lockDetail_monitoringCloseVoice.png')
|
|
||||||
: const AssetImage(
|
|
||||||
'images/main/icon_lockDetail_monitoringOpenVoice.png'))),
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(width: 60.w),
|
||||||
SizedBox(width: 60.w),
|
buildIconButton(
|
||||||
// 截图
|
icon: 'images/main/icon_lockDetail_monitoringScreenshot.png',
|
||||||
GestureDetector(
|
onTap: captureAndSavePng,
|
||||||
onTap: captureAndSavePng,
|
|
||||||
child: Container(
|
|
||||||
width: 50.w,
|
|
||||||
height: 50.w,
|
|
||||||
padding: EdgeInsets.all(5.w),
|
|
||||||
child: Image(
|
|
||||||
width: 40.w,
|
|
||||||
height: 40.w,
|
|
||||||
image: const AssetImage(
|
|
||||||
'images/main/icon_lockDetail_monitoringScreenshot.png')),
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(width: 60.w),
|
||||||
SizedBox(width: 60.w),
|
buildIconButton(
|
||||||
// 录制
|
icon: 'images/main/icon_lockDetail_monitoringScreenRecording.png',
|
||||||
GestureDetector(
|
onTap: () {
|
||||||
onTap: () {
|
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
|
||||||
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
|
},
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: 50.w,
|
|
||||||
height: 50.w,
|
|
||||||
padding: EdgeInsets.all(5.w),
|
|
||||||
child: Image(
|
|
||||||
width: 40.w,
|
|
||||||
height: 40.w,
|
|
||||||
image: const AssetImage(
|
|
||||||
'images/main/icon_lockDetail_monitoringScreenRecording.png')),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bottomBottomBtnWidget() {
|
Widget buildBottomButtons() {
|
||||||
return Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
|
return Row(
|
||||||
// 接听
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
Obx(() => bottomBtnItemWidget(
|
children: <Widget>[
|
||||||
state.isClickAnswer.value == true
|
buildAnswerButton(),
|
||||||
? 'images/main/icon_lockDetail_monitoringUnTalkback.png'
|
buildIconButton(
|
||||||
: getAnswerBtnImg(),
|
icon: 'images/main/icon_lockDetail_hangUp.png',
|
||||||
state.isClickAnswer.value == true ? '长按说话'.tr : getAnswerBtnName(),
|
label: '挂断'.tr,
|
||||||
Colors.white, () async {
|
color: Colors.red,
|
||||||
if (state.isClickAnswer.value == false) {
|
onTap: () async {
|
||||||
logic.initiateUdpAnswerAction();
|
|
||||||
state.isClickAnswer.value = true;
|
|
||||||
}
|
|
||||||
}, longPress: () {
|
|
||||||
// 开始长按
|
|
||||||
AppLog.log('onLongPress');
|
|
||||||
state.listAudioData.value = <int>[];
|
|
||||||
if (state.udpStatus.value == 8) {
|
|
||||||
state.udpStatus.value = 9;
|
|
||||||
}
|
|
||||||
// logic.readG711Data();
|
|
||||||
logic.startProcessing();
|
|
||||||
}, longPressUp: () async {
|
|
||||||
// 长按结束
|
|
||||||
AppLog.log('onLongPressUp');
|
|
||||||
if (state.udpStatus.value == 9) {
|
|
||||||
state.udpStatus.value = 8;
|
|
||||||
}
|
|
||||||
logic.stopProcessing();
|
logic.stopProcessing();
|
||||||
})),
|
CallTalk().finishAVData();
|
||||||
bottomBtnItemWidget(
|
if (!state.isClickHangUp.value) {
|
||||||
'images/main/icon_lockDetail_hangUp.png', '挂断'.tr, Colors.red, () async {
|
// logic.initiateUdpHangUpAction(3);
|
||||||
logic.stopProcessing();
|
logic.initiateHangUpCommand();
|
||||||
CallTalk().finishAVData();
|
state.isClickHangUp.value = true;
|
||||||
// 挂断
|
}
|
||||||
if (state.isClickHangUp.value == false) {
|
},
|
||||||
logic.initiateUdpHangUpAction(3);
|
),
|
||||||
state.isClickHangUp.value = true;
|
buildIconButton(
|
||||||
}
|
icon: 'images/main/icon_lockDetail_monitoringUnlock.png',
|
||||||
// else {
|
label: '开锁'.tr,
|
||||||
// AppLog.log('点了这里?');
|
color: AppColors.mainColor,
|
||||||
// state.isClickHangUp.value = true;
|
onTap: () {
|
||||||
// UDPTalkClass().stopLocalAudio();
|
if (UDPManage().remoteUnlock == 1) {
|
||||||
// logic.initiateUdpHangUpAction(4);
|
showDeletPasswordAlertDialog(context);
|
||||||
// }
|
} else {
|
||||||
}),
|
logic.showToast('请在锁设置中开启远程开锁'.tr);
|
||||||
bottomBtnItemWidget('images/main/icon_lockDetail_monitoringUnlock.png',
|
}
|
||||||
'开锁'.tr, AppColors.mainColor, () {
|
},
|
||||||
if (UDPManage().remoteUnlock == 1) {
|
),
|
||||||
showDeletPasswordAlertDialog(context);
|
],
|
||||||
} else {
|
);
|
||||||
logic.showToast('请在锁设置中开启远程开锁'.tr);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAnswerBtnImg() {
|
Widget buildAnswerButton() {
|
||||||
switch (state.udpStatus.value) {
|
return Obx(() {
|
||||||
case 8:
|
final bool isDuringCall =
|
||||||
return 'images/main/icon_lockDetail_monitoringUnTalkback.png';
|
state.talkStatus.value == TalkStatus.duringCall.index;
|
||||||
case 9:
|
return buildIconButton(
|
||||||
return 'images/main/icon_lockDetail_monitoringTalkback.png';
|
icon: isDuringCall
|
||||||
default:
|
? 'images/main/icon_lockDetail_monitoringUnTalkback.png'
|
||||||
return 'images/main/icon_lockDetail_monitoringAnswerCalls.png';
|
: 'images/main/icon_lockDetail_monitoringAnswerCalls.png',
|
||||||
}
|
label: isDuringCall ? '长按说话'.tr : '接听'.tr,
|
||||||
|
onTap: () async {
|
||||||
|
if (!state.isClickAnswer.value) {
|
||||||
|
logic.initiateAnswerCommand();
|
||||||
|
state.isClickAnswer.value = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
state.listAudioData.value = <int>[];
|
||||||
|
// if (state.udpStatus.value == 8) {
|
||||||
|
// state.udpStatus.value = 9;
|
||||||
|
// }
|
||||||
|
logic.startProcessing();
|
||||||
|
},
|
||||||
|
onLongPressUp: () {
|
||||||
|
// if (state.udpStatus.value == 9) {
|
||||||
|
// state.udpStatus.value = 8;
|
||||||
|
// }
|
||||||
|
logic.stopProcessing();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAnswerBtnName() {
|
Widget buildIconButton({
|
||||||
switch (state.udpStatus.value) {
|
required String icon,
|
||||||
case 8:
|
String? label,
|
||||||
return '长按说话'.tr;
|
Color color = Colors.white,
|
||||||
case 9:
|
required Function() onTap,
|
||||||
return '松开发送'.tr;
|
Function()? onLongPress,
|
||||||
default:
|
Function()? onLongPressUp,
|
||||||
return '接听'.tr;
|
}) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget bottomBtnItemWidget(
|
|
||||||
String iconUrl, String name, Color backgroundColor, Function() onClick,
|
|
||||||
{Function()? longPress, Function()? longPressUp}) {
|
|
||||||
final double wh = 80.w;
|
final double wh = 80.w;
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: onClick,
|
onTap: onTap,
|
||||||
onLongPress: longPress,
|
onLongPress: onLongPress,
|
||||||
onLongPressUp: longPressUp,
|
onLongPressUp: onLongPressUp,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 140.h,
|
height: 140.h,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Container(
|
Container(
|
||||||
width: wh,
|
width: wh,
|
||||||
height: wh,
|
height: wh,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: backgroundColor,
|
color: color,
|
||||||
borderRadius: BorderRadius.circular((wh + 10.w * 2) / 2)),
|
borderRadius: BorderRadius.circular((wh + 10.w * 2) / 2),
|
||||||
padding: EdgeInsets.all(20.w),
|
|
||||||
child: Image.asset(iconUrl, fit: BoxFit.fitWidth),
|
|
||||||
),
|
),
|
||||||
|
padding: EdgeInsets.all(20.w),
|
||||||
|
child: Image.asset(icon, fit: BoxFit.fitWidth),
|
||||||
|
),
|
||||||
|
if (label != null) ...[
|
||||||
SizedBox(height: 20.w),
|
SizedBox(height: 20.w),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(name,
|
child: Text(
|
||||||
style: TextStyle(fontSize: 20.sp, color: Colors.white),
|
label,
|
||||||
textAlign: TextAlign.center))
|
style: TextStyle(fontSize: 20.sp, color: Colors.white),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,23 +270,18 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
|||||||
FilteringTextInputFormatter.allow(RegExp('[0-9]')),
|
FilteringTextInputFormatter.allow(RegExp('[0-9]')),
|
||||||
],
|
],
|
||||||
sureClick: () async {
|
sureClick: () async {
|
||||||
//发送删除锁请求
|
|
||||||
if (state.passwordTF.text.isEmpty) {
|
if (state.passwordTF.text.isEmpty) {
|
||||||
logic.showToast('请输入开锁密码'.tr);
|
logic.showToast('请输入开锁密码'.tr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
|
|
||||||
// 开锁
|
|
||||||
// lockID
|
|
||||||
final List<int> numbers = <int>[];
|
final List<int> numbers = <int>[];
|
||||||
final List<int> lockIDData = utf8.encode(state.passwordTF.text);
|
final List<int> lockIDData = utf8.encode(state.passwordTF.text);
|
||||||
numbers.addAll(lockIDData);
|
numbers.addAll(lockIDData);
|
||||||
// topBytes = getFixedLengthList(lockIDData, 20 - lockIDData.length);
|
|
||||||
for (int i = 0; i < 6 - lockIDData.length; i++) {
|
for (int i = 0; i < 6 - lockIDData.length; i++) {
|
||||||
numbers.add(0);
|
numbers.add(0);
|
||||||
}
|
}
|
||||||
logic.udpOpenDoorAction(numbers);
|
//todo: 开门暂未实现
|
||||||
|
// logic.udpOpenDoorAction(numbers);
|
||||||
},
|
},
|
||||||
cancelClick: () {
|
cancelClick: () {
|
||||||
Get.back();
|
Get.back();
|
||||||
@ -318,16 +291,11 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取麦克风权限
|
Future<void> requestMicrophonePermission() async {
|
||||||
Future requestMicrophonePermission() async {
|
|
||||||
await logic.getPermissionStatus().then((bool value) async {
|
await logic.getPermissionStatus().then((bool value) async {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// state.isSenderAudioData.value = false;
|
|
||||||
// AppLog.log("发送接听了");
|
|
||||||
// 刚进来是接听状态,然后改为长按对讲
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,15 +316,12 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
|||||||
}
|
}
|
||||||
final Uint8List pngBytes = byteData.buffer.asUint8List();
|
final Uint8List pngBytes = byteData.buffer.asUint8List();
|
||||||
|
|
||||||
// 获取应用程序的文档目录
|
|
||||||
final Directory directory = await getApplicationDocumentsDirectory();
|
final Directory directory = await getApplicationDocumentsDirectory();
|
||||||
final String imagePath = '${directory.path}/screenshot.png';
|
final String imagePath = '${directory.path}/screenshot.png';
|
||||||
|
|
||||||
// 将截图保存为文件
|
|
||||||
final File imgFile = File(imagePath);
|
final File imgFile = File(imagePath);
|
||||||
await imgFile.writeAsBytes(pngBytes);
|
await imgFile.writeAsBytes(pngBytes);
|
||||||
|
|
||||||
// 将截图保存到相册
|
|
||||||
await ImageGallerySaver.saveFile(imagePath);
|
await ImageGallerySaver.saveFile(imagePath);
|
||||||
|
|
||||||
AppLog.log('截图保存路径: $imagePath');
|
AppLog.log('截图保存路径: $imagePath');
|
||||||
@ -366,30 +331,19 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 收到视频流数据
|
|
||||||
void _getTVDataRefreshUIAction() {
|
void _getTVDataRefreshUIAction() {
|
||||||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
state.getTVDataRefreshUIEvent = eventBus
|
||||||
state.getTVDataRefreshUIEvent =
|
.on<GetTVDataRefreshUI>()
|
||||||
eventBus.on<GetTVDataRefreshUI>().listen((GetTVDataRefreshUI event) async {
|
.listen((GetTVDataRefreshUI event) async {
|
||||||
if (event.tvList.isNotEmpty && event.tvList.length > 100) {
|
if (event.tvList.isNotEmpty && event.tvList.length > 100) {
|
||||||
// 比较新旧数据是否相同
|
|
||||||
final Uint8List imageData = Uint8List.fromList(event.tvList);
|
final Uint8List imageData = Uint8List.fromList(event.tvList);
|
||||||
|
|
||||||
if (!listEquals(state.listPhotoData.value, imageData)) {
|
if (!listEquals(state.listPhotoData.value, imageData)) {
|
||||||
// 更新状态
|
|
||||||
state.listPhotoData.value = imageData;
|
state.listPhotoData.value = imageData;
|
||||||
// 设置标志为true,表示需要更新UI
|
|
||||||
state.shouldUpdateUI.value = true;
|
state.shouldUpdateUI.value = true;
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
// 调用setState方法之前检查标志,只有当标志为true时才更新UI
|
|
||||||
if (state.shouldUpdateUI.value) {
|
if (state.shouldUpdateUI.value) {
|
||||||
setState(() {
|
setState(() {});
|
||||||
// 更新UI
|
|
||||||
});
|
|
||||||
// 更新完UI后将标志重新设置为false
|
|
||||||
state.shouldUpdateUI.value = false;
|
state.shouldUpdateUI.value = false;
|
||||||
}
|
}
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
|
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:network_info_plus/network_info_plus.dart';
|
import 'package:network_info_plus/network_info_plus.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/start_chart_talk_status.dart';
|
||||||
|
|
||||||
import '../../../../tools/storage.dart';
|
import '../../../../tools/storage.dart';
|
||||||
|
|
||||||
@ -18,8 +19,8 @@ class LockMonitoringState {
|
|||||||
Future<String?> userMobileIP = NetworkInfo().getWifiIP();
|
Future<String?> userMobileIP = NetworkInfo().getWifiIP();
|
||||||
Future<String?> userUid = Storage.getUid();
|
Future<String?> userUid = Storage.getUid();
|
||||||
|
|
||||||
RxInt udpStatus =
|
// RxInt udpStatus =
|
||||||
0.obs; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中 9:长按说话
|
// 0.obs; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中 9:长按说话
|
||||||
TextEditingController passwordTF = TextEditingController();
|
TextEditingController passwordTF = TextEditingController();
|
||||||
|
|
||||||
Rx<Uint8List> listPhotoData = Uint8List(0).obs; //得到的视频流字节数据
|
Rx<Uint8List> listPhotoData = Uint8List(0).obs; //得到的视频流字节数据
|
||||||
@ -31,10 +32,6 @@ class LockMonitoringState {
|
|||||||
RxBool isButtonDisabled = false.obs; //是否禁用按钮
|
RxBool isButtonDisabled = false.obs; //是否禁用按钮
|
||||||
final int frameLength = 320; //音视频帧长度为320
|
final int frameLength = 320; //音视频帧长度为320
|
||||||
final int sampleRate = 8000; //音频采样率为8000
|
final int sampleRate = 8000; //音频采样率为8000
|
||||||
// final int volumeHistoryCapacity = 5; //音量历史记录的容量
|
|
||||||
// final double dbOffset = 50.0; //用于音量计算的偏移量
|
|
||||||
// var volumeHistory = <double>[].obs; //用于存储音量历史记录的列表
|
|
||||||
// var smoothedVolumeValue = 0.0.obs; //存储平滑后的音量值
|
|
||||||
RxString errorMessage = ''.obs;
|
RxString errorMessage = ''.obs;
|
||||||
List<List<int>> allFrames = <List<int>>[];
|
List<List<int>> allFrames = <List<int>>[];
|
||||||
|
|
||||||
@ -55,4 +52,6 @@ class LockMonitoringState {
|
|||||||
|
|
||||||
late Timer openDoorTimer = Timer(const Duration(seconds: 1), () {}); //开门命令定时器
|
late Timer openDoorTimer = Timer(const Duration(seconds: 1), () {}); //开门命令定时器
|
||||||
RxInt openDoorSeconds = 0.obs;
|
RxInt openDoorSeconds = 0.obs;
|
||||||
|
|
||||||
|
RxInt talkStatus = 0.obs; //星图对讲状态
|
||||||
}
|
}
|
||||||
|
|||||||
206
lib/main/lockDetail/monitoring/monitoring/star_chart_logic.dart
Normal file
206
lib/main/lockDetail/monitoring/monitoring/star_chart_logic.dart
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:star_lock/app_settings/app_settings.dart';
|
||||||
|
import 'package:star_lock/talk/startChart/events/talk_status_change_event.dart';
|
||||||
|
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/tools/baseGetXController.dart';
|
||||||
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||||
|
import 'lockMonitoring_state.dart';
|
||||||
|
|
||||||
|
class StarChartLogic extends BaseGetXController {
|
||||||
|
final LockMonitoringState state = LockMonitoringState();
|
||||||
|
|
||||||
|
/// 收到Talk发送的状态
|
||||||
|
StreamSubscription? _getTalkStatusRefreshUIEvent;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onReady() {
|
||||||
|
super.onReady();
|
||||||
|
_getTalkStatusRefreshUIAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getTalkStatusRefreshUIAction() {
|
||||||
|
_getTalkStatusRefreshUIEvent = eventBus
|
||||||
|
.on<TalkStatusChangeEvent>()
|
||||||
|
.listen((TalkStatusChangeEvent event) async {
|
||||||
|
state.talkStatus.value = event.newStatus.index;
|
||||||
|
state.oneMinuteTime.value = 0;
|
||||||
|
|
||||||
|
if (state.talkStatus.value == TalkStatus.rejected.index) {
|
||||||
|
_cancelTimers();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.talkStatus.value == TalkStatus.duringCall.index) {
|
||||||
|
_startCallTimer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startCallTimer() {
|
||||||
|
state.oneMinuteTimeTimer.cancel();
|
||||||
|
state.oneMinuteTimeTimer =
|
||||||
|
Timer.periodic(const Duration(seconds: 1), (Timer t) {
|
||||||
|
state.oneMinuteTime.value++;
|
||||||
|
if (state.oneMinuteTime.value >= 60) {
|
||||||
|
t.cancel();
|
||||||
|
initiateHangUpCommand();
|
||||||
|
AppLog.log('通话时间超过60秒,自动挂断');
|
||||||
|
state.oneMinuteTime.value = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _cancelTimers() {
|
||||||
|
state.oneMinuteTimeTimer.cancel();
|
||||||
|
state.answerTimer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发起接听命令
|
||||||
|
void initiateAnswerCommand() {
|
||||||
|
state.answerTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
|
StartChartManage().sendTalkAcceptMessage();
|
||||||
|
state.answerSeconds++;
|
||||||
|
|
||||||
|
if (state.talkStatus.value == TalkStatus.duringCall.index) {
|
||||||
|
state.answerTimer.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.answerSeconds >= 6) {
|
||||||
|
state.answerTimer.cancel();
|
||||||
|
showToast('接听失败'.tr);
|
||||||
|
initiateHangUpCommand();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发起挂断命令
|
||||||
|
void initiateHangUpCommand() {
|
||||||
|
_cancelTimers();
|
||||||
|
StartChartManage().sendTalkRejectMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onFrame(List<int> frame) async {
|
||||||
|
state.allFrames.add(frame);
|
||||||
|
final List<int> concatenatedFrames = concatenateFrames(state.allFrames);
|
||||||
|
AppLog.log('pcm数据:$concatenatedFrames');
|
||||||
|
|
||||||
|
final List<int> pcmBytes = listLinearToULaw(frame);
|
||||||
|
//发起发送录音命令
|
||||||
|
// StartChartManage().sendTalkAudioMessage(pcmBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<int> listLinearToULaw(List<int> pcmList) {
|
||||||
|
return pcmList.map(linearToULaw).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<int> concatenateFrames(List<List<int>> frames) {
|
||||||
|
return frames.expand((frame) => frame).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> startProcessing() async {
|
||||||
|
state.isButtonDisabled.value = true;
|
||||||
|
|
||||||
|
state.voiceProcessor?.addFrameListener(_onFrame);
|
||||||
|
state.voiceProcessor?.addErrorListener(_onError);
|
||||||
|
try {
|
||||||
|
if (await state.voiceProcessor?.hasRecordAudioPermission() ?? false) {
|
||||||
|
await state.voiceProcessor?.start(state.frameLength, state.sampleRate);
|
||||||
|
state.isProcessing.value =
|
||||||
|
await state.voiceProcessor?.isRecording() ?? false;
|
||||||
|
} else {
|
||||||
|
state.errorMessage.value = 'Recording permission not granted';
|
||||||
|
}
|
||||||
|
} on PlatformException catch (ex) {
|
||||||
|
state.errorMessage.value = 'Failed to start recorder: $ex';
|
||||||
|
} finally {
|
||||||
|
state.isButtonDisabled.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onError(VoiceProcessorException error) {
|
||||||
|
state.errorMessage.value = error.message!;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> stopProcessing() async {
|
||||||
|
state.isButtonDisabled.value = true;
|
||||||
|
try {
|
||||||
|
await state.voiceProcessor?.stop();
|
||||||
|
state.voiceProcessor?.removeFrameListener(_onFrame);
|
||||||
|
state.udpSendDataFrameNumber = 0;
|
||||||
|
} on PlatformException catch (ex) {
|
||||||
|
state.errorMessage.value = 'Failed to stop recorder: $ex';
|
||||||
|
} finally {
|
||||||
|
state.isProcessing.value =
|
||||||
|
await state.voiceProcessor?.isRecording() ?? false;
|
||||||
|
state.isButtonDisabled.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int linearToULaw(int pcmVal) {
|
||||||
|
int mask;
|
||||||
|
int seg;
|
||||||
|
int uval;
|
||||||
|
|
||||||
|
if (pcmVal < 0) {
|
||||||
|
pcmVal = 0x84 - pcmVal;
|
||||||
|
mask = 0x7F;
|
||||||
|
} else {
|
||||||
|
pcmVal += 0x84;
|
||||||
|
mask = 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
seg = search(pcmVal);
|
||||||
|
if (seg >= 8) {
|
||||||
|
return 0x7F ^ mask;
|
||||||
|
} else {
|
||||||
|
uval = seg << 4;
|
||||||
|
uval |= (pcmVal >> (seg + 3)) & 0xF;
|
||||||
|
return uval ^ mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int search(int val) {
|
||||||
|
final List<int> table = [
|
||||||
|
0xFF,
|
||||||
|
0x1FF,
|
||||||
|
0x3FF,
|
||||||
|
0x7FF,
|
||||||
|
0xFFF,
|
||||||
|
0x1FFF,
|
||||||
|
0x3FFF,
|
||||||
|
0x7FFF
|
||||||
|
];
|
||||||
|
for (int i = 0; i < table.length; i++) {
|
||||||
|
if (val <= table[i]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return table.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> getPermissionStatus() async {
|
||||||
|
const Permission permission = Permission.microphone;
|
||||||
|
final PermissionStatus status = await permission.status;
|
||||||
|
if (status.isGranted) {
|
||||||
|
return true;
|
||||||
|
} else if (status.isDenied || status.isRestricted) {
|
||||||
|
await requestPermission(permission);
|
||||||
|
} else if (status.isPermanentlyDenied) {
|
||||||
|
openAppSettings();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> requestPermission(Permission permission) async {
|
||||||
|
final PermissionStatus status = await permission.request();
|
||||||
|
if (status.isPermanentlyDenied) {
|
||||||
|
openAppSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user