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,