完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -8,7 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../../../../core/app/app_user_cubit.dart';
|
||||
@@ -19,6 +19,7 @@ import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
import '../widgets/center_control_area.dart';
|
||||
import '../widgets/emergency_overlay.dart';
|
||||
import '../widgets/emergency_stop_button.dart';
|
||||
import '../widgets/left_joystick_area.dart';
|
||||
import '../widgets/right_joystick_area.dart';
|
||||
import '../widgets/driving_guide_overlay.dart';
|
||||
@@ -120,33 +121,30 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
// 🔥 离开安全模式:启动 90 秒倒计时
|
||||
GetIt.I<AuthCubit>().exitSafeMode();
|
||||
|
||||
// 释放远程控制权限(type=2:退出远程遥控页面释放)
|
||||
// Schedule the priority zero before ending control; release only after the
|
||||
// rate-limited stop finishes, so release cannot overtake the final stop.
|
||||
final pendingStop = _controlSessionStarted
|
||||
? _cubit.stopAllMovement(reason: 'page_dispose')
|
||||
: Future<void>.value();
|
||||
if (_controlSessionStarted) _cubit.stopControlLoop();
|
||||
final deviceId = _cubit.state.targetDevice?.deviceName;
|
||||
if (_controlSessionStarted && deviceId != null && deviceId.isNotEmpty) {
|
||||
_cubit.releasePermission(deviceId: deviceId, type: 2).then((success) {
|
||||
CapsuleToast.show(
|
||||
success
|
||||
? _l10n.translate('remote_control.toast_released')
|
||||
: _l10n.translate('remote_control.toast_release_failed'),
|
||||
showCheck: success,
|
||||
);
|
||||
});
|
||||
pendingStop
|
||||
.then((_) => _cubit.releasePermission(deviceId: deviceId, type: 2))
|
||||
.then((success) {
|
||||
CapsuleToast.show(
|
||||
success
|
||||
? _l10n.translate('remote_control.toast_released')
|
||||
: _l10n.translate('remote_control.toast_release_failed'),
|
||||
showCheck: success,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_permissionSubscription?.cancel(); // 🔥 取消订阅
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
// 🔥 退页先把车真正停下:归零双轴 + 连发 30 帧停止指令。
|
||||
// 只靠 stopControlLoop() 断掉 200ms 循环是不够的:设备只认“最后收到的
|
||||
// 运动帧”,若手指还压在摇杆上就退出(没走松手归零),已下发的高速帧会
|
||||
// 让车继续跑到它自己的失联保护为止。与新版 HUD 折叠/退出的 deactivate()
|
||||
// 同一口径。
|
||||
// 必须放在 stopControlLoop() 之前:stopAllMovement 末尾会按 _controlWanted
|
||||
// 决定是否重启循环,这里同步把意图关掉,就不会在退页后留下无主定时器。
|
||||
if (_controlSessionStarted) {
|
||||
unawaited(_cubit.stopAllMovement());
|
||||
_cubit.stopControlLoop();
|
||||
}
|
||||
// The priority stop above uses the same >=250ms sender as normal movement.
|
||||
_cubit.stopReverseCameraMock(); // 🔥 停止倒车影像 Mock,避免定时器空转
|
||||
// 🔥 重置权限状态,避免单例 hasPermission 残留导致下次进入不再查询接口
|
||||
_cubit.resetPermissionState();
|
||||
@@ -158,6 +156,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
deviceId: _modeDeviceId,
|
||||
target: ControlModeTarget.remote,
|
||||
cancelToPreview: true,
|
||||
emergencyStopControl: const EmergencyStopButton(),
|
||||
onReady: () {
|
||||
if (_cubit.state.targetDevice?.deviceName != _modeDeviceId) return;
|
||||
_controlSessionStarted = true;
|
||||
@@ -229,7 +228,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
token != null &&
|
||||
token.isNotEmpty) {
|
||||
_videoStreamUrl =
|
||||
"webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=$token";
|
||||
"webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/$deviceId?token=$token";
|
||||
debugPrint('🎬 [WebRTC] URL构建成功: $_videoStreamUrl');
|
||||
} else {
|
||||
_videoStreamUrl = '';
|
||||
@@ -279,9 +278,11 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
),
|
||||
|
||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
buildWhen: (p, c) => p.isEmergency != c.isEmergency,
|
||||
buildWhen: (p, c) =>
|
||||
p.isEmergency != c.isEmergency ||
|
||||
p.hasEmergencyStatus != c.hasEmergencyStatus,
|
||||
builder: (context, state) {
|
||||
return state.isEmergency
|
||||
return state.isEmergency && state.hasEmergencyStatus
|
||||
? const Positioned.fill(child: EmergencyOverlay())
|
||||
: const SizedBox.shrink();
|
||||
},
|
||||
@@ -300,6 +301,8 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
},
|
||||
buildWhen: (p, c) =>
|
||||
p.hasPermission != c.hasPermission ||
|
||||
p.permissionRequestPhase != c.permissionRequestPhase ||
|
||||
p.permissionFeedbackId != c.permissionFeedbackId ||
|
||||
p.isLocked != c.isLocked ||
|
||||
p.topRightIsExpanded != c.topRightIsExpanded ||
|
||||
p.obstacleRecognitionFlag != c.obstacleRecognitionFlag ||
|
||||
|
||||
Reference in New Issue
Block a user