1.优化注册切出去再回来问题

2.视频对讲优化
3.图传-视频对讲切出去再回来无法接听
4.优化远程开锁--使用蓝牙透传--判断蓝牙状态
This commit is contained in:
sky_min 2025-11-19 12:00:25 +08:00
parent d3969b6ba5
commit b97d7006b3
6 changed files with 262 additions and 17 deletions

View File

@ -1,13 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/login/login/starLock_login_state.dart';
import 'package:star_lock/talk/starChart/handle/impl/udp_talk_ping_handler.dart';
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
import 'package:star_lock/tools/appFirstEnterHandle.dart';
import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/tools/wechat/customer_tool.dart';
@ -16,7 +11,6 @@ import '../../appRouters.dart';
import '../../app_settings/app_colors.dart';
import '../../common/XSConstantMacro/XSConstantMacro.dart';
import '../../tools/commonItem.dart';
import '../../tools/jverify_one_click_login.dart';
import '../../tools/submitBtn.dart';
import '../../tools/tf_loginInput.dart';
import '../../tools/titleAppBar.dart';
@ -193,6 +187,7 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(20),
]),
_agreentWidget(),
SizedBox(height: 50.w),
Obx(() => SubmitBtn(
btnName: '登录'.tr,
@ -234,7 +229,7 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
Widget _agreentWidget() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Obx(() => GestureDetector(
onTap: () {

View File

@ -25,10 +25,10 @@ import 'starLock_register_state.dart';
class StarLockRegisterLogic extends BaseGetXController {
final StarLockRegisterState state = StarLockRegisterState();
late Timer _timer;
Timer? _timer;
void _startTimer() {
_timer = Timer.periodic(1.seconds, (Timer timer) {
_timer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
if (state.currentSecond > 1) {
state.currentSecond--;
} else {
@ -40,7 +40,8 @@ class StarLockRegisterLogic extends BaseGetXController {
}
void _cancelTimer() {
_timer.cancel();
_timer?.cancel();
_timer = null;
// _timer = null;
}
@ -162,4 +163,27 @@ class StarLockRegisterLogic extends BaseGetXController {
await checkIpAction();
}
void clearInputData() {
// /
state.phoneOrEmailController.clear();
state.phoneOrEmailStr.value = '';
//
state.pwdController.clear();
state.pwd.value = '';
//
state.sureController.clear();
state.surePwd.value = '';
//
state.codeController.clear();
state.verificationCode.value = '';
//
_cancelTimer();
state.currentSecond = state.totalSeconds;
state.resetResend();
}
}

View File

@ -89,7 +89,12 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
children: <Widget>[
GestureDetector(
onTap: () {
//
if (!state.isIphoneType.value) {
logic.clearInputData();
}
state.isIphoneType.value = true;
FocusScope.of(context).unfocus();
},
child: Obx(
() => Container(
@ -113,6 +118,11 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Expanded(
child: GestureDetector(
onTap: () {
//
if (state.isIphoneType.value) {
logic.clearInputData();
FocusScope.of(context).unfocus();
}
state.isIphoneType.value = false;
},
child: Obx(

View File

@ -696,6 +696,18 @@ class LockDetailLogic extends BaseGetXController {
final lockPeerId = StartChartManage().lockPeerId;
final LockListInfoGroupEntity? lockListInfoGroupEntity = await Storage.getLockMainListData();
//
final connectedDevices = await FlutterBluePlus.connectedDevices;
final isDeviceConnected = connectedDevices.any((device) =>
device.remoteId.str == BlueManage().connectDeviceName);
if (!isDeviceConnected) {
AppLog.log('蓝牙已断开,尝试重新连接');
// token
await _reconnectAndRefreshToken();
}
if (lockListInfoGroupEntity != null) {
lockListInfoGroupEntity!.groupList?.forEach((element) {
final lockList = element.lockList;
@ -712,7 +724,11 @@ class LockDetailLogic extends BaseGetXController {
}
});
}
if (remoteUnlock == 1) {
//
await _sendUnlockViaBluetooth();
// api
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
if (entity.errorCode!.codeIsSuccessful) {
showToast('已开锁'.tr);
@ -721,6 +737,179 @@ class LockDetailLogic extends BaseGetXController {
}
}
//
Future<void> _sendUnlockViaBluetooth() async {
try {
//
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyList = changeStringListToIntList(signKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> tokenList = changeStringListToIntList(token!);
//
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: tokenList,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
//
final List<int> messageDetail = openLockCommand.packageData();
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
AppLog.log('通过蓝牙透传发送远程开锁命令');
// token不一致的情况
_listenForOpenLockReply(tokenList);
} catch (e) {
AppLog.log('蓝牙透传开锁异常: $e');
showToast('蓝牙透传开锁失败'.tr);
}
}
// token验证
void _listenForOpenLockReply(List<int> originalToken) {
StreamSubscription<Reply>? subscription;
//
subscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is OpenDoorReply) {
final int status = reply.data[6];
// token不一致的情况(0x06)
if (status == 0x06) {
AppLog.log('token不一致使用新token重新开锁');
// token
final List<int> newToken = reply.data.sublist(2, 6);
// token到存储
final List<String> saveStrList = changeIntListToStringList(newToken);
Storage.setStringList(saveBlueToken, saveStrList);
// 使token重新发送开锁命令
await _reSendUnlockWithNewToken(newToken);
}
//
subscription?.cancel();
}
});
//
Timer(const Duration(seconds: 10), () {
subscription?.cancel();
});
}
// 使token重新发送开锁命令
Future<void> _reSendUnlockWithNewToken(List<int> newToken) async {
try {
//
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyList = changeStringListToIntList(signKey!);
//
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: newToken,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
//
final List<int> messageDetail = openLockCommand.packageData();
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
AppLog.log('使用新token重新发送开锁命令');
} catch (e) {
AppLog.log('使用新token重新开锁异常: $e');
showToast('重新开锁失败'.tr);
}
}
// token
Future<void> _reconnectAndRefreshToken() async {
try {
//
await BlueManage().blueSendData(
state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
AppLog.log('蓝牙重新连接成功');
// token
await _refreshLockToken();
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
AppLog.log('蓝牙重新连接失败');
showToast('蓝牙连接失败,请重试'.tr);
}
},
);
} catch (e) {
AppLog.log('蓝牙重连异常: $e');
showToast('蓝牙连接异常,请重试'.tr);
}
}
// token
Future<void> _refreshLockToken() async {
try {
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> tokenList = changeStringListToIntList(token!);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> privateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyList = changeStringListToIntList(signKey!);
// token的命令
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: tokenList,
needAuthor: 1,
signKey: signKeyList,
privateKey: privateKeyList,
);
// token更新完成
await Future.delayed(Duration(milliseconds: 500));
} catch (e) {
AppLog.log('刷新token异常: $e');
}
}
///
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
// eventBus

View File

@ -161,6 +161,18 @@ class StartChartManage {
await reportInformation();
}
//
Future<void> establishConnection({required String ToPeerId}) async {
//
await init(); //
//
await Future.wait([
startSendingRbcuInfoMessages(ToPeerId: ToPeerId),
startSendingRbcuProbeTMessages(),
] as Iterable<Future>);
}
///
Future<void> _clientRegister(LoginData? loginData) async {
if (loginData?.starchart?.starchartId != null) {
@ -457,7 +469,7 @@ class StartChartManage {
//
talkRequestTimer ??= Timer.periodic(
Duration(
seconds: _defaultIntervalTime,
milliseconds: 500,
),
(Timer timer) async {
AppLog.log('发送对讲请求:${ToPeerId}');
@ -719,7 +731,14 @@ class StartChartManage {
FromPeerId: FromPeerId,
MessageId: MessageCommand.getNextMessageId(ToPeerId, increment: true),
);
await _sendMessage(message: message);
try {
await _sendMessage(message: message);
} catch (e) {
//
AppLog.log('发送挂断消息失败: $e');
//
}
}
//
@ -800,9 +819,16 @@ class StartChartManage {
//
Future<void> _sendMessage({required List<int> message}) async {
var result = await _udpSocket?.send(message, InternetAddress(remoteHost), remotePort);
if (result != message.length) {
throw StartChartMessageException('❌Udp send data error----> $result ${message.length}');
// _udpSocket = null;
//
try {
// UDP发送逻辑
} catch (e) {
//
if (result != message.length) {
throw StartChartMessageException('❌Udp send data error----> $result ${message.length}');
// _udpSocket = null;
}
print('对讲消息发送失败: $e');
}
//ToDo:

View File

@ -68,9 +68,10 @@ class AppLifecycleObserver extends WidgetsBindingObserver {
status == TalkStatus.proactivelyCallWaitingAnswer ||
status == TalkStatus.answeredSuccessfully ||
status == TalkStatus.uninitialized) {
Get.back();
// Get.back(); //
}
StartChartManage().destruction();
//
// StartChartManage().destruction();
_readMessageRefreshUIEvent?.cancel();
}