|
|
|
@ -538,6 +538,32 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
|
} catch (e) { |
|
|
|
print('❌ 处理礼物消息失败: $e'); |
|
|
|
} |
|
|
|
} else if (message['type'] == 'kick_user') { |
|
|
|
// 处理踢人消息 |
|
|
|
try { |
|
|
|
final kickingUId = message['kickingUId']; |
|
|
|
final operatorName = message['operatorName']?.toString() ?? '主持人'; |
|
|
|
|
|
|
|
print('✅ 收到踢人消息: 被踢用户ID $kickingUId'); |
|
|
|
|
|
|
|
// 判断当前用户是否是被踢的用户 |
|
|
|
if (rtcChannel.value?.uid == kickingUId) { |
|
|
|
// 被踢用户:离开房间 |
|
|
|
SmartDialog.showToast('您已被$operatorName踢出房间'); |
|
|
|
await leaveChannel(); |
|
|
|
// 可以选择自动返回上一页或跳转到其他页面 |
|
|
|
Get.back(); |
|
|
|
} else { |
|
|
|
// 其他用户:刷新房间详情 |
|
|
|
final channelName = RTCManager.instance.currentChannelId; |
|
|
|
if (channelName != null && channelName.isNotEmpty) { |
|
|
|
await fetchRtcChannelDetail(channelName); |
|
|
|
} |
|
|
|
print('✅ 其他用户收到踢人消息,已刷新房间详情'); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
print('❌ 处理踢人消息失败: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -555,7 +581,7 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
|
|
|
|
|
/// 踢出 RTC 频道用户 |
|
|
|
Future<void> kickingRtcChannelUser({ |
|
|
|
required int channelId, |
|
|
|
required String channelId, |
|
|
|
required int kickingUId, |
|
|
|
}) async { |
|
|
|
try { |
|
|
|
@ -570,9 +596,24 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
|
|
|
|
|
if (response.data.isSuccess) { |
|
|
|
SmartDialog.showToast('已踢出用户'); |
|
|
|
// 刷新频道详情 |
|
|
|
|
|
|
|
// 发送 RTM 消息通知所有用户 |
|
|
|
final channelName = RTCManager.instance.currentChannelId; |
|
|
|
if (channelName != null && channelName.isNotEmpty) { |
|
|
|
final messageData = { |
|
|
|
'type': 'kick_user', |
|
|
|
'kickingUId': kickingUId, |
|
|
|
'operatorId': GlobalData().userData?.id ?? '', |
|
|
|
'operatorName': GlobalData().userData?.nickName ?? '', |
|
|
|
}; |
|
|
|
|
|
|
|
await RTMManager.instance.publishChannelMessage( |
|
|
|
channelName: channelName, |
|
|
|
message: json.encode(messageData), |
|
|
|
); |
|
|
|
print('✅ 踢人消息已发送: 踢出用户ID $kickingUId'); |
|
|
|
|
|
|
|
// 刷新频道详情 |
|
|
|
await fetchRtcChannelDetail(channelName); |
|
|
|
} |
|
|
|
} else { |
|
|
|
|