支持现场服务器地址配置
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user