告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,377 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
// import 'package:volc_engine_rtc/volc_engine_rtc.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../bloc/drone_station_bloc.dart';
|
||||
import '../bloc/drone_station_event.dart';
|
||||
import '../bloc/drone_station_state.dart';
|
||||
|
||||
class DroneMonitorPage extends StatefulWidget {
|
||||
final String gatewaySn;
|
||||
final String cameraIndex;
|
||||
|
||||
const DroneMonitorPage({
|
||||
super.key,
|
||||
required this.gatewaySn,
|
||||
required this.cameraIndex,
|
||||
});
|
||||
|
||||
@override
|
||||
_DroneMonitorPageState createState() => _DroneMonitorPageState();
|
||||
}
|
||||
|
||||
class _DroneMonitorPageState extends State<DroneMonitorPage> {
|
||||
bool isIndoor = false;
|
||||
late DroneStationBloc _bloc;
|
||||
String? videoUrl;
|
||||
bool isLoading = true;
|
||||
String? errorMessage;
|
||||
|
||||
// RTCEngine? _rtcEngine;
|
||||
// RTCRoom? _rtcRoom;
|
||||
// RTCViewContext? _remoteRenderContext;
|
||||
// final IRTCEngineEventHandler _videoHandler = IRTCEngineEventHandler();
|
||||
// final IRTCRoomEventHandler _roomHandler = IRTCRoomEventHandler();
|
||||
|
||||
String? _appId;
|
||||
String? _roomId;
|
||||
String? _token;
|
||||
String? _userId;
|
||||
bool _isJoined = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bloc = sl<DroneStationBloc>();
|
||||
// _initVideoEventHandler();
|
||||
// _initRoomEventHandler();
|
||||
_loadVideoStream();
|
||||
}
|
||||
|
||||
// void _initVideoEventHandler() {
|
||||
// _videoHandler.onFirstRemoteVideoFrameDecoded =
|
||||
// (String streamId, StreamInfo streamInfo, VideoFrameInfo frameInfo) {
|
||||
// debugPrint('onFirstRemoteVideoFrameDecoded: ${streamInfo.userId}');
|
||||
// if (streamInfo.userId.isNotEmpty && mounted && _roomId != null) {
|
||||
// setState(() {
|
||||
// _remoteRenderContext = RTCViewContext.remoteContext(
|
||||
// roomId: _roomId!,
|
||||
// userId: streamInfo.userId,
|
||||
// streamId: streamId,
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
|
||||
// _videoHandler.onWarning = (WarningCode code) {
|
||||
// debugPrint('warningCode: $code');
|
||||
// };
|
||||
|
||||
// _videoHandler.onError = (ErrorCode code) {
|
||||
// debugPrint('errorCode: $code');
|
||||
// if (mounted) {
|
||||
// setState(() {
|
||||
// errorMessage = '视频错误: $code';
|
||||
// isLoading = false;
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
// void _initRoomEventHandler() {
|
||||
// _roomHandler.onUserJoined = (UserInfo userInfo) {
|
||||
// debugPrint('onUserJoined: ${userInfo.userId}');
|
||||
// };
|
||||
|
||||
// _roomHandler.onUserLeave = (String uid, int reason) {
|
||||
// debugPrint('onUserLeave: $uid reason: $reason');
|
||||
// };
|
||||
// }
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_bloc.close();
|
||||
_leaveRoom();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadVideoStream() {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
errorMessage = null;
|
||||
});
|
||||
_leaveRoom();
|
||||
_bloc.add(
|
||||
VideoStreamLoad(
|
||||
sn: widget.gatewaySn,
|
||||
cameraIndex: widget.cameraIndex,
|
||||
cameraPosition: isIndoor ? 'indoor' : 'outdoor',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onCameraPositionChanged(bool indoor) {
|
||||
setState(() {
|
||||
isIndoor = indoor;
|
||||
});
|
||||
_loadVideoStream();
|
||||
}
|
||||
|
||||
void _parseUrlParams(String url) {
|
||||
try {
|
||||
final uri = Uri.parse(url.contains('?') ? 'http://host?$url' : url);
|
||||
final params = uri.queryParameters;
|
||||
|
||||
_appId = params['app_id'];
|
||||
_roomId = params['room_id'];
|
||||
_token = params['token'];
|
||||
_userId =
|
||||
params['user_id'] ?? 'user_${DateTime.now().millisecondsSinceEpoch}';
|
||||
|
||||
print(
|
||||
'Parsed RTC params: appId=$_appId, roomId=$_roomId, userId=$_userId',
|
||||
);
|
||||
} catch (e) {
|
||||
print('Failed to parse URL: $e');
|
||||
errorMessage = '解析视频参数失败';
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> _joinRoom() async {
|
||||
// if (_appId == null || _roomId == null || _token == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// try {
|
||||
// _rtcEngine = await RTCEngine.createRTCEngine(
|
||||
// RTCVideoContext(appId: _appId!, eventHandler: _videoHandler),
|
||||
// );
|
||||
|
||||
// if (_rtcEngine == null) {
|
||||
// setState(() {
|
||||
// errorMessage = '创建引擎失败';
|
||||
// isLoading = false;
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// _rtcRoom = await _rtcEngine?.createRTCRoom(_roomId!);
|
||||
// _rtcRoom?.setRTCRoomEventHandler(_roomHandler);
|
||||
|
||||
// final userInfo = UserInfo(userId: _userId!, extraInfo: "");
|
||||
|
||||
// final roomConfig = RoomConfig(
|
||||
// isPublishAudio: false,
|
||||
// isPublishVideo: false,
|
||||
// isAutoSubscribeAudio: true,
|
||||
// isAutoSubscribeVideo: true,
|
||||
// );
|
||||
|
||||
// await _rtcRoom?.joinRoom(
|
||||
// token: _token!,
|
||||
// userInfo: userInfo,
|
||||
// roomConfig: roomConfig,
|
||||
// userVisibility: true,
|
||||
// );
|
||||
|
||||
// setState(() {
|
||||
// _isJoined = true;
|
||||
// });
|
||||
|
||||
// print('Successfully joined room: $_roomId');
|
||||
// } catch (e) {
|
||||
// print('Failed to join room: $e');
|
||||
// setState(() {
|
||||
// errorMessage = '加入房间失败: $e';
|
||||
// isLoading = false;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> _leaveRoom() async {
|
||||
try {
|
||||
// if (_rtcRoom != null) {
|
||||
// await _rtcRoom!.leaveRoom();
|
||||
// _rtcRoom = null;
|
||||
// }
|
||||
// if (_rtcEngine != null) {
|
||||
// _rtcEngine!.destroy();
|
||||
// _rtcEngine = null;
|
||||
// }
|
||||
setState(() {
|
||||
_isJoined = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print('Failed to leave room: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider.value(
|
||||
value: _bloc,
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFF1D2129),
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF2A2E34),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: const Text('实时监控', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: BlocConsumer<DroneStationBloc, DroneStationState>(
|
||||
listener: (context, state) async {
|
||||
if (state is VideoStreamLoaded) {
|
||||
videoUrl = state.videoStream.url;
|
||||
_parseUrlParams(videoUrl!);
|
||||
// await _joinRoom();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
} else if (state is VideoStreamError) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
errorMessage = state.message;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (errorMessage != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error, size: 64, color: Colors.red),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
errorMessage!,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: _loadVideoStream,
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return _buildVideoView();
|
||||
},
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
color: const Color(0xFF2A2E34),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildBtn(
|
||||
Icons.home,
|
||||
'室内',
|
||||
isIndoor,
|
||||
() => _onCameraPositionChanged(true),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildBtn(
|
||||
Icons.sunny,
|
||||
'室外',
|
||||
!isIndoor,
|
||||
() => _onCameraPositionChanged(false),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVideoView() {
|
||||
// if (!_isJoined || _rtcEngine == null || _userId == null) {
|
||||
// return Center(
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// const Icon(Icons.video_library, size: 80, color: Colors.grey),
|
||||
// const SizedBox(height: 16),
|
||||
// const Text(
|
||||
// '正在连接...',
|
||||
// style: TextStyle(color: Colors.white, fontSize: 16),
|
||||
// ),
|
||||
// const SizedBox(height: 8),
|
||||
// Text(
|
||||
// '房间: $_roomId',
|
||||
// style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.videocam_off, size: 80, color: Colors.grey),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'RTC 功能已禁用',
|
||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'火山引擎 RTC 依赖已注释',
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBtn(
|
||||
IconData icon,
|
||||
String label,
|
||||
bool active,
|
||||
VoidCallback onTap,
|
||||
) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? const Color(0xFF165DFF) : const Color(0xFF3A3E44),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: Colors.white),
|
||||
const SizedBox(height: 8),
|
||||
Text(label, style: const TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user