|
|
|
@ -1,5 +1,4 @@ |
|
|
|
import 'package:agora_rtc_engine/agora_rtc_engine.dart'; |
|
|
|
import 'package:dating_touchme_app/model/live/live_chat_message.dart'; |
|
|
|
import 'package:dating_touchme_app/model/rtc/rtc_channel_data.dart'; |
|
|
|
import 'package:dating_touchme_app/model/rtc/rtc_channel_detail.dart'; |
|
|
|
import 'package:dating_touchme_app/network/network_service.dart'; |
|
|
|
@ -9,12 +8,14 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
|
|
|
|
import '../../model/live/live_chat_message.dart'; |
|
|
|
|
|
|
|
// 当前角色 |
|
|
|
enum CurrentRole{ |
|
|
|
broadcaster,//主持 |
|
|
|
maleAudience,//男嘉宾 |
|
|
|
femaleAudience,//女嘉宾 |
|
|
|
audience,//观众 |
|
|
|
enum CurrentRole { |
|
|
|
broadcaster, //主持 |
|
|
|
maleAudience, //男嘉宾 |
|
|
|
femaleAudience, //女嘉宾 |
|
|
|
audience, //观众 |
|
|
|
normalUser, //普通用户 |
|
|
|
} |
|
|
|
|
|
|
|
@ -26,6 +27,7 @@ class RoomController extends GetxController { |
|
|
|
final NetworkService _networkService; |
|
|
|
CurrentRole currentRole = CurrentRole.normalUser; |
|
|
|
bool isLive = false; |
|
|
|
|
|
|
|
/// 当前频道信息 |
|
|
|
final Rxn<RtcChannelData> rtcChannel = Rxn<RtcChannelData>(); |
|
|
|
final Rxn<RtcChannelDetail> rtcChannelDetail = Rxn<RtcChannelDetail>(); |
|
|
|
@ -158,7 +160,10 @@ class RoomController extends GetxController { |
|
|
|
'channelId': rtcChannel.value?.channelId, |
|
|
|
'seatNumber': role == CurrentRole.maleAudience ? 1 : 2, |
|
|
|
'isMicrophoneOn': role != CurrentRole.normalUser ? true : false, |
|
|
|
'isVideoOn': role == CurrentRole.maleAudience || role == CurrentRole.femaleAudience ? true : false, |
|
|
|
'isVideoOn': |
|
|
|
role == CurrentRole.maleAudience || role == CurrentRole.femaleAudience |
|
|
|
? true |
|
|
|
: false, |
|
|
|
}; |
|
|
|
final response = await _networkService.rtcApi.connectRtcChannel(data); |
|
|
|
if (!response.data.isSuccess) { |
|
|
|
@ -166,21 +171,38 @@ class RoomController extends GetxController { |
|
|
|
return; |
|
|
|
} |
|
|
|
currentRole = role; |
|
|
|
if(role == CurrentRole.maleAudience || role == CurrentRole.femaleAudience){ |
|
|
|
if (role == CurrentRole.maleAudience || |
|
|
|
role == CurrentRole.femaleAudience) { |
|
|
|
await RTCManager.instance.publishVideo(role); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
await RTCManager.instance.publishAudio(); |
|
|
|
} |
|
|
|
isLive = true; |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> leaveChat() async { |
|
|
|
final data = { |
|
|
|
'channelId': rtcChannel.value?.channelId |
|
|
|
}; |
|
|
|
final data = {'channelId': rtcChannel.value?.channelId}; |
|
|
|
final response = await _networkService.rtcApi.disconnectRtcChannel(data); |
|
|
|
if(response.data.isSuccess){ |
|
|
|
if (response.data.isSuccess) { |
|
|
|
isLive = false; |
|
|
|
await RTCManager.instance.unpublish(); |
|
|
|
if (currentRole == CurrentRole.maleAudience) { |
|
|
|
final newDetail = RtcChannelDetail( |
|
|
|
channelId: rtcChannelDetail.value!.channelId, |
|
|
|
anchorInfo: rtcChannelDetail.value!.anchorInfo, |
|
|
|
maleInfo: null, |
|
|
|
femaleInfo: rtcChannelDetail.value!.femaleInfo, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
} else if (currentRole == CurrentRole.femaleAudience) { |
|
|
|
final newDetail = RtcChannelDetail( |
|
|
|
channelId: rtcChannelDetail.value!.channelId, |
|
|
|
anchorInfo: rtcChannelDetail.value!.anchorInfo, |
|
|
|
maleInfo: rtcChannelDetail.value!.maleInfo, |
|
|
|
femaleInfo: null, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -234,6 +256,94 @@ class RoomController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> leaveChannel() async { |
|
|
|
isLive = false; |
|
|
|
currentRole = CurrentRole.normalUser;; |
|
|
|
await RTCManager.instance.leaveChannel(); |
|
|
|
} |
|
|
|
|
|
|
|
/// 接收RTC消息 |
|
|
|
Future<void> receiveRTCMessage(Map<String, dynamic> message) async { |
|
|
|
if (message['type'] == 'join_chat') { |
|
|
|
final response = await _networkService.rtcApi.getDatingRtcChannelUserDetail( |
|
|
|
rtcChannel.value!.channelId, |
|
|
|
message['uid'], |
|
|
|
); |
|
|
|
if (!response.data.isSuccess) { |
|
|
|
return; |
|
|
|
} |
|
|
|
final currentDetail = rtcChannelDetail.value; |
|
|
|
if (currentDetail == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (message['role'] == 'male_audience') { |
|
|
|
final userData = response.data.data; |
|
|
|
// if (userData != null) { |
|
|
|
final maleInfo = RtcSeatUserInfo( |
|
|
|
miId: rtcChannelDetail.value!.anchorInfo!.miId, |
|
|
|
userId: rtcChannelDetail.value!.anchorInfo!.userId, |
|
|
|
nickName: rtcChannelDetail.value!.anchorInfo!.nickName, |
|
|
|
profilePhoto: rtcChannelDetail.value!.anchorInfo!.profilePhoto, |
|
|
|
genderCode: rtcChannelDetail.value!.anchorInfo!.genderCode, |
|
|
|
seatNumber: rtcChannelDetail.value!.anchorInfo!.seatNumber, |
|
|
|
isFriend: rtcChannelDetail.value!.anchorInfo!.isFriend, |
|
|
|
isMicrophoneOn: rtcChannelDetail.value!.anchorInfo!.isMicrophoneOn, |
|
|
|
isVideoOn: rtcChannelDetail.value!.anchorInfo!.isVideoOn, |
|
|
|
uid: message['uid'] is int |
|
|
|
? message['uid'] as int |
|
|
|
: int.tryParse(message['uid']?.toString() ?? ''), |
|
|
|
); |
|
|
|
final newDetail = RtcChannelDetail( |
|
|
|
channelId: currentDetail.channelId, |
|
|
|
anchorInfo: currentDetail.anchorInfo, |
|
|
|
maleInfo: maleInfo, |
|
|
|
femaleInfo: currentDetail.femaleInfo, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
// } |
|
|
|
} else if (message['role'] == 'female_audience') { |
|
|
|
final userData = response.data.data; |
|
|
|
// if (userData != null) { |
|
|
|
final femaleInfo = RtcSeatUserInfo( |
|
|
|
miId: rtcChannelDetail.value!.anchorInfo!.miId, |
|
|
|
userId: rtcChannelDetail.value!.anchorInfo!.userId, |
|
|
|
nickName: rtcChannelDetail.value!.anchorInfo!.nickName, |
|
|
|
profilePhoto: rtcChannelDetail.value!.anchorInfo!.profilePhoto, |
|
|
|
genderCode: rtcChannelDetail.value!.anchorInfo!.genderCode, |
|
|
|
seatNumber: rtcChannelDetail.value!.anchorInfo!.seatNumber, |
|
|
|
isFriend: rtcChannelDetail.value!.anchorInfo!.isFriend, |
|
|
|
isMicrophoneOn: rtcChannelDetail.value!.anchorInfo!.isMicrophoneOn, |
|
|
|
isVideoOn: rtcChannelDetail.value!.anchorInfo!.isVideoOn, |
|
|
|
uid: message['uid'] is int |
|
|
|
? message['uid'] as int |
|
|
|
: int.tryParse(message['uid']?.toString() ?? ''), |
|
|
|
); |
|
|
|
final newDetail = RtcChannelDetail( |
|
|
|
channelId: currentDetail.channelId, |
|
|
|
anchorInfo: currentDetail.anchorInfo, |
|
|
|
maleInfo: currentDetail.maleInfo, |
|
|
|
femaleInfo: femaleInfo, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
} |
|
|
|
// } |
|
|
|
}else if (message['type'] == 'leave_chat') { |
|
|
|
if (message['role'] == 'male_audience') { |
|
|
|
final newDetail = RtcChannelDetail( |
|
|
|
channelId: rtcChannelDetail.value!.channelId, |
|
|
|
anchorInfo: rtcChannelDetail.value!.anchorInfo, |
|
|
|
maleInfo: null, |
|
|
|
femaleInfo: rtcChannelDetail.value!.femaleInfo, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
} else if (message['role'] == 'female_audience') { |
|
|
|
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, |
|
|
|
); |
|
|
|
rtcChannelDetail.value = newDetail; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |