Browse Source

增加升级红娘,对接支付查询

ios
王子贤 4 months ago
parent
commit
5a9cc60f58
7 changed files with 73 additions and 1897 deletions
  1. 105
      lib/controller/discover/room_controller.dart
  2. 4
      lib/controller/discover/svga_player_manager.dart
  3. 57
      lib/rtc/rtc_manager.dart
  4. 14
      lib/widget/live/live_gift_popup.dart
  5. 6
      lib/widget/live/live_room_anchor_showcase.dart
  6. 1782
      pubspec.lock
  7. 2
      pubspec.yaml

105
lib/controller/discover/room_controller.dart

@ -201,6 +201,10 @@ class RoomController extends GetxController with WidgetsBindingObserver {
SmartDialog.showToast(response.data.message);
return;
}
if (!response.data.data['success']) {
SmartDialog.showToast('积分不足');
return;
}
currentRole = role;
if (role == CurrentRole.maleAudience ||
role == CurrentRole.femaleAudience) {
@ -264,7 +268,8 @@ class RoomController extends GetxController with WidgetsBindingObserver {
}
}
Future<void> _fetchRtcChannelDetail(String channelName) async {
/// RTC
Future<void> fetchRtcChannelDetail(String channelName) async {
try {
final response = await _networkService.rtcApi.getRtcChannelDetail(
channelName,
@ -278,6 +283,10 @@ class RoomController extends GetxController with WidgetsBindingObserver {
}
}
Future<void> _fetchRtcChannelDetail(String channelName) async {
await fetchRtcChannelDetail(channelName);
}
///
Future<void> sendChatMessage(String content) async {
final channelName = RTCManager.instance.currentChannelId;
@ -362,7 +371,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
///
Future<void> sendGift({
required GiftProductModel gift,
String? targetUserId,
required int targetUserId,
}) async {
try {
//
@ -376,7 +385,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
final requestData = {
'channelId': int.tryParse(channelId) ?? 0,
'type': 1, // 1. 2.
'toUId': targetUserId != null ? int.tryParse(targetUserId) ?? 0 : 0,
'toUId': targetUserId,
'productSpecId': int.tryParse(gift.productSpecId) ?? 0,
'quantity': 1,
};
@ -399,7 +408,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
SvgaAnimationItem(
svgaFile: gift.svgaFile,
targetUserId: targetUserId,
senderUserId: GlobalData().userId ?? GlobalData().userData?.id,
senderUserId: rtcChannel.value?.uid,
giftProductId: gift.productId,
),
);
@ -411,7 +420,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
'svgaFile': gift.svgaFile,
'giftProductId': gift.productId,
'targetUserId': targetUserId,
'senderUserId': GlobalData().userId ?? GlobalData().userData?.id,
'senderUserId': rtcChannel.value?.uid,
'senderNickName': GlobalData().userData?.nickName ?? '',
};
@ -433,8 +442,8 @@ class RoomController extends GetxController with WidgetsBindingObserver {
try {
final svgaFile = message['svgaFile']?.toString() ?? '';
final giftProductId = message['giftProductId']?.toString();
final targetUserId = message['targetUserId']?.toString();
final senderUserId = message['senderUserId']?.toString();
final targetUserId = message['targetUserId']?.toInt() ?? 0;
final senderUserId = message['senderUserId']?.toInt() ?? 0;
final senderNickName = message['senderNickName']?.toString() ?? '';
if (svgaFile.isNotEmpty) {
@ -453,88 +462,6 @@ class RoomController extends GetxController with WidgetsBindingObserver {
} catch (e) {
print('❌ 处理礼物消息失败: $e');
}
} else if (message['type'] == 'join_chat') {
final response = await _networkService.rtcApi
.getDatingRtcChannelUserDetail(
rtcChannel.value!.channelId,
message['uid'],
);
if (!response.data.isSuccess) {
return;
}
final currentDetail = rtcChannelDetail.value;
if (currentDetail == null) {
return;
}
final userData = response.data.data;
if (userData == null) {
return;
}
if (message['role'] == 'male_audience') {
final maleInfo = RtcSeatUserInfo(
miId: userData.miId,
userId: userData.userId,
nickName: userData.nickName,
profilePhoto: userData.profilePhoto,
genderCode: userData.genderCode,
seatNumber: userData.seatNumber,
isFriend: userData.isFriend,
isMicrophoneOn: userData.isMicrophoneOn,
isVideoOn: userData.isVideoOn,
uid: message['uid'] is int
? message['uid'] as int
: int.tryParse(message['uid']?.toString() ?? ''),
);
final newDetail = RtcChannelDetail(
channelId: currentDetail.channelId,
anchorInfo: currentDetail.anchorInfo,
maleInfo: maleInfo,
femaleInfo: currentDetail.femaleInfo,
);
rtcChannelDetail.value = newDetail;
} else if (message['role'] == 'female_audience') {
final femaleInfo = RtcSeatUserInfo(
miId: userData.miId,
userId: userData.userId,
nickName: userData.nickName,
profilePhoto: userData.profilePhoto,
genderCode: userData.genderCode,
seatNumber: userData.seatNumber,
isFriend: userData.isFriend,
isMicrophoneOn: userData.isMicrophoneOn,
isVideoOn: userData.isVideoOn,
uid: message['uid'] is int
? message['uid'] as int
: int.tryParse(message['uid']?.toString() ?? ''),
);
final newDetail = RtcChannelDetail(
channelId: currentDetail.channelId,
anchorInfo: currentDetail.anchorInfo,
maleInfo: currentDetail.maleInfo,
femaleInfo: femaleInfo,
);
rtcChannelDetail.value = newDetail;
}
// }
} else if (message['type'] == 'leave_chat') {
if (message['role'] == 'male_audience') {
final newDetail = RtcChannelDetail(
channelId: rtcChannelDetail.value!.channelId,
anchorInfo: rtcChannelDetail.value!.anchorInfo,
maleInfo: null,
femaleInfo: rtcChannelDetail.value!.femaleInfo,
);
rtcChannelDetail.value = newDetail;
} else if (message['role'] == 'female_audience') {
final newDetail = RtcChannelDetail(
channelId: rtcChannelDetail.value!.channelId,
anchorInfo: rtcChannelDetail.value!.anchorInfo,
maleInfo: rtcChannelDetail.value!.maleInfo,
femaleInfo: null,
);
rtcChannelDetail.value = newDetail;
}
}
}

4
lib/controller/discover/svga_player_manager.dart

@ -6,8 +6,8 @@ import 'package:get/get.dart';
/// SVGA
class SvgaAnimationItem {
final String svgaFile;
final String? targetUserId; // ID
final String? senderUserId; // ID
final int? targetUserId; // ID
final int? senderUserId; // ID
final String? giftProductId; // ID
SvgaAnimationItem({

57
lib/rtc/rtc_manager.dart

@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import '../controller/discover/room_controller.dart';
import '../network/network_service.dart';
import '../pages/discover/live_room_page.dart';
/// RTC
@ -119,6 +118,16 @@ class RTCManager {
channelJoinedNotifier.value = true;
_currentChannelId = connection.channelId;
print('加入频道成功,频道名:${connection.channelId},耗时:${elapsed}ms');
// RoomController fetchRtcChannelDetail
final channelId = connection.channelId;
if (Get.isRegistered<RoomController>() &&
channelId != null &&
channelId.isNotEmpty) {
final roomController = Get.find<RoomController>();
await roomController.fetchRtcChannelDetail(channelId);
}
if (connection.localUid == _currentUid) {
await RTMManager.instance.subscribe(_currentChannelId ?? '');
await RTMManager.instance.publishChannelMessage(
@ -131,21 +140,42 @@ class RTCManager {
onJoinChannelSuccess!(connection, elapsed);
}
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) async{
print('用户加入,UID:$remoteUid');
_handleRemoteUserJoined(remoteUid);
if (onUserJoined != null) {
onUserJoined!(connection, remoteUid, elapsed);
}
},
onUserJoined:
(RtcConnection connection, int remoteUid, int elapsed) async {
print('用户加入,UID:$remoteUid');
_handleRemoteUserJoined(remoteUid);
// RoomController fetchRtcChannelDetail
final channelId = connection.channelId;
if (Get.isRegistered<RoomController>() &&
channelId != null &&
channelId.isNotEmpty) {
final roomController = Get.find<RoomController>();
await roomController.fetchRtcChannelDetail(channelId);
}
if (onUserJoined != null) {
onUserJoined!(connection, remoteUid, elapsed);
}
},
onUserOffline:
(
RtcConnection connection,
int remoteUid,
UserOfflineReasonType reason,
) {
) async {
print('用户离开,UID:$remoteUid,原因:$reason');
_handleRemoteUserOffline(remoteUid);
// RoomController fetchRtcChannelDetail
final channelId = connection.channelId;
if (Get.isRegistered<RoomController>() &&
channelId != null &&
channelId.isNotEmpty) {
final roomController = Get.find<RoomController>();
await roomController.fetchRtcChannelDetail(channelId);
}
if (onUserOffline != null) {
onUserOffline!(connection, remoteUid, reason);
}
@ -521,8 +551,13 @@ class RTCManager {
await _engine?.muteLocalVideoStream(true);
await RTMManager.instance.publishChannelMessage(
channelName: _currentChannelId ?? '',
message: json.encode({'type': 'leave_chat', 'uid': _currentUid, 'role': role == CurrentRole.maleAudience
? 'male_audience' : 'female_audience',}),
message: json.encode({
'type': 'leave_chat',
'uid': _currentUid,
'role': role == CurrentRole.maleAudience
? 'male_audience'
: 'female_audience',
}),
);
}
}

14
lib/widget/live/live_gift_popup.dart

@ -26,7 +26,7 @@ class LiveGiftPopup extends StatefulWidget {
final List<dynamic> giftList; // List<Map> List<GiftProductModel>
final void Function(int) changeActive;
final bool showHeader; //
final String? targetUserId; // ID
final int? targetUserId; // ID
@override
State<LiveGiftPopup> createState() => _LiveGiftPopupState();
@ -34,7 +34,7 @@ class LiveGiftPopup extends StatefulWidget {
class _LiveGiftPopupState extends State<LiveGiftPopup> {
// ID
String? _selectedUserId;
int? _selectedUserId;
@override
void initState() {
@ -50,7 +50,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
//
void _toggleUserSelection(String userId) {
void _toggleUserSelection(int userId) {
setState(() {
if (_selectedUserId == userId) {
//
@ -74,7 +74,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
// showHeader为falsetargetUserId
if (_selectedUserId == null || _selectedUserId!.isEmpty) {
if (_selectedUserId == 0) {
if (widget.showHeader) {
SmartDialog.showToast('请先选择接收礼物的用户');
}
@ -107,7 +107,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
//
await roomController.sendGift(gift: gift, targetUserId: _selectedUserId);
await roomController.sendGift(gift: gift, targetUserId: _selectedUserId ?? 0);
SmartDialog.dismiss();
}
@ -208,9 +208,9 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
...displayUsers.asMap().entries.map((entry) {
final index = entry.key;
final user = entry.value;
final isSelected = _selectedUserId == user.userId;
final isSelected = _selectedUserId == user.uid;
return GestureDetector(
onTap: () => _toggleUserSelection(user.userId),
onTap: () => _toggleUserSelection(user.uid ?? 0),
child: Padding(
padding: EdgeInsets.only(right: 10.w),
child: Stack(

6
lib/widget/live/live_room_anchor_showcase.dart

@ -361,11 +361,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
}
// ID使userId使miId
final targetUserId = userInfo.userId.isNotEmpty
? userInfo.userId
: userInfo.miId.isNotEmpty
? userInfo.miId
: null;
final targetUserId = userInfo.uid;
if (targetUserId == null) {
SmartDialog.showToast('用户ID不存在');

1782
pubspec.lock
File diff suppressed because it is too large
View File

2
pubspec.yaml

@ -45,7 +45,7 @@ dependencies:
path_provider: ^2.1.4
event_bus: ^2.0.1
dio: ^5.9.0
retrofit: ^4.9.0
retrofit: 4.9.0
flutter_native_splash: ^2.4.7
im_flutter_sdk: ^4.15.2
easy_localization: ^3.0.8

Loading…
Cancel
Save