接入声网四路视频
This commit is contained in:
@@ -33,6 +33,12 @@ import '../models/pv_telemetry.dart';
|
||||
import '../channel/pv_robot_command_channel.dart';
|
||||
import '../models/pv_video_fit.dart';
|
||||
import '../models/pv_video_source.dart';
|
||||
import '../../domain/usecases/get_pv_agora_credentials_usecase.dart';
|
||||
import '../../domain/usecases/start_pv_agora_video_stream_usecase.dart';
|
||||
import '../../domain/video/pv_agora_config.dart';
|
||||
import '../video/pv_agora_session.dart';
|
||||
import '../video/pv_agora_scope.dart';
|
||||
import '../widgets/pv_agora_config_dialog.dart';
|
||||
import '../theme/pv_colors.dart';
|
||||
import '../widgets/pv_control_bar.dart';
|
||||
import '../widgets/pv_info_column.dart';
|
||||
@@ -119,6 +125,11 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
/// 当前视频链路(多源可扩展):在设置面板「视频源」行切换,
|
||||
/// 切换即重建对应链路 cubit(_wrapVideoProvider 挂了 ValueKey)。
|
||||
PvVideoSource _videoSource = PvVideoSource.usbCamera;
|
||||
String get _deviceSn => widget.deviceId.trim();
|
||||
PvAgoraConfig? _agoraConfig;
|
||||
final PvAgoraSession _agoraSession = PvAgoraSession();
|
||||
|
||||
bool _editingVideoConfig = false;
|
||||
|
||||
/// 视频展示方式(设置面板「视频展示」行切换):
|
||||
/// contain 完整显示(可能留黑边)/ cover 等比铺满(裁掉边缘)。
|
||||
@@ -170,6 +181,17 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
// 控制会话由模式确认完成后的回调建立。
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant PvControlPage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.deviceId.trim() == _deviceSn) return;
|
||||
_agoraConfig = null;
|
||||
if (_videoSource == PvVideoSource.agoraRtc) {
|
||||
_videoSource = PvVideoSource.usbCamera;
|
||||
unawaited(_agoraSession.disconnect());
|
||||
}
|
||||
}
|
||||
|
||||
/// 本页的视频、地图、遥测都是围绕 `deviceId` 这一台设备,所以进页时确保
|
||||
/// MQTT 实时定位/路线订阅就指向它(全局单例 bloc,数据源内部同 SN 去重、
|
||||
/// 自动退旧订新,重复调用无副作用)。退出页面不切回去:语义与设备列表
|
||||
@@ -211,6 +233,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_agoraSession.dispose();
|
||||
// 离开安全模式:启动 90 秒倒计时(与远程遥控页一致)。
|
||||
sl<AuthCubit>().exitSafeMode();
|
||||
// 取消「权限交接」弹窗监听,避免回调打到已销毁的 State。
|
||||
@@ -568,7 +591,45 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
simObstacle: _simObstacle,
|
||||
simReverse: _simReverse,
|
||||
showJoysticks: _showJoysticks,
|
||||
onVideoSourceChanged: (v) => update(() => _videoSource = v),
|
||||
onVideoSourceChanged: (v) async {
|
||||
if (_editingVideoConfig) return;
|
||||
if (v == PvVideoSource.agoraRtc) {
|
||||
final sn = _deviceSn;
|
||||
if (sn.isEmpty) {
|
||||
CapsuleToast.show('请先选择设备');
|
||||
return;
|
||||
}
|
||||
_editingVideoConfig = true;
|
||||
PvAgoraConfig? config;
|
||||
try {
|
||||
config = await showPvAgoraConfigDialog(
|
||||
sheetCtx,
|
||||
_agoraConfig ??
|
||||
PvAgoraConfig(appId: '', channel: sn, token: ''),
|
||||
loadCredentials: sl<GetPvAgoraCredentialsUseCase>().call,
|
||||
startVideoStream: sl<StartPvAgoraVideoStreamUseCase>().call,
|
||||
);
|
||||
} finally {
|
||||
_editingVideoConfig = false;
|
||||
}
|
||||
if (!mounted ||
|
||||
!sheetCtx.mounted ||
|
||||
config == null ||
|
||||
sn != _deviceSn) {
|
||||
return;
|
||||
}
|
||||
final confirmed = config;
|
||||
update(() {
|
||||
_agoraConfig = confirmed;
|
||||
_videoSource = v;
|
||||
});
|
||||
unawaited(_agoraSession.connect(confirmed));
|
||||
} else {
|
||||
if (v == _videoSource) return;
|
||||
unawaited(_agoraSession.disconnect());
|
||||
update(() => _videoSource = v);
|
||||
}
|
||||
},
|
||||
onVideoFitChanged: (v) => update(() => _videoFit = v),
|
||||
onSimObstacleChanged: (v) => update(() => _simObstacle = v),
|
||||
// 倒车影像:不靠面板回传的 value 取反(面板是独立 Route,
|
||||
@@ -667,6 +728,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
child: child,
|
||||
);
|
||||
case PvVideoSource.webrtc:
|
||||
case PvVideoSource.agoraRtc:
|
||||
return child;
|
||||
}
|
||||
}
|
||||
@@ -680,7 +742,10 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
cancelToPreview: true,
|
||||
emergencyStopControl: const EmergencyStopButton(),
|
||||
onReady: _startControl,
|
||||
child: _buildPage(context),
|
||||
child: PvAgoraScope(
|
||||
session: _agoraSession,
|
||||
child: _buildPage(context),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildPage(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user