From 5b7bae50aa28c7c16ea5c54e75ec8a5dbfcb24bc Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Mon, 24 Nov 2025 01:45:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(live):=20=E4=BF=AE=E5=A4=8D=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E6=88=BF=E9=97=B4=E8=A7=82=E4=BC=97=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整聊天面板显示条件,确保仅非主播角色可见 - 更新 RTC 断开连接逻辑,传递当前用户角色以正确取消发布 - 在离开频道时增加对男性和女性观众的角色判断并执行取消发布 - 修改频道详情更新逻辑,避免清除男性信息并强制清空女性信息 - 优化 RTC 管理器中的取消发布方法 --- lib/controller/discover/room_controller.dart | 9 ++++++--- lib/rtc/rtc_manager.dart | 5 +++-- lib/widget/live/live_room_notice_chat_panel.dart | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/controller/discover/room_controller.dart b/lib/controller/discover/room_controller.dart index 0011b47..ec95211 100644 --- a/lib/controller/discover/room_controller.dart +++ b/lib/controller/discover/room_controller.dart @@ -205,7 +205,7 @@ class RoomController extends GetxController { final response = await _networkService.rtcApi.disconnectRtcChannel(data); if (response.data.isSuccess) { isLive = false; - await RTCManager.instance.unpublish(); + await RTCManager.instance.unpublish(currentRole); if (currentRole == CurrentRole.maleAudience) { final newDetail = RtcChannelDetail( channelId: rtcChannelDetail.value!.channelId, @@ -276,6 +276,9 @@ class RoomController extends GetxController { Future leaveChannel() async { isLive = false; + if (currentRole == CurrentRole.maleAudience || currentRole == CurrentRole.femaleAudience) { + await RTCManager.instance.unpublish(currentRole); + } currentRole = CurrentRole.normalUser;; await RTCManager.instance.leaveChannel(); } @@ -358,8 +361,8 @@ class RoomController extends GetxController { final newDetail = RtcChannelDetail( channelId: rtcChannelDetail.value!.channelId, anchorInfo: rtcChannelDetail.value!.anchorInfo, - maleInfo: rtcChannelDetail.value!.maleInfo?.uid != message['uid'] ? rtcChannelDetail.value!.maleInfo : null, - femaleInfo: rtcChannelDetail.value!.femaleInfo?.uid != message['uid'] ? rtcChannelDetail.value!.femaleInfo : null, + maleInfo: rtcChannelDetail.value!.maleInfo, + femaleInfo: null, ); rtcChannelDetail.value = newDetail; } diff --git a/lib/rtc/rtc_manager.dart b/lib/rtc/rtc_manager.dart index c37ad65..4403136 100644 --- a/lib/rtc/rtc_manager.dart +++ b/lib/rtc/rtc_manager.dart @@ -516,13 +516,14 @@ class RTCManager { } /// 取消发布视频 - Future unpublish() async { + Future unpublish(CurrentRole role) async { await _engine?.setClientRole(role: ClientRoleType.clientRoleAudience); await _engine?.muteLocalAudioStream(true); await _engine?.muteLocalVideoStream(true); await RTMManager.instance.publishChannelMessage( channelName: _currentChannelId ?? '', - message: json.encode({'type': 'leave_chat', 'uid': _currentUid}), + message: json.encode({'type': 'leave_chat', 'uid': _currentUid, 'role': role == CurrentRole.maleAudience + ? 'male_audience' : 'female_audience',}), ); } } diff --git a/lib/widget/live/live_room_notice_chat_panel.dart b/lib/widget/live/live_room_notice_chat_panel.dart index fb429ad..4de83f3 100644 --- a/lib/widget/live/live_room_notice_chat_panel.dart +++ b/lib/widget/live/live_room_notice_chat_panel.dart @@ -77,8 +77,8 @@ class _LiveRoomNoticeChatPanelState extends State { SizedBox(width: 18.w), Obx((){ if(controller.rtcChannelDetail.value?.maleInfo == null && GlobalData().userData?.genderCode == 0 && controller.currentRole != CurrentRole.broadcaster || - controller.rtcChannelDetail.value?.femaleInfo == null && GlobalData().userData?.genderCode == 1 && controller.currentRole != CurrentRole.broadcaster || controller.isLive){ - Get.log('${controller.isLive}'); + controller.rtcChannelDetail.value?.femaleInfo == null && GlobalData().userData?.genderCode == 1 && controller.currentRole != CurrentRole.broadcaster || + controller.isLive && controller.currentRole != CurrentRole.broadcaster){ return Container( width: 120.w, height: 55.w,