支持现场服务器地址配置
This commit is contained in:
@@ -3,6 +3,8 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/server_configuration.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
|
||||
@@ -20,13 +22,13 @@ class AiCubit extends Cubit<AiState> {
|
||||
|
||||
final Dio _dio = Dio();
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
static const String BASE_URL = 'http://1.95.137.212:30009';
|
||||
static String get _baseUrl => EnvConfig.baseAddress(ServerService.ai);
|
||||
String get _userId => appUserCubit.state.user?.userId ?? '1';
|
||||
//final String _userId = '1';
|
||||
|
||||
Future<void> fetchSessions() async {
|
||||
try {
|
||||
final response = await _dio.get('$BASE_URL/sessions', queryParameters: {'userId': _userId});
|
||||
final response = await _dio.get('$_baseUrl/sessions', queryParameters: {'userId': _userId});
|
||||
if (response.statusCode == 200 && response.data['code'] == 0) {
|
||||
final sessionsData = response.data['sessions'] as List;
|
||||
emit(state.copyWith(sessions: sessionsData.map((data) => Session.fromJson(data)).toList()));
|
||||
@@ -52,7 +54,7 @@ class AiCubit extends Cubit<AiState> {
|
||||
emit(state.copyWith(status: AiStatus.loading, messages: [], sessionId: sessionId));
|
||||
|
||||
try {
|
||||
final response = await _dio.get('$BASE_URL/history', queryParameters: {'sessionId': sessionId});
|
||||
final response = await _dio.get('$_baseUrl/history', queryParameters: {'sessionId': sessionId});
|
||||
if (response.statusCode == 200 && response.data['code'] == 0) {
|
||||
final messagesData = response.data['messages'] as List;
|
||||
final historyMessages = messagesData.map((data) {
|
||||
@@ -95,7 +97,7 @@ class AiCubit extends Cubit<AiState> {
|
||||
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'$BASE_URL/analyze',
|
||||
'$_baseUrl/analyze',
|
||||
data: {'userId': _userId, 'sessionId': state.sessionId, 'userPrompt': prompt, 'imageBase64': imageBase64},
|
||||
options: Options(responseType: ResponseType.stream),
|
||||
);
|
||||
|
||||
@@ -237,7 +237,12 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
}
|
||||
|
||||
/// 退出登录 (主动或被动)
|
||||
Future<void> logout() async {
|
||||
Future<void> logout() => _logout();
|
||||
|
||||
/// 先清除旧会话,再应用新地址,最后返回登录页。
|
||||
Future<void> logoutForServerChange(Future<void> Function() apply) => _logout(apply);
|
||||
|
||||
Future<void> _logout([Future<void> Function()? beforeSignedOut]) async {
|
||||
print('>>> [AUTH] 🚨🚨🚨 logout() 被调用!时间: ${DateTime.now()}');
|
||||
print('>>> [AUTH] 调用栈:\n${StackTrace.current}');
|
||||
|
||||
@@ -247,7 +252,11 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
await storage.deleteUser();
|
||||
tcp.forceDisconnect(); // 🔥 修复:彻底断开连接,禁止自动重连
|
||||
appCubit.clearAuth();
|
||||
emit(AuthUnauthenticated());
|
||||
try {
|
||||
if (beforeSignedOut != null) await beforeSignedOut();
|
||||
} finally {
|
||||
emit(AuthUnauthenticated());
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔥 Token 过期处理:弹出提示后退出登录
|
||||
|
||||
@@ -209,6 +209,17 @@ class _LoginPageV2State extends State<LoginPageV2>
|
||||
animation: _interval(0.26, 0.63),
|
||||
child: _buildFormCard(),
|
||||
),
|
||||
Center(
|
||||
child: BlocBuilder<LoginCubit, LoginState>(
|
||||
builder: (context, state) => TextButton.icon(
|
||||
onPressed: state is LoginLoading
|
||||
? null
|
||||
: () => context.push(RoutePaths.serverConfiguration),
|
||||
icon: const Icon(Icons.settings_ethernet),
|
||||
label: Text(l10n.translate('servers.title')),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 暂时隐藏登录页的帮助与客服入口。
|
||||
// const SizedBox(height: 12),
|
||||
// _Entrance(
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/common.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/server_configuration.dart';
|
||||
|
||||
import '../../../../../core/logging/i_logger_service.dart';
|
||||
import '../../../../../core/storage/user_storage.dart';
|
||||
@@ -57,7 +59,7 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
// print(requestBody);
|
||||
//print('🔍 [路径规划请求] ====== 请求体结束 ======');
|
||||
final response = await http.post(
|
||||
Uri.parse('https://servicepathplan.satabot.com/api/path'),
|
||||
EnvConfig.address(ServerService.pathPlanning),
|
||||
headers: {'Content'
|
||||
'-Type': 'application/json', 'Authorization': token},
|
||||
body: requestBody,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/server_configuration.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
@@ -25,7 +27,12 @@ class _DjPageState extends State<DjPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final url = "https://pvs.satabot.com/?platform=flutter&t=${DateTime.now().millisecondsSinceEpoch}";
|
||||
final url = EnvConfig.address(ServerService.stationWeb).replace(
|
||||
queryParameters: {
|
||||
'platform': 'flutter',
|
||||
't': DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
controller = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
@@ -35,7 +42,7 @@ class _DjPageState extends State<DjPage> {
|
||||
_handleJsMessage(message.message);
|
||||
},
|
||||
)
|
||||
..loadRequest(Uri.parse(url));
|
||||
..loadRequest(url);
|
||||
}
|
||||
|
||||
/// 处理 H5 返回的数据
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/server_configuration.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -12,7 +14,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
|
||||
/// GeoServer 基地址(公司端)
|
||||
const String kGeoserverBase = 'http://1.95.137.212:7900/geoserver';
|
||||
String get kGeoserverBase => EnvConfig.baseAddress(ServerService.geoServer);
|
||||
|
||||
/// GeoServer 工作区名(后端 siteMapName 形如 workSpace:suzhou)
|
||||
const String kGeoWorkspace = 'workSpace';
|
||||
@@ -22,6 +24,9 @@ const String kGeoWorkspace = 'workSpace';
|
||||
/// 返回透明图导致“一直出不来”。故放宽到 90s,并配合下方并发闸门分批取图。
|
||||
const Duration kWmsTileTimeout = Duration(seconds: 90);
|
||||
|
||||
/// 保持地图瓦片覆盖范围和逻辑尺寸不变,以双倍像素取图供高密度屏显示。
|
||||
const int kWmsTilePixelSize = 512;
|
||||
|
||||
/// 各场站高清图层的真实范围(取自 GeoServer GetCapabilities,原生 EPSG:4326)
|
||||
/// key = 后端下发的 siteMapName(形如 workSpace:suzhou)
|
||||
final Map<String, LatLngBounds> kStationLayerBounds = {
|
||||
@@ -77,7 +82,7 @@ class GeoWmsProvider extends TileProvider {
|
||||
GeoWmsProvider({
|
||||
required this.layerName,
|
||||
required this.bounds,
|
||||
this.maxLevel = 21,
|
||||
this.maxLevel = 22,
|
||||
});
|
||||
|
||||
final String layerName;
|
||||
@@ -129,10 +134,10 @@ class GeoWmsProvider extends TileProvider {
|
||||
'REQUEST': 'GetMap',
|
||||
'VERSION': '1.1.1',
|
||||
'LAYERS': layerName,
|
||||
'BBOX': '${westLng.toStringAsFixed(6)},${southLat.toStringAsFixed(6)},'
|
||||
'${eastLng.toStringAsFixed(6)},${northLat.toStringAsFixed(6)}',
|
||||
'WIDTH': '256',
|
||||
'HEIGHT': '256',
|
||||
'BBOX': '${westLng.toStringAsFixed(9)},${southLat.toStringAsFixed(9)},'
|
||||
'${eastLng.toStringAsFixed(9)},${northLat.toStringAsFixed(9)}',
|
||||
'WIDTH': '$kWmsTilePixelSize',
|
||||
'HEIGHT': '$kWmsTilePixelSize',
|
||||
'FORMAT': 'image/png',
|
||||
'TRANSPARENT': 'true',
|
||||
'SRS': 'EPSG:4326',
|
||||
@@ -150,7 +155,7 @@ class GeoSuzhouOverlay extends StatelessWidget {
|
||||
super.key,
|
||||
this.siteMapName,
|
||||
this.minZoom = 16,
|
||||
this.maxZoom = 21,
|
||||
this.maxZoom = 22,
|
||||
});
|
||||
|
||||
/// 当前选中场站对应的 GeoServer 图层名(形如 workSpace:suzhou)
|
||||
@@ -210,12 +215,12 @@ final List<TileLayer> kAllStationTileLayers = kStationLayerBounds.entries
|
||||
tileProvider: GeoWmsProvider(
|
||||
layerName: entry.key,
|
||||
bounds: entry.value,
|
||||
maxLevel: 21,
|
||||
maxLevel: 22,
|
||||
),
|
||||
userAgentPackageName: 'com.example.app',
|
||||
minZoom: 16,
|
||||
maxZoom: 21,
|
||||
maxNativeZoom: 21,
|
||||
maxZoom: 22,
|
||||
maxNativeZoom: 22,
|
||||
tileBounds: entry.value,
|
||||
),
|
||||
)
|
||||
@@ -395,15 +400,31 @@ class StationLayerRepo {
|
||||
|
||||
Map<String, LatLngBounds> _bounds =
|
||||
Map<String, LatLngBounds>.of(kStationLayerBounds);
|
||||
String _baseAddress = kGeoserverBase;
|
||||
bool _dynamicLoaded = false;
|
||||
Future<void>? _inflight;
|
||||
final List<void Function()> _listeners = [];
|
||||
|
||||
/// 当前生效的范围表(动态成功后为最新;否则为内置兜底)
|
||||
Map<String, LatLngBounds> get bounds => _bounds;
|
||||
Map<String, LatLngBounds> get bounds {
|
||||
_syncBaseAddress();
|
||||
return _bounds;
|
||||
}
|
||||
|
||||
/// 范围表是否来自动态拉取
|
||||
bool get isDynamic => _dynamicLoaded;
|
||||
bool get isDynamic {
|
||||
_syncBaseAddress();
|
||||
return _dynamicLoaded;
|
||||
}
|
||||
|
||||
void _syncBaseAddress() {
|
||||
final current = kGeoserverBase;
|
||||
if (_baseAddress == current) return;
|
||||
_baseAddress = current;
|
||||
_bounds = Map.of(kStationLayerBounds);
|
||||
_dynamicLoaded = false;
|
||||
_inflight = null;
|
||||
}
|
||||
|
||||
void addListener(void Function() cb) {
|
||||
if (!_listeners.contains(cb)) _listeners.add(cb);
|
||||
@@ -419,14 +440,22 @@ class StationLayerRepo {
|
||||
|
||||
/// 拉取 GetCapabilities 刷新范围表;并发调用自动合并;失败保持兜底不变
|
||||
Future<void> refresh() {
|
||||
return _inflight ??= _doRefresh().whenComplete(() => _inflight = null);
|
||||
_syncBaseAddress();
|
||||
final inflight = _inflight;
|
||||
if (inflight != null) return inflight;
|
||||
|
||||
late final Future<void> request;
|
||||
request = _doRefresh(_baseAddress).whenComplete(() {
|
||||
if (identical(_inflight, request)) _inflight = null;
|
||||
});
|
||||
return _inflight = request;
|
||||
}
|
||||
|
||||
Future<void> _doRefresh() async {
|
||||
Future<void> _doRefresh(String baseAddress) async {
|
||||
final sw = Stopwatch()..start();
|
||||
try {
|
||||
// 用工作区专用端点:只返回 workSpace 下图层,XML 小、快、稳(全局端点图层多易超时)
|
||||
final url = Uri.parse('$kGeoserverBase/$kGeoWorkspace/wms').replace(
|
||||
final url = Uri.parse('$baseAddress/$kGeoWorkspace/wms').replace(
|
||||
queryParameters: {
|
||||
'SERVICE': 'WMS',
|
||||
'VERSION': '1.1.1',
|
||||
@@ -435,6 +464,7 @@ class StationLayerRepo {
|
||||
);
|
||||
debugPrint('🌐 [StationLayerRepo] 拉取 GetCapabilities...');
|
||||
final resp = await http.get(url).timeout(const Duration(seconds: 20));
|
||||
if (baseAddress != kGeoserverBase) return;
|
||||
if (resp.statusCode != 200) {
|
||||
debugPrint(
|
||||
'⚠️ [StationLayerRepo] status=${resp.statusCode},保持兜底',
|
||||
@@ -472,8 +502,8 @@ class StationLayerRepo {
|
||||
}
|
||||
|
||||
/// 基于当前范围表构建全部场站叠加图层(滑到哪个场站区域就叠加哪个)
|
||||
List<TileLayer> buildLayers({double minZoom = 16, double maxZoom = 21}) {
|
||||
return _bounds.entries.map((entry) {
|
||||
List<TileLayer> buildLayers({double minZoom = 16, double maxZoom = 22}) {
|
||||
return bounds.entries.map((entry) {
|
||||
// 自愈兜底:万一范围表里仍残留非法 bounds(历史污染等),回退到内置兜底的同名范围,
|
||||
// 避免生成“框不住任何瓦片”的坏图层导致该场站整体不显示
|
||||
final b = _isValidLayerBounds(entry.value)
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'package:maibu_satabot_v2/components/confrim_dialog.dart';
|
||||
import 'package:maibu_satabot_v2/components/toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.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/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
@@ -4483,7 +4483,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
userState.user != null &&
|
||||
userState.user!.token != null) {
|
||||
_videoStreamUrl =
|
||||
"webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=${userState.user!.token}";
|
||||
"webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/$deviceId?token=${userState.user!.token}";
|
||||
} else {
|
||||
_videoStreamUrl = '';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
@@ -89,11 +90,11 @@ class _WebRTCMapPlayerState extends State<WebRTCMapPlayer> {
|
||||
await _peerConnection!.setLocalDescription(offer);
|
||||
|
||||
final uri = Uri.parse(widget.streamUrl.replaceFirst('webrtc://', 'http://'));
|
||||
final apiUrl = "http://${uri.host}:1985/rtc/v1/play/";
|
||||
final apiUrl = EnvConfig.webRtcPlayAddress(uri);
|
||||
final response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
apiUrl,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({"api": apiUrl, "streamurl": widget.streamUrl, "clientip": null, "sdp": offer.sdp}),
|
||||
body: jsonEncode({"api": apiUrl.toString(), "streamurl": widget.streamUrl, "clientip": null, "sdp": offer.sdp}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/components/control_mode_text.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/router/route_paths.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||
@@ -78,7 +78,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
|
||||
if (_deviceId.isNotEmpty && userState.user != null && userState.user!.token != null) {
|
||||
setState(() {
|
||||
_videoStreamUrl = "webrtc://${TCPConsts.TCP_IP}/live/livestream/$_deviceId?token=${userState.user!.token}";
|
||||
_videoStreamUrl = "webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/$_deviceId?token=${userState.user!.token}";
|
||||
});
|
||||
debugPrint('✅ [MachineDetails] 视频URL初始化成功: $_videoStreamUrl');
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
@@ -268,13 +269,13 @@ class _WebRTCLocalPlayerState extends State<WebRTCLocalPlayer> {
|
||||
Uri uri = Uri.parse(
|
||||
widget.streamUrl.replaceFirst('webrtc://', 'http://'),
|
||||
);
|
||||
String apiUrl = "http://${uri.host}:1985/rtc/v1/play/";
|
||||
final apiUrl = EnvConfig.webRtcPlayAddress(uri);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
apiUrl,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
"api": apiUrl,
|
||||
"api": apiUrl.toString(),
|
||||
"streamurl": widget.streamUrl,
|
||||
"clientip": null,
|
||||
"sdp": offer.sdp,
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../core/di/injection.dart';
|
||||
import '../../../core/env/env_config.dart';
|
||||
import '../../../core/env/server_configuration.dart';
|
||||
import '../../../core/localization/app_localizations.dart';
|
||||
import '../../../core/network/mqtt/mqtt_manager.dart';
|
||||
import '../../../core/router/route_paths.dart';
|
||||
import '../../auth/presentation/bloc/auth_cubit.dart';
|
||||
import '../../auth/presentation/bloc/auth_state.dart';
|
||||
|
||||
class ServerConfigurationPage extends StatefulWidget {
|
||||
const ServerConfigurationPage({super.key});
|
||||
|
||||
@override
|
||||
State<ServerConfigurationPage> createState() =>
|
||||
_ServerConfigurationPageState();
|
||||
}
|
||||
|
||||
class _ServerConfigurationPageState extends State<ServerConfigurationPage> {
|
||||
final _host = TextEditingController();
|
||||
final _inputs = {
|
||||
for (final service in ServerService.values)
|
||||
service: TextEditingController(),
|
||||
};
|
||||
final _advanced = ExpansibleController();
|
||||
final _invalidServices = <ServerService>{};
|
||||
Map<ServerService, ({Uri address, bool reachable})> _results = {};
|
||||
bool _invalidHost = false;
|
||||
bool _saving = false;
|
||||
bool _testing = false;
|
||||
|
||||
bool get _busy => _saving || _testing;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final config = EnvConfig.serverConfiguration;
|
||||
_host.text = config.sharedHost;
|
||||
for (final entry in config.overrides.entries) {
|
||||
_inputs[entry.key]!.text = entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_host.dispose();
|
||||
for (final controller in _inputs.values) {
|
||||
controller.dispose();
|
||||
}
|
||||
_advanced.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
ServerConfiguration? _readDraft() {
|
||||
final host = _host.text.trim();
|
||||
final invalidHost = host.isNotEmpty && !ServerConfiguration.isHost(host);
|
||||
final effectiveHost = host.isEmpty || invalidHost
|
||||
? ServerConfiguration.defaultHost
|
||||
: host;
|
||||
final invalidServices = <ServerService>{};
|
||||
final inputs = <ServerService, String>{};
|
||||
for (final entry in _inputs.entries) {
|
||||
final input = entry.value.text.trim();
|
||||
inputs[entry.key] = input;
|
||||
try {
|
||||
entry.key.resolve(
|
||||
input,
|
||||
production: EnvConfig.isProduction,
|
||||
commonHost: effectiveHost,
|
||||
);
|
||||
} on FormatException {
|
||||
invalidServices.add(entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_invalidHost = invalidHost;
|
||||
_invalidServices
|
||||
..clear()
|
||||
..addAll(invalidServices);
|
||||
});
|
||||
if (invalidServices.any((service) => !service.isCore)) _advanced.expand();
|
||||
if (invalidHost || invalidServices.isNotEmpty) return null;
|
||||
return ServerConfiguration(
|
||||
production: EnvConfig.isProduction,
|
||||
sharedHost: host,
|
||||
overrides: inputs,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _testConnection() async {
|
||||
FocusScope.of(context).unfocus();
|
||||
final draft = _readDraft();
|
||||
if (draft == null) return;
|
||||
setState(() {
|
||||
_testing = true;
|
||||
_results = {};
|
||||
});
|
||||
final results = await Future.wait(
|
||||
ServerService.values.map((service) async {
|
||||
final address = draft.address(service);
|
||||
var reachable = false;
|
||||
try {
|
||||
final socket = await Socket.connect(
|
||||
address.host,
|
||||
address.port,
|
||||
timeout: const Duration(seconds: 3),
|
||||
);
|
||||
socket.destroy();
|
||||
reachable = true;
|
||||
} on SocketException {
|
||||
// A failed reachability check does not prevent saving the address.
|
||||
}
|
||||
return MapEntry(service, (address: address, reachable: reachable));
|
||||
}),
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_testing = false;
|
||||
_results = Map.fromEntries(results);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
FocusScope.of(context).unfocus();
|
||||
final draft = _readDraft();
|
||||
if (draft == null) return;
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final previous = EnvConfig.serverConfiguration;
|
||||
bool changed(ServerService service) =>
|
||||
previous.address(service) != draft.address(service);
|
||||
final auth = context.read<AuthCubit>();
|
||||
final relogin =
|
||||
auth.state is AuthAuthenticated && ServerService.values.any(changed);
|
||||
final reconnectMqtt =
|
||||
relogin ||
|
||||
changed(ServerService.mqtt) ||
|
||||
changed(ServerService.droneMqtt);
|
||||
setState(() => _saving = true);
|
||||
|
||||
Future<void> applyConfiguration() async {
|
||||
try {
|
||||
await EnvConfig.saveServerConfiguration(sl<SharedPreferences>(), draft);
|
||||
} finally {
|
||||
if (reconnectMqtt) await MqttManager().reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (relogin) {
|
||||
await auth.logoutForServerChange(applyConfiguration);
|
||||
} else {
|
||||
await applyConfiguration();
|
||||
}
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.translate('servers.saved'))));
|
||||
if (!relogin && context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go(
|
||||
auth.state is AuthAuthenticated ? RoutePaths.home : RoutePaths.login,
|
||||
);
|
||||
}
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(l10n.translate('servers.save_failed'))),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _saving = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final loggedIn = context.select(
|
||||
(AuthCubit auth) => auth.state is AuthAuthenticated,
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.translate('servers.title'))),
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(l10n.translate('servers.help')),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _host,
|
||||
enabled: !_busy,
|
||||
keyboardType: TextInputType.url,
|
||||
autocorrect: false,
|
||||
onChanged: (_) => setState(() {
|
||||
_invalidHost = false;
|
||||
_results = {};
|
||||
}),
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: l10n.translate('servers.shared_host'),
|
||||
hintText: ServerConfiguration.defaultHost,
|
||||
errorText: _invalidHost
|
||||
? l10n.translate('servers.invalid_host')
|
||||
: null,
|
||||
),
|
||||
),
|
||||
for (final service in ServerService.values.where(
|
||||
(service) => service.isCore,
|
||||
))
|
||||
_serviceField(service, l10n),
|
||||
const SizedBox(height: 12),
|
||||
ExpansionTile(
|
||||
controller: _advanced,
|
||||
title: Text(l10n.translate('servers.advanced')),
|
||||
tilePadding: EdgeInsets.zero,
|
||||
children: [
|
||||
for (final service in ServerService.values.where(
|
||||
(service) => !service.isCore,
|
||||
))
|
||||
_serviceField(service, l10n),
|
||||
],
|
||||
),
|
||||
if (loggedIn) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(l10n.translate('servers.relogin')),
|
||||
],
|
||||
if (_saving || _testing) ...[
|
||||
const SizedBox(height: 12),
|
||||
const LinearProgressIndicator(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
minimum: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 12,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: _busy ? null : _testConnection,
|
||||
child: Text(l10n.translate('servers.test_ports')),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _busy ? null : _save,
|
||||
child: Text(l10n.translate('servers.save')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _serviceField(ServerService service, AppLocalizations l10n) {
|
||||
final input = _inputs[service]!;
|
||||
final host = _host.text.trim();
|
||||
final sharedHost = ServerConfiguration.isHost(host)
|
||||
? host
|
||||
: ServerConfiguration.defaultHost;
|
||||
Uri address;
|
||||
try {
|
||||
address = service.resolve(
|
||||
input.text.trim(),
|
||||
production: EnvConfig.isProduction,
|
||||
commonHost: sharedHost,
|
||||
);
|
||||
} on FormatException {
|
||||
address = service.defaultAddress(
|
||||
production: EnvConfig.isProduction,
|
||||
commonHost: sharedHost,
|
||||
);
|
||||
}
|
||||
final result = _results[service];
|
||||
final text = result == null
|
||||
? address.toString()
|
||||
: l10n.translate(
|
||||
result.reachable ? 'servers.reachable' : 'servers.unreachable',
|
||||
{'address': result.address.toString()},
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: TextField(
|
||||
controller: input,
|
||||
enabled: !_busy,
|
||||
keyboardType: TextInputType.url,
|
||||
autocorrect: false,
|
||||
onChanged: (_) => setState(() {
|
||||
_invalidServices.remove(service);
|
||||
_results = {};
|
||||
}),
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: l10n.translate('servers.${service.name}'),
|
||||
helperText: text,
|
||||
helperMaxLines: 2,
|
||||
errorText: _invalidServices.contains(service)
|
||||
? l10n.translate('servers.invalid_address')
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_state.dart'; // 🔥 导入 AppUserState
|
||||
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 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/webrtc/webrtc_local_player.dart';
|
||||
@@ -58,7 +58,7 @@ class _RobotHeaderCardState extends State<RobotHeaderCard> {
|
||||
if (deviceId == null || deviceId.isEmpty || token == null) {
|
||||
return '';
|
||||
}
|
||||
return "webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=$token";
|
||||
return "webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/$deviceId?token=$token";
|
||||
}
|
||||
|
||||
/// 🔥 点击播放按钮
|
||||
|
||||
@@ -83,6 +83,17 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
|
||||
_buildUpdateSection(),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Card(
|
||||
margin: EdgeInsets.zero,
|
||||
color: context.appColors.cardBackground,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.settings_ethernet),
|
||||
title: Text(AppLocalizations.of(context).translate('servers.title')),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => context.push(RoutePaths.serverConfiguration),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 退出登录(已挪至“我的”页面最下边,此处注释掉)
|
||||
// _buildLogoutButton(context),
|
||||
// const SizedBox(height: 20),
|
||||
|
||||
Reference in New Issue
Block a user