添加 network_info_plus 依赖以支持局域网 IP 获取;在事件信息和录制页面中增强局域网 IP 查询功能,更新相关模型以包含 scheduleId 字段;重构录制页面以改善用户体验,修复推流控制器释放逻辑。
This commit is contained in:
@@ -16,14 +16,21 @@ class StreamKeyReq {
|
||||
required this.eventId,
|
||||
required this.itemId,
|
||||
required this.userId,
|
||||
required this.scheduleId,
|
||||
});
|
||||
|
||||
final String eventId;
|
||||
final String itemId;
|
||||
final String userId;
|
||||
final String scheduleId;
|
||||
|
||||
Map<String, dynamic> toFormDataMap() {
|
||||
return {'eventId': eventId, 'itemId': itemId, 'userId': userId};
|
||||
return {
|
||||
'eventId': eventId,
|
||||
'itemId': itemId,
|
||||
'userId': userId,
|
||||
'scheduleId': scheduleId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +143,7 @@ class EventRegistrationItem {
|
||||
final String playerName;
|
||||
final String playerPhone;
|
||||
|
||||
String get scheduleTime =>
|
||||
_formatScheduleTime(matchStartTime, matchEndTime);
|
||||
String get scheduleTime => _formatScheduleTime(matchStartTime, matchEndTime);
|
||||
|
||||
String? get statusLabel => completed ? '已完成' : null;
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:recording_tool/app/router/app_navigator.dart';
|
||||
import 'package:recording_tool/core/utils/util_search_nasIp.dart';
|
||||
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
||||
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
||||
import 'package:recording_tool/features/events/view_model/view_model_event_info.dart';
|
||||
import 'package:recording_tool/shared/widgets/app_webview.dart';
|
||||
import 'package:recording_tool/features/recording/model/model_recording_context.dart';
|
||||
import 'package:recording_tool/features/recording/pages/page_record.dart';
|
||||
import 'package:recording_tool/shared/widgets/widgets.dart';
|
||||
|
||||
class EventInfoPage extends ConsumerStatefulWidget {
|
||||
@@ -24,16 +26,33 @@ class _EventInfoPageState extends ConsumerState<EventInfoPage> {
|
||||
|
||||
Future<void> onItemTap(EventRegistrationItem item) async {
|
||||
// debugPrint('item tapped: ${item.itemName}');
|
||||
// await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
|
||||
final streamKey = await ref
|
||||
.read(eventInfoProvider.notifier)
|
||||
.requestStreamKey(item);
|
||||
if (streamKey == null || streamKey.isEmpty) {
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
// final profile = ref.read(eventInfoProvider).profile;
|
||||
|
||||
/// 个人赛
|
||||
/// 获取局域网 IP
|
||||
// final ip =
|
||||
// await ref.read(eventInfoProvider.notifier).getLocalIP() ?? 'sheling';
|
||||
final ip = UtilSearchNasIp.nasIp ?? 'sheling';
|
||||
// final ip = '192.168.1.245';
|
||||
// final streamUrl = 'rtmp://$ip:19090/$streamKey';
|
||||
final streamUrl = 'rtmp://$ip:19090/测试团队赛录分缓存/空中足球赛/初中组/林培伦vs周白芷';
|
||||
AppNavigator.push(
|
||||
WebviewPage(
|
||||
url: 'https://drone.apptest.sportsx.cc/#/pages/h5/score-entry',
|
||||
eventRegistrationItem: item,
|
||||
playerId: widget.playerId,
|
||||
RecordingPage(
|
||||
recordingContext: RecordingContext(
|
||||
eventTitle: item.eventName,
|
||||
matchName: item.itemName,
|
||||
group: item.groupName,
|
||||
venue: item.matchPlace,
|
||||
time: item.scheduleTime,
|
||||
playerName: item.playerName,
|
||||
playerPhone: item.playerPhone,
|
||||
),
|
||||
streamUrl: streamUrl,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/legacy.dart';
|
||||
import 'package:recording_tool/core/network/api_exception.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
||||
import 'package:recording_tool/features/events/server/server_events.dart';
|
||||
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
||||
@@ -20,10 +20,6 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
status: '',
|
||||
);
|
||||
|
||||
static const _fallbackEventId = '';
|
||||
static const _fallbackItemId = '';
|
||||
static const _fallbackStreamUserId = '';
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<bool> loadRegistrationList({
|
||||
@@ -50,28 +46,43 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
||||
/// 获取局域网 IP
|
||||
|
||||
Future<String?> getLocalIP() async {
|
||||
final info = NetworkInfo();
|
||||
try {
|
||||
// 获取当前连接 Wi-Fi 分配的局域网 IPv4 地址(例如 192.168.1.105)
|
||||
String? wifiIP = await info.getWifiIP();
|
||||
return wifiIP;
|
||||
} catch (e) {
|
||||
print("获取局域网 IP 失败: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> requestStreamKey(EventRegistrationItem item) async {
|
||||
state = state.copyWith(isRequestingStreamKey: true);
|
||||
final req = StreamKeyReq(
|
||||
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
||||
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
||||
userId: item.userId.isNotEmpty ? item.userId : _fallbackStreamUserId,
|
||||
eventId: item.eventId,
|
||||
itemId: item.itemId,
|
||||
userId: item.userId,
|
||||
scheduleId: item.scheduleId,
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await _ref
|
||||
.read(eventsServerProvider)
|
||||
.fetchStreamKey(req);
|
||||
debugPrint('推流 Key 接口响应: $response');
|
||||
debugPrint('推流 Key 接口响应: ${response.rawData['streamKey']}');
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
} on ApiException catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show(error.message);
|
||||
|
||||
return response.rawData['streamKey'];
|
||||
// return response['streamKey'];
|
||||
} catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: $error');
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show('推流 Key 获取失败');
|
||||
AppToast.show('获取选手信息失败');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user