style:将对讲时的开门调整为使用http

This commit is contained in:
liyi 2025-01-24 11:05:28 +08:00
parent cea20dff00
commit d2b3ce2a3b
8 changed files with 253 additions and 197 deletions

View File

@ -10,6 +10,7 @@ class LockListInfoEntity {
? LockListInfoGroupEntity.fromJson(json['data'])
: null;
}
int? errorCode;
String? description;
String? errorMsg;
@ -43,6 +44,7 @@ class LockListInfoGroupEntity {
pages = json['pages'];
total = json['total'];
}
List<GroupList>? groupList;
int? pageNo;
int? pageSize;
@ -75,6 +77,7 @@ class GroupList {
});
}
}
String? groupName;
int? groupId;
List<LockListInfoItemEntity>? lockList;
@ -143,6 +146,7 @@ class LockListInfoItemEntity {
this.mac,
this.initUserNo,
this.updateDate,
this.network,
});
LockListInfoItemEntity.fromJson(Map<String, dynamic> json) {
@ -189,7 +193,11 @@ class LockListInfoItemEntity {
mac = json['mac'];
initUserNo = json['initUserNo'];
updateDate = json['updateDate'];
network = json['network'] != null
? NetworkInfo.fromJson(json['network'])
: null;
}
int? keyId;
int? lockId;
String? lockName;
@ -227,6 +235,7 @@ class LockListInfoItemEntity {
String? mac;
int? initUserNo;
int? updateDate;
NetworkInfo? network;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
@ -273,6 +282,9 @@ class LockListInfoItemEntity {
data['mac'] = mac;
data['initUserNo'] = initUserNo;
data['updateDate'] = updateDate;
if (network != null) {
data['network'] = network!.toJson();
}
return data;
}
@ -301,6 +313,7 @@ class Bluetooth {
privateKey = json['privateKey'].cast<int>();
signKey = json['signKey'].cast<int>();
}
String? bluetoothDeviceId;
String? bluetoothDeviceName;
List<int>? publicKey;
@ -348,6 +361,7 @@ class LockFeature {
isSupportBackupBattery = json['isSupportBackupBattery'];
isNoSupportedBlueBroadcast = json['isNoSupportedBlueBroadcast'];
}
int? password;
int? icCard;
int? fingerprint;
@ -391,6 +405,7 @@ class LockSetting {
appUnlockOnline = json['appUnlockOnline'];
remoteUnlock = json['remoteUnlock'];
}
int? attendance;
int? appUnlockOnline;
int? remoteUnlock;
@ -403,3 +418,21 @@ class LockSetting {
return data;
}
}
class NetworkInfo {
NetworkInfo({
this.peerId,
});
NetworkInfo.fromJson(Map<String, dynamic> json) {
peerId = json['peerId'];
}
String? peerId;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['peerId'] = peerId;
return data;
}
}

View File

