|
|
@ -238,8 +238,19 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> joinChat(CurrentRole role) async { |
|
|
Future<void> joinChat(CurrentRole role) async { |
|
|
final granted = await _ensureRtcPermissions(); |
|
|
|
|
|
if (!granted) return; |
|
|
|
|
|
|
|
|
// 根据角色检查权限:男/女嘉宾需要摄像头和麦克风权限,普通观众只需要麦克风权限 |
|
|
|
|
|
bool granted = false; |
|
|
|
|
|
if (role == CurrentRole.maleAudience || role == CurrentRole.femaleAudience) { |
|
|
|
|
|
// 男/女嘉宾上麦:需要摄像头和麦克风权限 |
|
|
|
|
|
granted = await _ensureRtcPermissions(); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 普通观众上麦:只需要麦克风权限 |
|
|
|
|
|
granted = await _ensureMicrophonePermission(); |
|
|
|
|
|
} |
|
|
|
|
|
if (!granted) { |
|
|
|
|
|
print('❌ [RoomController] 权限检查失败,无法上麦'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
final data = { |
|
|
final data = { |
|
|
'channelId': RTCManager.instance.currentChannelId, |
|
|
'channelId': RTCManager.instance.currentChannelId, |
|
|
'seatNumber': role == CurrentRole.maleAudience ? 1 : 2, |
|
|
'seatNumber': role == CurrentRole.maleAudience ? 1 : 2, |
|
|
@ -374,6 +385,22 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 检查麦克风权限(用于普通观众上麦) |
|
|
|
|
|
Future<bool> _ensureMicrophonePermission() async { |
|
|
|
|
|
final micStatus = await Permission.microphone.request(); |
|
|
|
|
|
if (micStatus.isGranted) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (micStatus.isPermanentlyDenied) { |
|
|
|
|
|
SmartDialog.showToast('请在系统设置中开启麦克风权限'); |
|
|
|
|
|
await openAppSettings(); |
|
|
|
|
|
} else { |
|
|
|
|
|
SmartDialog.showToast('请允许麦克风权限以进入房间'); |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Future<void> leaveChannel() async { |
|
|
Future<void> leaveChannel() async { |
|
|
if (currentRole == CurrentRole.broadcaster) { |
|
|
if (currentRole == CurrentRole.broadcaster) { |
|
|
try { |
|
|
try { |
|
|
|