Browse Source

fix(live): 修复直播间功能和礼物防抖问题

- 添加礼物发送防抖机制,3秒内不允许重复点击
- 修复直播间跳转逻辑,避免重复加入相同频道
- 优化聊天消息点击处理,避免自己的消息显示用户资料对话框
- 添加频道切换时的退出机制,确保正确切换直播间
master
Jolie 3 months ago
parent
commit
ba27aae01d
4 changed files with 59 additions and 7 deletions
  1. 35
      lib/pages/discover/live_item_widget.dart
  2. 10
      lib/pages/message/chat_page.dart
  3. 13
      lib/widget/live/live_gift_popup.dart
  4. 8
      lib/widget/live/live_room_chat_item.dart

35
lib/pages/discover/live_item_widget.dart

@ -1,7 +1,10 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/controller/overlay_controller.dart';
import 'package:dating_touchme_app/generated/assets.dart';
import 'package:dating_touchme_app/model/discover/rtc_channel_model.dart';
import 'package:dating_touchme_app/pages/discover/live_room_page.dart';
import 'package:dating_touchme_app/rtc/rtc_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
@ -39,10 +42,38 @@ class _LiveItemWidgetState extends State<LiveItemWidget> {
Widget build(BuildContext context) {
return InkWell(
onTap: () async {
// channelId
String? targetChannelId;
if (widget.channelId != null && widget.channelId!.isNotEmpty) {
await roomController.joinChannel(widget.channelId!);
targetChannelId = widget.channelId!;
} else if (widget.item is Map && widget.item['channelId'] != null) {
await roomController.joinChannel(widget.item['channelId'].toString());
targetChannelId = widget.item['channelId'].toString();
}
if (targetChannelId == null || targetChannelId.isEmpty) {
return;
}
// channelId
final currentChannelId = RTCManager.instance.currentChannelId;
// channelId
if (currentChannelId != null &&
currentChannelId.isNotEmpty &&
currentChannelId == targetChannelId) {
//
if (Get.isRegistered<OverlayController>()) {
final overlayController = Get.find<OverlayController>();
overlayController.hide();
}
//
Get.to(() => const LiveRoomPage(id: 0));
} else {
// 退
if (currentChannelId != null && currentChannelId.isNotEmpty) {
await roomController.leaveChannel();
}
await roomController.joinChannel(targetChannelId);
}
},
child: ClipRRect(

10
lib/pages/message/chat_page.dart

@ -167,11 +167,11 @@ class _ChatPageState extends State<ChatPage> {
);
//
if (success) {
Get.to(() => VideoCallPage(
targetUserId: widget.userId,
userData: widget.userData ?? controller.userData,
isInitiator: true,
));
Get.to(() => VideoCallPage(
targetUserId: widget.userId,
userData: widget.userData ?? controller.userData,
isInitiator: true,
));
}
},
);

13
lib/widget/live/live_gift_popup.dart

@ -39,6 +39,8 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
int? _selectedUserId;
//
bool _hasTriedSetDefault = false;
// 3
DateTime? _lastSendGiftTime;
@override
void initState() {
@ -101,6 +103,17 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
//
Future<void> _handleSendGift(int type) async {
// 3
final now = DateTime.now();
if (_lastSendGiftTime != null) {
final duration = now.difference(_lastSendGiftTime!);
if (duration.inSeconds < 3) {
SmartDialog.showToast('操作太频繁,请稍后再试');
return;
}
}
_lastSendGiftTime = now;
//
final activeIndex = widget.activeGift.value;
if (activeIndex == null ||

8
lib/widget/live/live_room_chat_item.dart

@ -1,4 +1,5 @@
import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/controller/global.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart';
import 'package:dating_touchme_app/generated/assets.dart';
import 'package:dating_touchme_app/model/live/live_chat_message.dart';
@ -77,6 +78,13 @@ class LiveRoomChatItem extends StatelessWidget {
height: 25.w,
),
).onTap(() {
//
final currentUserId = GlobalData().userId ?? GlobalData().userData?.id;
if (currentUserId != null && currentUserId == message.userId) {
//
return;
}
//
showUserProfileDialog(
context,
message,

Loading…
Cancel
Save