Browse Source

优化

dev-2.0
YakumoChen 2 weeks ago
parent
commit
b3779bdb8f
6 changed files with 109 additions and 8 deletions
  1. 6
      lib/controller/discover/room_controller.dart
  2. 14
      lib/controller/home/home_controller.dart
  3. 8
      lib/controller/message/chat_controller.dart
  4. 42
      lib/main.dart
  5. 17
      lib/rtc/rtc_manager.dart
  6. 30
      lib/widget/live/live_room_anchor_showcase.dart

6
lib/controller/discover/room_controller.dart

@ -90,6 +90,10 @@ class RoomController extends GetxController with WidgetsBindingObserver {
// matchmakerFlag // matchmakerFlag
final closeBoss = false.obs;
final closeMale = false.obs;
final closeFemale = false.obs;
final femaleData = Rxn<UserInfoData>(); final femaleData = Rxn<UserInfoData>();
final maleData = Rxn<UserInfoData>(); final maleData = Rxn<UserInfoData>();
@ -116,6 +120,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
} else { } else {
print("清除数据"); print("清除数据");
femaleData.value = null; femaleData.value = null;
closeFemale.value = false;
} }
if (value?.maleInfo != null) { if (value?.maleInfo != null) {
print("获取数据"); print("获取数据");
@ -123,6 +128,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
} else { } else {
print("清除数据"); print("清除数据");
maleData.value = null; maleData.value = null;
closeMale.value = false;
} }
}); });
} }

14
lib/controller/home/home_controller.dart

@ -102,6 +102,7 @@ class HomeController extends GetxController {
final sseClient = SSEClient(); final sseClient = SSEClient();
Timer? illTimer;
openSSE() async { openSSE() async {
final Stream<SSEResponse> stream = sseClient.connect("connectionId", request); final Stream<SSEResponse> stream = sseClient.connect("connectionId", request);
@ -117,7 +118,14 @@ class HomeController extends GetxController {
if (Get.isRegistered<RoomController>()) { if (Get.isRegistered<RoomController>()) {
final roomController = Get.find<RoomController>(); final roomController = Get.find<RoomController>();
if(data["data"]["illegalHandle"] == 1){ if(data["data"]["illegalHandle"] == 1){
// RTCManager.instance.closeCamera();
if(data["data"]["illegalSubLabel"] != "WithoutFace"){
illTimer?.cancel();
RTCManager.instance.closeCamera();
illTimer = Timer(const Duration(minutes: 2), () {
// 5
RTCManager.instance.reOpenCamera();
});
}
// overlay // overlay
if(!roomController.isDialogShowing.value){ if(!roomController.isDialogShowing.value){
@ -347,8 +355,8 @@ class HomeController extends GetxController {
throw Exception(response.data.message ?? '获取数据失败'); throw Exception(response.data.message ?? '获取数据失败');
} }
} catch(e){ } catch(e){
print('钱包数据获取失败: $e');
SmartDialog.showToast('钱包数据获取失败');
print('足迹数据获取失败: $e');
SmartDialog.showToast('足迹数据获取失败');
rethrow; rethrow;
} }

8
lib/controller/message/chat_controller.dart

@ -1849,12 +1849,16 @@ class ChatController extends GetxController {
} }
} }
bool isSend = false;
/// ///
Future<bool> sendGift({ Future<bool> sendGift({
required GiftProductModel gift, required GiftProductModel gift,
int quantity = 1, int quantity = 1,
}) async { }) async {
try { try {
if(isSend) return false;
isSend = true;
// IM // IM
final requestData = { final requestData = {
'toUserId': int.tryParse(userId) ?? 0, 'toUserId': int.tryParse(userId) ?? 0,
@ -1886,6 +1890,7 @@ class ChatController extends GetxController {
} else { } else {
SmartDialog.showToast('发送礼物失败'); SmartDialog.showToast('发送礼物失败');
} }
isSend = false;
return false; return false;
} }
@ -1938,6 +1943,7 @@ class ChatController extends GetxController {
if (Get.isLogEnable) { if (Get.isLogEnable) {
Get.log('✅ 礼物消息发送成功: ${gift.productTitle}'); Get.log('✅ 礼物消息发送成功: ${gift.productTitle}');
} }
isSend = false;
return true; return true;
} else { } else {
// //
@ -1946,6 +1952,7 @@ class ChatController extends GetxController {
update(); update();
} }
SmartDialog.showToast('礼物消息发送失败,请点击重发'); SmartDialog.showToast('礼物消息发送失败,请点击重发');
isSend = false;
return false; return false;
} }
} catch (e) { } catch (e) {
@ -1953,6 +1960,7 @@ class ChatController extends GetxController {
Get.log('❌ 发送礼物失败: $e'); Get.log('❌ 发送礼物失败: $e');
} }
SmartDialog.showToast('发送礼物失败: $e'); SmartDialog.showToast('发送礼物失败: $e');
isSend = false;
return false; return false;
} }
} }

