告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
abstract class DroneStationDataSource {
|
||||
Future<List<DroneStationEntity>> getDroneStationList(int siteId);
|
||||
Future<UAVDetailEntity> getUAVDetail(String gatewaySn, String deviceSn);
|
||||
Future<VideoStreamEntity> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
String qualityType = 'adaptive',
|
||||
int videoExpire = 7200,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
class DroneStationDataSourceImpl implements DroneStationDataSource {
|
||||
final Dio dio;
|
||||
|
||||
DroneStationDataSourceImpl(this.dio);
|
||||
|
||||
@override
|
||||
Future<List<DroneStationEntity>> getDroneStationList(int siteId) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getSiteUAVList,
|
||||
queryParameters: {'siteId': siteId},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
return rows.map((item) => DroneStationEntity.fromJson(item)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UAVDetailEntity> getUAVDetail(
|
||||
String gatewaySn,
|
||||
String deviceSn,
|
||||
) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getUAVState,
|
||||
queryParameters: {'sn': gatewaySn, 'droneSn': deviceSn},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return UAVDetailEntity.fromJson(responseData['data']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<VideoStreamEntity> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
String qualityType = 'adaptive',
|
||||
int videoExpire = 7200,
|
||||
}) async {
|
||||
final response = await dio.post(
|
||||
HttpApiConsts.changeCamera,
|
||||
data: {
|
||||
'sn': sn,
|
||||
'cameraIndex': cameraIndex,
|
||||
'cameraPosition': cameraPosition,
|
||||
'qualityType': qualityType,
|
||||
'videoExpire': videoExpire,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return VideoStreamEntity.fromJson(responseData['data']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/// 机器人数据模型
|
||||
class RobotDataModel {
|
||||
final String name;
|
||||
final String id;
|
||||
final String type;
|
||||
final String status;
|
||||
final double battery;
|
||||
final String task;
|
||||
|
||||
const RobotDataModel({
|
||||
required this.name,
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.battery,
|
||||
required this.task,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建数据模型
|
||||
factory RobotDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return RobotDataModel(
|
||||
name: json['deviceName'] ?? json['name'] ?? '',
|
||||
id: json['deviceId']?.toString() ?? json['id']?.toString() ?? '',
|
||||
type: json['deviceTypeName'] ?? json['type'] ?? '未知类型',
|
||||
status: _getStatusText(json['status'] ?? 0),
|
||||
battery: (json['battery'] as num?)?.toDouble() ??
|
||||
(json['capacity_percent'] as num?)?.toDouble() ?? 0.0,
|
||||
task: json['task'] ?? json['currentTask'] ?? '待机中',
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'id': id,
|
||||
'type': type,
|
||||
'status': status,
|
||||
'battery': battery,
|
||||
'task': task,
|
||||
};
|
||||
}
|
||||
|
||||
/// 状态码转换
|
||||
static String _getStatusText(int status) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '在线';
|
||||
case 2:
|
||||
return '离线';
|
||||
case 3:
|
||||
return '异常';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../../domain/repositories/drone_station_repository.dart';
|
||||
|
||||
class DroneStationRepositoryImpl implements DroneStationRepository {
|
||||
final DroneStationDataSource dataSource;
|
||||
|
||||
DroneStationRepositoryImpl(this.dataSource);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<DroneStationEntity>>> getDroneStationList(
|
||||
int siteId,
|
||||
) async {
|
||||
try {
|
||||
final stations = await dataSource.getDroneStationList(siteId);
|
||||
return Right(stations);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, UAVDetailEntity>> getUAVDetail(
|
||||
String gatewaySn,
|
||||
String deviceSn,
|
||||
) async {
|
||||
try {
|
||||
final detail = await dataSource.getUAVDetail(gatewaySn, deviceSn);
|
||||
return Right(detail);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, VideoStreamEntity>> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
}) async {
|
||||
try {
|
||||
final videoStream = await dataSource.getVideoStream(
|
||||
sn: sn,
|
||||
cameraIndex: cameraIndex,
|
||||
cameraPosition: cameraPosition,
|
||||
);
|
||||
return Right(videoStream);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// 摄像头信息
|
||||
class CameraInfo extends Equatable {
|
||||
final String cameraIndex;
|
||||
final List<String>? availableCameraPositions;
|
||||
final String cameraPosition;
|
||||
|
||||
const CameraInfo({
|
||||
required this.cameraIndex,
|
||||
this.availableCameraPositions,
|
||||
required this.cameraPosition,
|
||||
});
|
||||
|
||||
factory CameraInfo.fromJson(Map<String, dynamic> json) {
|
||||
return CameraInfo(
|
||||
cameraIndex: json['camera_index'] ?? '',
|
||||
availableCameraPositions: json['available_camera_positions'] != null
|
||||
? List<String>.from(json['available_camera_positions'])
|
||||
: null,
|
||||
cameraPosition: json['camera_position'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'camera_index': cameraIndex,
|
||||
'available_camera_positions': availableCameraPositions,
|
||||
'camera_position': cameraPosition,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
cameraIndex,
|
||||
availableCameraPositions,
|
||||
cameraPosition,
|
||||
];
|
||||
}
|
||||
|
||||
/// 位置状态
|
||||
class PositionState extends Equatable {
|
||||
final int gpsNumber;
|
||||
final String isFixed;
|
||||
final String quality;
|
||||
final int rtkNumber;
|
||||
|
||||
const PositionState({
|
||||
required this.gpsNumber,
|
||||
required this.isFixed,
|
||||
required this.quality,
|
||||
required this.rtkNumber,
|
||||
});
|
||||
|
||||
factory PositionState.fromJson(Map<String, dynamic> json) {
|
||||
return PositionState(
|
||||
gpsNumber: json['gps_number'] ?? 0,
|
||||
isFixed: json['is_fixed'] ?? '',
|
||||
quality: json['quality'] ?? '',
|
||||
rtkNumber: json['rtk_number'] ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'gps_number': gpsNumber,
|
||||
'is_fixed': isFixed,
|
||||
'quality': quality,
|
||||
'rtk_number': rtkNumber,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [gpsNumber, isFixed, quality, rtkNumber];
|
||||
}
|
||||
|
||||
/// UAV详情实体(用于详情页面API返回的数据)
|
||||
class UAVDetailEntity extends Equatable {
|
||||
final String deviceSn;
|
||||
final String gatewaySn;
|
||||
final String callsign;
|
||||
final String droneCallsign;
|
||||
final int onlineStatus;
|
||||
final int droneOnlineStatus;
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final double? capacityPercent;
|
||||
final double? windSpeed;
|
||||
final double? height;
|
||||
final double? environmentTemperature;
|
||||
final dynamic networkState;
|
||||
final PositionState? positionState;
|
||||
final double? homeDistance;
|
||||
final double? liveCapacity;
|
||||
final String? rainfall;
|
||||
final List<CameraInfo>? gatewayCameraList;
|
||||
final List<dynamic>? droneCameraList;
|
||||
final int? orgId;
|
||||
final int? siteId;
|
||||
final int? userId;
|
||||
|
||||
const UAVDetailEntity({
|
||||
required this.deviceSn,
|
||||
required this.gatewaySn,
|
||||
required this.callsign,
|
||||
required this.droneCallsign,
|
||||
required this.onlineStatus,
|
||||
required this.droneOnlineStatus,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.capacityPercent,
|
||||
this.windSpeed,
|
||||
this.height,
|
||||
this.environmentTemperature,
|
||||
this.networkState,
|
||||
this.positionState,
|
||||
this.homeDistance,
|
||||
this.liveCapacity,
|
||||
this.rainfall,
|
||||
this.gatewayCameraList,
|
||||
this.droneCameraList,
|
||||
this.orgId,
|
||||
this.siteId,
|
||||
this.userId,
|
||||
});
|
||||
|
||||
factory UAVDetailEntity.fromJson(Map<String, dynamic> json) {
|
||||
return UAVDetailEntity(
|
||||
deviceSn: json['device_sn'] ?? '',
|
||||
gatewaySn: json['gateway_sn'] ?? '',
|
||||
callsign: json['callsign'] ?? '',
|
||||
droneCallsign: json['drone_callsign'] ?? '',
|
||||
onlineStatus: json['onlineStatus'] ?? 0,
|
||||
droneOnlineStatus: json['drone_onlineStatus'] ?? 0,
|
||||
latitude: json['latitude'] != null
|
||||
? (json['latitude'] as num).toDouble()
|
||||
: null,
|
||||
longitude: json['longitude'] != null
|
||||
? (json['longitude'] as num).toDouble()
|
||||
: null,
|
||||
capacityPercent: json['capacity_percent'] != null
|
||||
? (json['capacity_percent'] as num).toDouble()
|
||||
: null,
|
||||
windSpeed: json['wind_speed'] != null
|
||||
? (json['wind_speed'] as num).toDouble()
|
||||
: null,
|
||||
height: json['height'] != null
|
||||
? (json['height'] as num).toDouble()
|
||||
: null,
|
||||
environmentTemperature: json['environment_temperature'] != null
|
||||
? (json['environment_temperature'] as num).toDouble()
|
||||
: null,
|
||||
networkState: json['network_state'],
|
||||
positionState: json['position_state'] != null
|
||||
? PositionState.fromJson(json['position_state'])
|
||||
: null,
|
||||
homeDistance: json['home_distance'] != null
|
||||
? (json['home_distance'] as num).toDouble()
|
||||
: null,
|
||||
liveCapacity: json['live_capacity'] != null
|
||||
? (json['live_capacity'] as num).toDouble()
|
||||
: null,
|
||||
rainfall: json['rainfall']?.toString(),
|
||||
gatewayCameraList: json['gateway_camera_list'] != null
|
||||
? (json['gateway_camera_list'] as List)
|
||||
.map((item) => CameraInfo.fromJson(item))
|
||||
.toList()
|
||||
: null,
|
||||
droneCameraList: json['drone_camera_list'],
|
||||
orgId: json['orgId'],
|
||||
siteId: json['siteId'],
|
||||
userId: json['userId'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'device_sn': deviceSn,
|
||||
'gateway_sn': gatewaySn,
|
||||
'callsign': callsign,
|
||||
'drone_callsign': droneCallsign,
|
||||
'onlineStatus': onlineStatus,
|
||||
'drone_onlineStatus': droneOnlineStatus,
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'capacity_percent': capacityPercent,
|
||||
'wind_speed': windSpeed,
|
||||
'height': height,
|
||||
'environment_temperature': environmentTemperature,
|
||||
'network_state': networkState,
|
||||
'position_state': positionState?.toJson(),
|
||||
'home_distance': homeDistance,
|
||||
'live_capacity': liveCapacity,
|
||||
'rainfall': rainfall,
|
||||
'gateway_camera_list': gatewayCameraList?.map((c) => c.toJson()).toList(),
|
||||
'drone_camera_list': droneCameraList,
|
||||
'orgId': orgId,
|
||||
'siteId': siteId,
|
||||
'userId': userId,
|
||||
};
|
||||
}
|
||||
|
||||
bool get isOnline => onlineStatus == 1;
|
||||
bool get isDroneOnline => droneOnlineStatus == 1;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
deviceSn,
|
||||
gatewaySn,
|
||||
callsign,
|
||||
droneCallsign,
|
||||
onlineStatus,
|
||||
droneOnlineStatus,
|
||||
latitude,
|
||||
longitude,
|
||||
capacityPercent,
|
||||
windSpeed,
|
||||
height,
|
||||
environmentTemperature,
|
||||
networkState,
|
||||
positionState,
|
||||
homeDistance,
|
||||
liveCapacity,
|
||||
rainfall,
|
||||
gatewayCameraList,
|
||||
droneCameraList,
|
||||
orgId,
|
||||
siteId,
|
||||
userId,
|
||||
];
|
||||
}
|
||||
|
||||
/// 无人机机场实体
|
||||
class DroneStationEntity extends Equatable {
|
||||
final String deviceSn; // 机场设备序列号
|
||||
final String gatewaySn; // 网关序列号
|
||||
final String callsign; // 机场呼号/名称
|
||||
final String droneCallsign; // 无人机呼号
|
||||
final int onlineStatus; // 机场在线状态 (1:在线, 0:离线)
|
||||
final int droneOnlineStatus; // 无人机在线状态
|
||||
final double? latitude; // 纬度
|
||||
final double? longitude; // 经度
|
||||
final double? capacityPercent; // 电量百分比
|
||||
final double? windSpeed; // 风速
|
||||
final double? height; // 高度
|
||||
final double? environmentTemperature; // 环境温度
|
||||
final int? networkState; // 网络状态
|
||||
final int? positionState; // 位置状态
|
||||
final double? homeDistance; // 距离home点距离
|
||||
final double? liveCapacity; // 实时容量
|
||||
final double? rainfall; // 降雨量
|
||||
final List<CameraInfo>? gatewayCameraList; // 网关摄像头列表
|
||||
final List<dynamic>? droneCameraList; // 无人机摄像头列表
|
||||
final int orgId; // 组织ID
|
||||
final int siteId; // 场站ID
|
||||
final int? userId; // 用户ID
|
||||
|
||||
const DroneStationEntity({
|
||||
required this.deviceSn,
|
||||
required this.gatewaySn,
|
||||
required this.callsign,
|
||||
required this.droneCallsign,
|
||||
required this.onlineStatus,
|
||||
required this.droneOnlineStatus,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.capacityPercent,
|
||||
this.windSpeed,
|
||||
this.height,
|
||||
this.environmentTemperature,
|
||||
this.networkState,
|
||||
this.positionState,
|
||||
this.homeDistance,
|
||||
this.liveCapacity,
|
||||
this.rainfall,
|
||||
this.gatewayCameraList,
|
||||
this.droneCameraList,
|
||||
required this.orgId,
|
||||
required this.siteId,
|
||||
this.userId,
|
||||
});
|
||||
|
||||
factory DroneStationEntity.fromJson(Map<String, dynamic> json) {
|
||||
return DroneStationEntity(
|
||||
deviceSn: json['device_sn'] ?? '',
|
||||
gatewaySn: json['gateway_sn'] ?? '',
|
||||
callsign: json['callsign'] ?? '',
|
||||
droneCallsign: json['drone_callsign'] ?? '',
|
||||
onlineStatus: json['onlineStatus'] ?? 0,
|
||||
droneOnlineStatus: json['drone_onlineStatus'] ?? 0,
|
||||
latitude: json['latitude'] != null
|
||||
? (json['latitude'] as num).toDouble()
|
||||
: null,
|
||||
longitude: json['longitude'] != null
|
||||
? (json['longitude'] as num).toDouble()
|
||||
: null,
|
||||
capacityPercent: json['capacity_percent'] != null
|
||||
? (json['capacity_percent'] as num).toDouble()
|
||||
: null,
|
||||
windSpeed: json['wind_speed'] != null
|
||||
? (json['wind_speed'] as num).toDouble()
|
||||
: null,
|
||||
height: json['height'] != null
|
||||
? (json['height'] as num).toDouble()
|
||||
: null,
|
||||
environmentTemperature: json['environment_temperature'] != null
|
||||
? (json['environment_temperature'] as num).toDouble()
|
||||
: null,
|
||||
networkState: json['network_state'],
|
||||
positionState: json['position_state'],
|
||||
homeDistance: json['home_distance'] != null
|
||||
? (json['home_distance'] as num).toDouble()
|
||||
: null,
|
||||
liveCapacity: json['live_capacity'] != null
|
||||
? (json['live_capacity'] as num).toDouble()
|
||||
: null,
|
||||
rainfall: json['rainfall'] != null
|
||||
? (json['rainfall'] as num).toDouble()
|
||||
: null,
|
||||
gatewayCameraList: json['gateway_camera_list'] != null
|
||||
? (json['gateway_camera_list'] as List)
|
||||
.map((item) => CameraInfo.fromJson(item))
|
||||
.toList()
|
||||
: null,
|
||||
droneCameraList: json['drone_camera_list'],
|
||||
orgId: json['orgId'] ?? 0,
|
||||
siteId: json['siteId'] ?? 0,
|
||||
userId: json['userId'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'device_sn': deviceSn,
|
||||
'gateway_sn': gatewaySn,
|
||||
'callsign': callsign,
|
||||
'drone_callsign': droneCallsign,
|
||||
'onlineStatus': onlineStatus,
|
||||
'drone_onlineStatus': droneOnlineStatus,
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'capacity_percent': capacityPercent,
|
||||
'wind_speed': windSpeed,
|
||||
'height': height,
|
||||
'environment_temperature': environmentTemperature,
|
||||
'network_state': networkState,
|
||||
'position_state': positionState,
|
||||
'home_distance': homeDistance,
|
||||
'live_capacity': liveCapacity,
|
||||
'rainfall': rainfall,
|
||||
'gateway_camera_list': gatewayCameraList?.map((c) => c.toJson()).toList(),
|
||||
'drone_camera_list': droneCameraList,
|
||||
'orgId': orgId,
|
||||
'siteId': siteId,
|
||||
'userId': userId,
|
||||
};
|
||||
}
|
||||
|
||||
/// 是否在线
|
||||
bool get isOnline => onlineStatus == 1;
|
||||
|
||||
/// 无人机是否在线
|
||||
bool get isDroneOnline => droneOnlineStatus == 1;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
deviceSn,
|
||||
gatewaySn,
|
||||
callsign,
|
||||
droneCallsign,
|
||||
onlineStatus,
|
||||
droneOnlineStatus,
|
||||
latitude,
|
||||
longitude,
|
||||
capacityPercent,
|
||||
windSpeed,
|
||||
height,
|
||||
environmentTemperature,
|
||||
networkState,
|
||||
positionState,
|
||||
homeDistance,
|
||||
liveCapacity,
|
||||
rainfall,
|
||||
gatewayCameraList,
|
||||
droneCameraList,
|
||||
orgId,
|
||||
siteId,
|
||||
userId,
|
||||
];
|
||||
}
|
||||
|
||||
/// 视频流实体
|
||||
class VideoStreamEntity extends Equatable {
|
||||
final String sn;
|
||||
final String cameraIndex;
|
||||
final String url;
|
||||
final int expireTs;
|
||||
final String urlType;
|
||||
|
||||
const VideoStreamEntity({
|
||||
required this.sn,
|
||||
required this.cameraIndex,
|
||||
required this.url,
|
||||
required this.expireTs,
|
||||
required this.urlType,
|
||||
});
|
||||
|
||||
factory VideoStreamEntity.fromJson(Map<String, dynamic> json) {
|
||||
return VideoStreamEntity(
|
||||
sn: json['sn'] ?? '',
|
||||
cameraIndex: json['camera_index'] ?? '',
|
||||
url: json['url'] ?? '',
|
||||
expireTs: json['expire_ts'] ?? 0,
|
||||
urlType: json['url_type'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [sn, cameraIndex, url, expireTs, urlType];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// 视频流实体
|
||||
class VideoStreamEntity extends Equatable {
|
||||
final String sn;
|
||||
final String cameraIndex;
|
||||
final String
|
||||
url; // 火山引擎 RTC 鉴权参数(包含 app_id、room_id、token、user_id、expire_time)
|
||||
final int expireTs;
|
||||
final String urlType; // 标识是 "rtc" 还是其他类型
|
||||
|
||||
const VideoStreamEntity({
|
||||
required this.sn,
|
||||
required this.cameraIndex,
|
||||
required this.url,
|
||||
required this.expireTs,
|
||||
required this.urlType,
|
||||
});
|
||||
|
||||
factory VideoStreamEntity.fromJson(Map<String, dynamic> json) {
|
||||
return VideoStreamEntity(
|
||||
sn: json['sn'] ?? '',
|
||||
cameraIndex: json['camera_index'] ?? '',
|
||||
url: json['url'] ?? '', // 火山引擎 RTC 鉴权参数
|
||||
expireTs: json['expire_ts'] ?? 0,
|
||||
urlType: json['url_type'] ?? 'rtc', // 默认为 rtc 类型
|
||||
);
|
||||
}
|
||||
|
||||
/// 解析火山引擎 RTC 参数
|
||||
/// url 格式示例: "app_id=xxx&room_id=xxx&token=xxx&user_id=xxx&expire_time=xxx"
|
||||
Map<String, String> parseRtcParams() {
|
||||
final params = <String, String>{};
|
||||
final pairs = url.split('&');
|
||||
for (final pair in pairs) {
|
||||
final kv = pair.split('=');
|
||||
if (kv.length == 2) {
|
||||
// 对 URL 编码的字符进行解码(如 %2F -> /, %2B -> +)
|
||||
params[kv[0]] = Uri.decodeComponent(kv[1]);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/// 获取火山引擎 App ID(从 URL 中解析)
|
||||
String get appId => parseRtcParams()['app_id'] ?? '';
|
||||
|
||||
/// 获取房间 ID(从 URL 中解析)
|
||||
String get roomId => parseRtcParams()['room_id'] ?? '';
|
||||
|
||||
/// 获取 Token(从 URL 中解析)
|
||||
String get token => parseRtcParams()['token'] ?? '';
|
||||
|
||||
/// 获取用户 ID(从 URL 中解析)
|
||||
String get userId => parseRtcParams()['user_id'] ?? '';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [sn, cameraIndex, url, expireTs, urlType];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../entities/drone_station_entity.dart';
|
||||
|
||||
abstract class DroneStationRepository {
|
||||
Future<Either<Failure, List<DroneStationEntity>>> getDroneStationList(
|
||||
int siteId,
|
||||
);
|
||||
Future<Either<Failure, UAVDetailEntity>> getUAVDetail(
|
||||
String gatewaySn,
|
||||
String deviceSn,
|
||||
);
|
||||
Future<Either<Failure, VideoStreamEntity>> getVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../entities/drone_station_entity.dart';
|
||||
import '../repositories/drone_station_repository.dart';
|
||||
|
||||
class GetDroneStationListUseCase {
|
||||
final DroneStationRepository repository;
|
||||
|
||||
GetDroneStationListUseCase(this.repository);
|
||||
|
||||
Future<Either<Failure, List<DroneStationEntity>>> call(int siteId) async {
|
||||
return await repository.getDroneStationList(siteId);
|
||||
}
|
||||
}
|
||||
|
||||
class GetUAVDetailUseCase {
|
||||
final DroneStationRepository repository;
|
||||
|
||||
GetUAVDetailUseCase(this.repository);
|
||||
|
||||
Future<Either<Failure, UAVDetailEntity>> call(String gatewaySn, String deviceSn) async {
|
||||
return await repository.getUAVDetail(gatewaySn, deviceSn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../entities/drone_station_entity.dart';
|
||||
import '../repositories/drone_station_repository.dart';
|
||||
|
||||
class GetVideoStreamUseCase {
|
||||
final DroneStationRepository repository;
|
||||
|
||||
GetVideoStreamUseCase(this.repository);
|
||||
|
||||
Future<Either<Failure, VideoStreamEntity>> call({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
required String cameraPosition,
|
||||
}) async {
|
||||
return await repository.getVideoStream(
|
||||
sn: sn,
|
||||
cameraIndex: cameraIndex,
|
||||
cameraPosition: cameraPosition,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/usecases/get_drone_station_list_usecase.dart';
|
||||
import '../../domain/usecases/get_video_stream_usecase.dart';
|
||||
import 'drone_station_event.dart';
|
||||
import 'drone_station_state.dart';
|
||||
|
||||
class DroneStationBloc extends Bloc<DroneStationEvent, DroneStationState> {
|
||||
final GetDroneStationListUseCase getDroneStationListUseCase;
|
||||
final GetUAVDetailUseCase getUAVDetailUseCase;
|
||||
final GetVideoStreamUseCase getVideoStreamUseCase;
|
||||
|
||||
DroneStationBloc(
|
||||
this.getDroneStationListUseCase,
|
||||
this.getUAVDetailUseCase,
|
||||
this.getVideoStreamUseCase,
|
||||
) : super(const DroneStationInitial()) {
|
||||
on<DroneStationLoadData>(_onLoadData);
|
||||
on<DroneStationRefresh>(_onRefresh);
|
||||
on<UAVDetailLoad>(_onUAVDetailLoad);
|
||||
on<VideoStreamLoad>(_onVideoStreamLoad);
|
||||
}
|
||||
|
||||
Future<void> _onLoadData(
|
||||
DroneStationLoadData event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const DroneStationLoading());
|
||||
|
||||
final result = await getDroneStationListUseCase(event.siteId);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(DroneStationError(failure.message)),
|
||||
(stations) => emit(DroneStationLoaded(stations)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(
|
||||
DroneStationRefresh event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
if (state is DroneStationLoaded) {
|
||||
final result = await getDroneStationListUseCase(event.siteId);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(DroneStationError(failure.message)),
|
||||
(stations) => emit(DroneStationLoaded(stations)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onUAVDetailLoad(
|
||||
UAVDetailLoad event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const UAVDetailLoading());
|
||||
|
||||
final result = await getUAVDetailUseCase(event.gatewaySn, event.deviceSn);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(UAVDetailError(failure.message)),
|
||||
(detail) => emit(UAVDetailLoaded(detail)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onVideoStreamLoad(
|
||||
VideoStreamLoad event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const VideoStreamLoading());
|
||||
|
||||
final result = await getVideoStreamUseCase(
|
||||
sn: event.sn,
|
||||
cameraIndex: event.cameraIndex,
|
||||
cameraPosition: event.cameraPosition,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(VideoStreamError(failure.message)),
|
||||
(videoStream) => emit(VideoStreamLoaded(videoStream)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class DroneStationEvent extends Equatable {
|
||||
const DroneStationEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class DroneStationLoadData extends DroneStationEvent {
|
||||
final int siteId;
|
||||
|
||||
const DroneStationLoadData(this.siteId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class DroneStationRefresh extends DroneStationEvent {
|
||||
final int siteId;
|
||||
|
||||
const DroneStationRefresh(this.siteId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class UAVDetailLoad extends DroneStationEvent {
|
||||
final String gatewaySn;
|
||||
final String deviceSn;
|
||||
|
||||
const UAVDetailLoad({required this.gatewaySn, required this.deviceSn});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [gatewaySn, deviceSn];
|
||||
}
|
||||
|
||||
class VideoStreamLoad extends DroneStationEvent {
|
||||
final String sn;
|
||||
final String cameraIndex;
|
||||
final String cameraPosition;
|
||||
|
||||
const VideoStreamLoad({
|
||||
required this.sn,
|
||||
required this.cameraIndex,
|
||||
required this.cameraPosition,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [sn, cameraIndex, cameraPosition];
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
abstract class DroneStationState extends Equatable {
|
||||
const DroneStationState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class DroneStationInitial extends DroneStationState {
|
||||
const DroneStationInitial();
|
||||
}
|
||||
|
||||
class DroneStationLoading extends DroneStationState {
|
||||
const DroneStationLoading();
|
||||
}
|
||||
|
||||
class DroneStationLoaded extends DroneStationState {
|
||||
final List<DroneStationEntity> stations;
|
||||
|
||||
const DroneStationLoaded(this.stations);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [stations];
|
||||
}
|
||||
|
||||
class DroneStationError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const DroneStationError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class UAVDetailLoading extends DroneStationState {
|
||||
const UAVDetailLoading();
|
||||
}
|
||||
|
||||
class UAVDetailLoaded extends DroneStationState {
|
||||
final UAVDetailEntity detail;
|
||||
|
||||
const UAVDetailLoaded(this.detail);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [detail];
|
||||
}
|
||||
|
||||
class UAVDetailError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const UAVDetailError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class VideoStreamLoading extends DroneStationState {
|
||||
const VideoStreamLoading();
|
||||
}
|
||||
|
||||
class VideoStreamLoaded extends DroneStationState {
|
||||
final VideoStreamEntity videoStream;
|
||||
|
||||
const VideoStreamLoaded(this.videoStream);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [videoStream];
|
||||
}
|
||||
|
||||
class VideoStreamError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const VideoStreamError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import 'robot_list_event.dart';
|
||||
import 'robot_list_state.dart';
|
||||
|
||||
class RobotListBloc extends Bloc<RobotListEvent, RobotListState> {
|
||||
final Dio dio;
|
||||
|
||||
RobotListBloc(this.dio) : super(const RobotListInitial()) {
|
||||
on<RobotListLoadData>(_onLoadData);
|
||||
on<RobotListRefresh>(_onRefresh);
|
||||
on<RobotListChangeType>(_onChangeType);
|
||||
}
|
||||
|
||||
Future<void> _onLoadData(
|
||||
RobotListLoadData event,
|
||||
Emitter<RobotListState> emit,
|
||||
) async {
|
||||
if (event.siteId == null) {
|
||||
emit(const RobotListError('请先选择场站'));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(const RobotListLoading());
|
||||
|
||||
try {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getRobotList,
|
||||
queryParameters: {
|
||||
'siteId': event.siteId,
|
||||
'pageSize': 9999,
|
||||
'pageNum': 1,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(RobotListLoaded(
|
||||
robots: robots,
|
||||
siteId: event.siteId,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(RobotListError(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(
|
||||
RobotListRefresh event,
|
||||
Emitter<RobotListState> emit,
|
||||
) async {
|
||||
if (state is RobotListLoaded) {
|
||||
final currentState = state as RobotListLoaded;
|
||||
|
||||
if (currentState.siteId == null) {
|
||||
emit(const RobotListError('请先选择场站'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getRobotList,
|
||||
queryParameters: {
|
||||
'siteId': currentState.siteId,
|
||||
'pageSize': 9999,
|
||||
'pageNum': 1,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(currentState.copyWith(robots: robots));
|
||||
} catch (e) {
|
||||
emit(RobotListError(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onChangeType(
|
||||
RobotListChangeType event,
|
||||
Emitter<RobotListState> emit,
|
||||
) {
|
||||
if (state is RobotListLoaded) {
|
||||
final currentState = state as RobotListLoaded;
|
||||
emit(currentState.copyWith(selectedType: event.type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class RobotListEvent extends Equatable {
|
||||
const RobotListEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class RobotListLoadData extends RobotListEvent {
|
||||
final int? siteId;
|
||||
|
||||
const RobotListLoadData({this.siteId});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class RobotListRefresh extends RobotListEvent {
|
||||
const RobotListRefresh();
|
||||
}
|
||||
|
||||
class RobotListChangeType extends RobotListEvent {
|
||||
final String? type;
|
||||
|
||||
const RobotListChangeType(this.type);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [type];
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
|
||||
abstract class RobotListState extends Equatable {
|
||||
const RobotListState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class RobotListInitial extends RobotListState {
|
||||
const RobotListInitial();
|
||||
}
|
||||
|
||||
class RobotListLoading extends RobotListState {
|
||||
const RobotListLoading();
|
||||
}
|
||||
|
||||
class RobotListLoaded extends RobotListState {
|
||||
final List<RobotDataModel> robots;
|
||||
final String? selectedType;
|
||||
final int? siteId;
|
||||
|
||||
const RobotListLoaded({
|
||||
required this.robots,
|
||||
this.selectedType,
|
||||
this.siteId,
|
||||
});
|
||||
|
||||
RobotListLoaded copyWith({
|
||||
List<RobotDataModel>? robots,
|
||||
String? selectedType,
|
||||
int? siteId,
|
||||
}) {
|
||||
return RobotListLoaded(
|
||||
robots: robots ?? this.robots,
|
||||
selectedType: selectedType ?? this.selectedType,
|
||||
siteId: siteId ?? this.siteId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [robots, selectedType, siteId];
|
||||
}
|
||||
|
||||
class RobotListError extends RobotListState {
|
||||
final String message;
|
||||
|
||||
const RobotListError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
@@ -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