style:将对讲时的开门调整为使用http
This commit is contained in:
parent
cea20dff00
commit
d2b3ce2a3b
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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}');
|
||||
|
||||
@ -25,7 +25,7 @@ class UdpHeartBeatHandler extends ScpMessageBaseHandle
|
||||
// 心跳回复失败,停止发送心跳
|
||||
startChartManage.stopHeartbeat();
|
||||
// 心跳响应失败,重新上线
|
||||
startChartManage.isOnlineStartChartServer = false;
|
||||
startChartManage.isOnlineStarChartServer = false;
|
||||
startChartManage.reStartOnlineStartChartServer();
|
||||
} else {
|
||||
// 修改间隔为返回的心跳间隔
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
// 判断帧间隔是否在500毫秒到1秒之间
|
||||
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;
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user