42
lib/main.dart

@ -101,7 +101,9 @@ void main() async {
), ),
); );
}, },
home: Agreement(),
home: AppLifecycleCleaner(
child: Agreement(),
),
); );
}, },
) )
@ -374,4 +376,42 @@ class _MyAppState extends State<MyApp> {
} }
} }
class AppLifecycleCleaner extends StatefulWidget {
final Widget child;
const AppLifecycleCleaner({
super.key,
required this.child,
});
@override
State<AppLifecycleCleaner> createState() => _AppLifecycleCleanerState();
}
class _AppLifecycleCleanerState extends State<AppLifecycleCleaner>
with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
SmartDialog.dismiss(status: SmartStatus.toast);
}
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}

17
lib/rtc/rtc_manager.dart

@ -381,10 +381,23 @@ class RTCManager {
){ ){
print("$remoteUid,$state"); print("$remoteUid,$state");
print("变化变化"); print("变化变化");
final roomController = Get.find<RoomController>();
if(state == RemoteVideoState.remoteVideoStateStopped){ if(state == RemoteVideoState.remoteVideoStateStopped){
if(remoteUid == roomController.rtcChannelDetail.value?.anchorInfo?.uid){
roomController.closeBoss.value = true;
} else if(remoteUid == roomController.rtcChannelDetail.value?.femaleInfo?.uid){
roomController.closeFemale.value = true;
} else if(remoteUid == roomController.rtcChannelDetail.value?.maleInfo?.uid){
roomController.closeMale.value = true;
}
} else { } else {
if(remoteUid == roomController.rtcChannelDetail.value?.anchorInfo?.uid){
roomController.closeBoss.value = false;
} else if(remoteUid == roomController.rtcChannelDetail.value?.femaleInfo?.uid){
roomController.closeFemale.value = false;
} else if(remoteUid == roomController.rtcChannelDetail.value?.maleInfo?.uid){
roomController.closeMale.value = false;
}
} }
}, },
onError: (ErrorCodeType err, String msg) { onError: (ErrorCodeType err, String msg) {

30
lib/widget/live/live_room_anchor_showcase.dart

@ -1,4 +1,5 @@
import 'package:agora_rtc_engine/agora_rtc_engine.dart'; import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dating_touchme_app/controller/discover/room_controller.dart'; import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/controller/global.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:dating_touchme_app/extension/ex_widget.dart';
@ -229,7 +230,19 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
child: SizedBox( child: SizedBox(
width: 177.w, width: 177.w,
height: 175.w, height: 175.w,
child: _roomController.currentRole == CurrentRole.broadcaster
child: _roomController.closeBoss.value ? CachedNetworkImage(
imageUrl: "${_roomController.rtcChannelDetail.value?.anchorInfo?.profilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_120",
width: 177.w,
height: 175.w,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
) : _roomController.currentRole == CurrentRole.broadcaster
? AgoraVideoView( ? AgoraVideoView(
controller: VideoViewController( controller: VideoViewController(
rtcEngine: engine, rtcEngine: engine,
@ -300,7 +313,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
(_rtcManager.currentChannelId != null && _rtcManager.currentChannelId!.isNotEmpty) (_rtcManager.currentChannelId != null && _rtcManager.currentChannelId!.isNotEmpty)
? Stack( ? Stack(
children: [ children: [
AgoraVideoView(
if((isLeft && !_roomController.closeMale.value) || (!isLeft && !_roomController.closeFemale.value))AgoraVideoView(
controller: isCurrentUser controller: isCurrentUser
? VideoViewController( ? VideoViewController(
rtcEngine: engine, rtcEngine: engine,
@ -314,6 +327,19 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
), ),
), ),
), ),
if((isLeft && _roomController.closeMale.value) || (!isLeft && _roomController.closeFemale.value)) CachedNetworkImage(
imageUrl: "${userInfo.profilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_120",
width: 177.w,
height: 175.w,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
),
if(!isCurrentUser) if(!isCurrentUser)
Positioned( Positioned(
top: 5.w, top: 5.w,

Loading…
Cancel
Save