Browse Source

fix(live): 修复直播房间观众角色处理逻辑

- 调整聊天面板显示条件,确保仅非主播角色可见
- 更新 RTC 断开连接逻辑,传递当前用户角色以正确取消发布
- 在离开频道时增加对男性和女性观众的角色判断并执行取消发布
- 修改频道详情更新逻辑,避免清除男性信息并强制清空女性信息
- 优化 RTC 管理器中的取消发布方法
ios
Jolie 4 months ago
parent
commit
5b7bae50aa
3 changed files with 11 additions and 7 deletions
  1. 9
      lib/controller/discover/room_controller.dart
  2. 5
      lib/rtc/rtc_manager.dart
  3. 4
      lib/widget/live/live_room_notice_chat_panel.dart

9
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<void> 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;
}

5
lib/rtc/rtc_manager.dart

@ -516,13 +516,14 @@ class RTCManager {
}
///
Future<void> unpublish() async {
Future<void> 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',}),
);
}
}

4
lib/widget/live/live_room_notice_chat_panel.dart

@ -77,8 +77,8 @@ class _LiveRoomNoticeChatPanelState extends State<LiveRoomNoticeChatPanel> {
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,

Loading…
Cancel
Save