@ -1,4 +1,3 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
@ -6,6 +5,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import '../../../blue/blue_manage.dart';
@ -32,7 +32,6 @@ class LockListLogic extends BaseGetXController {
final ShowTipView showTipView = ShowTipView();
List<GroupList> get groupDataList {
final List<GroupList> list =
_groupDataList.map((GroupList e) => e.copy()).toList();
if (state.searchStr.value != '' && state.showSearch.value) {
@ -41,6 +40,20 @@ class LockListLogic extends BaseGetXController {
!(element.lockAlias?.contains(state.searchStr.value) ?? true));
});
}
if (list.length > 0) {
StartChartManage().lockListPeerId.clear();
list.forEach((element) {
final lockList = element.lockList;
if (lockList != null && lockList.length > 0) {
lockList.forEach((element) {
if (element.network?.peerId != null &&
element.network?.peerId != '') {
StartChartManage().lockListPeerId.add(element);
}
});
}
});
}
return list;
}
@ -142,7 +155,7 @@ class LockListLogic extends BaseGetXController {
} else {
return XSConstantMacro.getKeyStatusStr(keyInfo.keyStatus!);
}
}else if (keyInfo.keyType == XSConstantMacro.keyTypeOnce){
} else if (keyInfo.keyType == XSConstantMacro.keyTypeOnce) {
return XSConstantMacro.getKeyStatusStr(keyInfo.keyStatus!);
}
return '';
@ -185,11 +198,13 @@ class LockListLogic extends BaseGetXController {
//
AppLog.log('调用了删除锁');
showTipView.resetGetController();
showTipView.showTFViewAlertDialog(state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, checkLoginPassword);
showTipView.showTFViewAlertDialog(
state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, checkLoginPassword);
});
} else if (state.lockListInfoItemEntity.keyRight == 1) {
//
showTipView.showDeleteAdministratorIsHaveAllDataDialog('同时删除其发送的所有钥匙,钥匙删除后不能恢复'.tr, (bool a) {
showTipView.showDeleteAdministratorIsHaveAllDataDialog(
'同时删除其发送的所有钥匙,钥匙删除后不能恢复'.tr, (bool a) {
//
state.deleteAdministratorIsHaveAllData.value = a;
deletKeyData();

View File

@ -22,7 +22,7 @@ class UdpGoOnlineHandler extends ScpMessageBaseHandle
final responseType = loginResponse.responseType;
if (responseType != null &&
responseType == PayloadTypeConstant.loginSuccessResponse) {
startChartManage.isOnlineStartChartServer = true;
startChartManage.isOnlineStarChartServer = true;
// 线
startChartManage.stopReStartOnlineStartChartServer();
log(text: '星图登录成功,PeerID:${scpMessage.ToPeerId}');

View File

@ -25,7 +25,7 @@ class UdpHeartBeatHandler extends ScpMessageBaseHandle
//
startChartManage.stopHeartbeat();
// 线
startChartManage.isOnlineStartChartServer = false;
startChartManage.isOnlineStarChartServer = false;
startChartManage.reStartOnlineStartChartServer();
} else {
//

View File

@ -30,6 +30,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
final TalkReq talkReq = scpMessage.Payload;
startChartManage.FromPeerId = scpMessage.ToPeerId!;
startChartManage.ToPeerId = scpMessage.FromPeerId!;
startChartManage.lockPeerId = scpMessage.FromPeerId!;
//
_talkRequestEvent(talkObjectName: talkReq.callerName);
}

View File

@ -12,6 +12,7 @@ import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/login/login/entity/LoginData.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/network/start_chart_api.dart';
import 'package:star_lock/talk/other/audio_player_manager.dart';
@ -79,12 +80,13 @@ class StartChartManage {
String ToPeerId = ''; // ID
String FromPeerId = ''; // ID
String lockPeerId = '';
String lockPeerId = ''; // peerId
List<LockListInfoItemEntity> lockListPeerId = []; // peerId
// echo测试peer对端
final String echoPeerId = '3phX8Ng2cZHz5NtP8xAf6nYy2z1BYytoejgjoHrWMGhH';
bool isOnlineStartChartServer = false; // 线
bool isOnlineStarChartServer = false; // 线
Timer? reStartOnlineStartChartServerTimer; // 线
Timer? talkPingTimer; //
Timer? talkExpectTimer; //
@ -119,7 +121,7 @@ class StartChartManage {
//
final loginData = await Storage.getLoginData();
if ((isOnlineStartChartServer && _udpSocket != null) || loginData == null) {
if ((isOnlineStarChartServer && _udpSocket != null) || loginData == null) {
// 线
return;
}
@ -391,7 +393,7 @@ class StartChartManage {
// 线
Future<void> _sendOnlineMessage() async {
if (isOnlineStartChartServer) {
if (isOnlineStarChartServer) {
_log(text: '星图已上线,请勿重复发送上线消息');
return;
}
@ -670,7 +672,7 @@ class StartChartManage {
// 线
Future<void> reStartOnlineStartChartServer() async {
if (isOnlineStartChartServer) {
if (isOnlineStarChartServer) {
_log(text: '星图已上线,请勿重复发送上线消息');
return;
}
@ -714,17 +716,16 @@ class StartChartManage {
// _udpSocket = null;
}
// print('发送消息');
//ToDo:
UdpTalkDataHandler().updateSendDataRate(message.length);
//
Provider.of<DebugInfoModel>(Get.context!, listen: false).updateDebugInfo(
UdpTalkDataHandler().getLastRecvDataRate() ~/ 1024, // KB
UdpTalkDataHandler().getLastRecvPacketCount(),
UdpTalkDataHandler().getLastSendDataRate() ~/ 1024, // KB
UdpTalkDataHandler().getLastSendPacketCount(),
);
// UdpTalkDataHandler().updateSendDataRate(message.length);
//
// //
// Provider.of<DebugInfoModel>(Get.context!, listen: false).updateDebugInfo(
// UdpTalkDataHandler().getLastRecvDataRate() ~/ 1024, // KB
// UdpTalkDataHandler().getLastRecvPacketCount(),
// UdpTalkDataHandler().getLastSendDataRate() ~/ 1024, // KB
// UdpTalkDataHandler().getLastSendPacketCount(),
// );
}
//
@ -1101,9 +1102,10 @@ class StartChartManage {
}
///
Future<void> destruction() async {
// sendTalkHangupMessage();
isOnlineStartChartServer = false;
void destruction() async {
//
sendTalkHangupMessage();
isOnlineStarChartServer = false;
//
stopHeartbeat();
//
@ -1120,8 +1122,12 @@ class StartChartManage {
stopSendingRbcuConfirmMessages();
//
_resetData();
//
await Storage.removerRelayInfo();
//
await Storage.removerStarChartRegisterNodeInfo();
// udp服务
closeUdpSocket();
}
///
@ -1130,6 +1136,7 @@ class StartChartManage {
videoType: [VideoTypeE.IMAGE],
audioType: [AudioTypeE.G711],
);
isOnlineStartChartServer = false;
isOnlineStarChartServer = false;
talkStatus.setUninitialized();
}
}

View File

@ -21,9 +21,12 @@ import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/blue/io_protocol/io_openLock.dart';
import 'package:star_lock/blue/io_tool/io_tool.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_logic.dart';
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_state.dart';
import 'package:star_lock/main/lockDetail/lockDetail/lockNetToken_entity.dart';
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
import 'package:star_lock/main/lockMian/lockList/lockList_logic.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/talk/call/g711.dart';
import 'package:star_lock/talk/starChart/constant/talk_status.dart';
@ -98,8 +101,6 @@ class TalkViewLogic extends BaseGetXController {
state.videoBuffer.removeAt(0); //
}
state.videoBuffer.add(talkData); //
///
// updateNetworkStatus(currentTimestamp);
break;
}
});
@ -233,36 +234,6 @@ class TalkViewLogic extends BaseGetXController {
}
}
///
void updateNetworkStatus(int currentTimestamp) {
if (state.lastFrameTimestamp.value != 0) {
final frameInterval = currentTimestamp - state.lastFrameTimestamp.value;
if (frameInterval > 500 && frameInterval <= 1000) {
// 5001
state.networkStatus.value = NetworkStatus.lagging;
// showNetworkStatus("Network is lagging");
} else if (frameInterval > 1000) {
// 1
state.networkStatus.value = NetworkStatus.delayed;
// showNetworkStatus("Network is delayed");
} else {
state.networkStatus.value = NetworkStatus.normal;
state.alertCount.value = 0; //
}
}
state.lastFrameTimestamp.value = currentTimestamp;
}
///
void showNetworkStatus(String message) {
// EasyLoading
if (state.alertCount.value < state.maxAlertNumber.value &&
!EasyLoading.isShow) {
showToast(message);
state.alertCount++;
}
}
///
void _stopPlayG711Data() async {
await FlutterPcmSound.pause();
@ -271,44 +242,44 @@ class TalkViewLogic extends BaseGetXController {
}
///
udpOpenDoorAction() async {
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!);
await _getLockNetToken();
final OpenLockCommand openLockCommand = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: lockDetailState.openDoorModel,
openTime: _getUTCNetTime(),
onlineToken: lockDetailState.lockNetToken,
token: getTokenList,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
final messageDetail = openLockCommand.packageData();
// List<int>
String hexString = messageDetail
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
.join(' ');
AppLog.log('open lock hexString: $hexString');
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
openLockCommand: messageDetail,
);
showToast('正在开锁中...'.tr);
}
// udpOpenDoorAction() async {
// final List<String>? privateKey =
// await Storage.getStringList(saveBluePrivateKey);
// final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
//
// final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
// final List<int> signKeyDataList = changeStringListToIntList(signKey!);
//
// final List<String>? token = await Storage.getStringList(saveBlueToken);
// final List<int> getTokenList = changeStringListToIntList(token!);
//
// await _getLockNetToken();
//
// final OpenLockCommand openLockCommand = OpenLockCommand(
// lockID: BlueManage().connectDeviceName,
// userID: await Storage.getUid(),
// openMode: lockDetailState.openDoorModel,
// openTime: _getUTCNetTime(),
// onlineToken: lockDetailState.lockNetToken,
// token: getTokenList,
// needAuthor: 1,
// signKey: signKeyDataList,
// privateKey: getPrivateKeyList,
// );
// final messageDetail = openLockCommand.packageData();
// // List<int>
// String hexString = messageDetail
// .map((byte) => byte.toRadixString(16).padLeft(2, '0'))
// .join(' ');
//
// AppLog.log('open lock hexString: $hexString');
// //
// StartChartManage().sendRemoteUnLockMessage(
// bluetoothDeviceName: BlueManage().connectDeviceName,
// openLockCommand: messageDetail,
// );
// showToast('正在开锁中...'.tr);
// }
int _getUTCNetTime() {
if (lockDetailState.isHaveNetwork) {
@ -524,6 +495,34 @@ class TalkViewLogic extends BaseGetXController {
}
}
//
Future<void> remoteOpenLock() async {
final lockPeerId = StartChartManage().lockPeerId;
final lockListPeerId = StartChartManage().lockListPeerId;
int lockId = 0;
if (lockListPeerId.length == 0) {
// peerId使lockId
lockId = lockDetailState.keyInfos.value.lockId ?? 0;
} else {
// peerId使peerId
// peerId
lockId = lockListPeerId
.firstWhere(
(element) => element.network?.peerId == lockPeerId,
orElse: () => LockListInfoItemEntity(), // null
)
?.lockId ??
0;
}
if (lockPeerId.isNotEmpty) {}
final LoginEntity entity = await ApiRepository.to
.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
if (entity.errorCode!.codeIsSuccessful) {
showToast('已开锁'.tr);
StartChartManage().lockListPeerId = [];
}
}
///
void _initAudioRecorder() {
state.voiceProcessor = VoiceProcessor.instance;

View File

@ -56,31 +56,31 @@ class _TalkViewPageState extends State<TalkViewPage>
}
});
_latencyStream = measureServerLatencyStream(F.apiPrefix); //
}
Stream<int> measureServerLatencyStream(String url) async* {
while (true) {
final latency = await measureServerLatency(url);
yield latency;
await Future.delayed(Duration(seconds: 1)); //
}
}
Future<int> measureServerLatency(String url) async {
final Stopwatch stopwatch = Stopwatch()..start();
try {
final http.Response response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
stopwatch.stop();
return stopwatch.elapsedMilliseconds;
} else {
return -1; //
}
} catch (e) {
return -1; //
}
// _latencyStream = measureServerLatencyStream(F.apiPrefix); //
}
//
// Stream<int> measureServerLatencyStream(String url) async* {
// while (true) {
// final latency = await measureServerLatency(url);
// yield latency;
// await Future.delayed(Duration(seconds: 1)); //
// }
// }
//
// Future<int> measureServerLatency(String url) async {
// final Stopwatch stopwatch = Stopwatch()..start();
// try {
// final http.Response response = await http.get(Uri.parse(url));
// if (response.statusCode == 200) {
// stopwatch.stop();
// return stopwatch.elapsedMilliseconds;
// } else {
// return -1; //
// }
// } catch (e) {
// return -1; //
// }
// }
@override
Widget build(BuildContext context) {
@ -255,40 +255,40 @@ class _TalkViewPageState extends State<TalkViewPage>
)
: Container()),
//ToDo:
// Visibility(
// visible: true,
// child: Positioned(
// top: 20, //
// left: 20,
// right: 20, //
// child: Container(
// height: 100, // 100
// color: Colors.black.withOpacity(0.5), //
// padding: const EdgeInsets.all(10), //
// child: Consumer<DebugInfoModel>(
// builder: (BuildContext context, DebugInfoModel debugInfo,
// Widget? child) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Text(
// 'recv ${debugInfo.recvDataRate}KB/s [${debugInfo.recvPacketCount}]',
// style: const TextStyle(
// color: Colors.white), //
// ),
// Text(
// 'send ${debugInfo.sendDataRate}KB/s [${debugInfo.sendPacketCount}]',
// style: const TextStyle(
// color: Colors.white), //
// ),
// ],
// );
// },
// ),
// ),
// ),
// ),
// //
Visibility(
visible: true,
child: Positioned(
top: 20, //
left: 20,
right: 20, //
child: Container(
height: 100, // 100
color: Colors.black.withOpacity(0.5), //
padding: const EdgeInsets.all(10), //
child: Consumer<DebugInfoModel>(
builder: (BuildContext context, DebugInfoModel debugInfo,
Widget? child) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'recv ${debugInfo.recvDataRate}KB/s [${debugInfo.recvPacketCount}]',
style: const TextStyle(
color: Colors.white), //
),
Text(
'send ${debugInfo.sendDataRate}KB/s [${debugInfo.sendPacketCount}]',
style: const TextStyle(
color: Colors.white), //
),
],
);
},
),
),
),
),
//
// Positioned(
// top: 120,
// left: 20,
@ -455,10 +455,11 @@ class _TalkViewPageState extends State<TalkViewPage>
'开锁'.tr,
AppColors.mainColor,
onClick: () {
if (state.talkStatus.value == TalkStatus.answeredSuccessfully &&
state.listData.value.length > 0) {
logic.udpOpenDoorAction();
}
// if (state.talkStatus.value == TalkStatus.answeredSuccessfully &&
// state.listData.value.length > 0) {
// logic.udpOpenDoorAction();
logic.remoteOpenLock();
// }
// if (UDPManage().remoteUnlock == 1) {
// logic.udpOpenDoorAction();
// showDeletPasswordAlertDialog(context);
@ -534,45 +535,45 @@ class _TalkViewPageState extends State<TalkViewPage>
);
}
void showDeletPasswordAlertDialog(BuildContext context) {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return ShowTFView(
title: '请输入6位数字开锁密码'.tr,
tipTitle: '',
controller: state.passwordTF,
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(6), //
FilteringTextInputFormatter.allow(RegExp('[0-9]')),
],
sureClick: () async {
//
// if (state.passwordTF.text.isEmpty) {
// logic.showToast('请输入开锁密码'.tr);
// return;
// }
// List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
//
// lockID
// final List<int> numbers = <int>[];
// final List<int> lockIDData = utf8.encode(state.passwordTF.text);
// numbers.addAll(lockIDData);
// // topBytes = getFixedLengthList(lockIDData, 20 - lockIDData.length);
// for (int i = 0; i < 6 - lockIDData.length; i++) {
// numbers.add(0);
// }
logic.udpOpenDoorAction();
},
cancelClick: () {
Get.back();
},
);
},
);
}
// void showDeletPasswordAlertDialog(BuildContext context) {
// showDialog(
// barrierDismissible: false,
// context: context,
// builder: (BuildContext context) {
// return ShowTFView(
// title: '请输入6位数字开锁密码'.tr,
// tipTitle: '',
// controller: state.passwordTF,
// inputFormatters: <TextInputFormatter>[
// LengthLimitingTextInputFormatter(6), //
// FilteringTextInputFormatter.allow(RegExp('[0-9]')),
// ],
// sureClick: () async {
// //
// // if (state.passwordTF.text.isEmpty) {
// // logic.showToast('请输入开锁密码'.tr);
// // return;
// // }
//
// // List<int> numbers = state.passwordTF.text.split('').map((char) => int.parse(char)).toList();
// //
// // lockID
// // final List<int> numbers = <int>[];
// // final List<int> lockIDData = utf8.encode(state.passwordTF.text);
// // numbers.addAll(lockIDData);
// // // topBytes = getFixedLengthList(lockIDData, 20 - lockIDData.length);
// // for (int i = 0; i < 6 - lockIDData.length; i++) {
// // numbers.add(0);
// // }
// // logic.udpOpenDoorAction();
// },
// cancelClick: () {
// Get.back();
// },
// );
// },
// );
// }
//
Widget buildRotationTransition() {