Browse Source

优化

dev-2.0
王子贤 3 weeks ago
parent
commit
148dd2e895
4 changed files with 261 additions and 312 deletions
  1. 226
      lib/controller/discover/room_controller.dart
  2. 257
      lib/controller/home/home_controller.dart
  3. 2
      lib/pages/mine/my_wallet_page.dart
  4. 88
      lib/rtc/rtc_manager.dart

226
lib/controller/discover/room_controller.dart

@ -467,21 +467,6 @@ class RoomController extends GetxController with WidgetsBindingObserver {
} }
} }
final request = SSERequest(
requestType: RequestMethodType.get,
url: "${EnvConfig.mainBaseUrl}dating-agency-sse/user/sse/connect",
headers: {
"Authorization": GetStorage().read('token'),
"'X-APP-ID'": '50325897884795885'
},
onData: (data) => print("Received: $data"),
onError: (error) => print("Error: $error"),
onDone: () => print("Stream closed"),
retry: true, // Enables automatic reconnection
);
final sseClient = SSEClient();
logout() async { logout() async {
// 退 // 退
if (Get.isRegistered<RoomController>()) { if (Get.isRegistered<RoomController>()) {
@ -522,7 +507,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
GlobalData().logout(); GlobalData().logout();
} }
final count = 3.obs;
/// RTC /// RTC
Future<void> createRtcChannel() async { Future<void> createRtcChannel() async {
if (isLive.value) { if (isLive.value) {
@ -565,214 +550,6 @@ class RoomController extends GetxController with WidgetsBindingObserver {
ClientRoleType.clientRoleBroadcaster, ClientRoleType.clientRoleBroadcaster,
); );
final Stream<SSEResponse> stream = sseClient.connect("connectionId", request);
stream.listen(
(SSEResponse response) {
print("sseData: ${response.rawResponse}");
String raw = response.rawResponse;
if (raw.startsWith("data:")) {
String result = raw.substring(5);
print(result);
Map<String, dynamic> data = jsonDecode(result);
print(data["data"]["illegalLabel"]);
if(data["data"]["illegalHandle"] == 1){
RTCManager.instance.publishAudio();
// overlay
if(!isDialogShowing.value){
SmartDialog.dismiss();
setDialogDismiss(true);
SmartDialog.show(
onDismiss: (){
setDialogDismiss(false);
},
builder: (context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
child: Material(
color: Colors.white,
child: Container(
width: 311.w,
height: 275.w,
padding: EdgeInsets.only(
top: 25.w,
right: 25.w,
left: 25.w
),
child: Column(
children: [
Image.asset(
Assets.imagesLiveErrorIcon,
width: 102.w,
height: 102.w,
),
SizedBox(height: 5.w,),
Text(
"系统提醒",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.w,
fontWeight: FontWeight.w700
),
),
SizedBox(height: 7.w,),
Text(
"你的行为涉嫌违反平台社区规范,请注意规范言行。多次违规将会受到限制功能、封禁账号等处罚,请文明交友,理性互动。",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
),
SizedBox(height: 14.w,),
Container(
width: 188.w,
height: 40.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12.w)),
color: const Color.fromRGBO(117, 98, 249, 1)
),
child: Center(
child: Text(
"确认",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
),
),
).onTap(() {
// overlay
SmartDialog.dismiss();
setDialogDismiss(false);
})
],
),
),
),
);
},
);
}
} else if(data["data"]["illegalHandle"] == 2){
SmartDialog.dismiss();
setDialogDismiss(true);
Future.delayed(Duration(seconds: 3), () async {
SmartDialog.dismiss();
final isNotBroadcaster = currentRole != CurrentRole.broadcaster;
if (isNotBroadcaster) {
await leaveChannel();
// LiveChatMessageService
LiveChatMessageService.instance.handleEndLiveMessage();
logout();
Get.offAll(() => LoginPage());
} else {
if(isClose.value) return;
isClose.value = true;
await leaveChannel();
SmartDialog.dismiss();
if (Get.isRegistered<RoomController>()) {
final roomController = Get.find<RoomController>();
roomController.chatMessages.clear();
}
// pop Get.back()
final OverlayController _overlayController = Get.find<OverlayController>();
//
Future.delayed(const Duration(milliseconds: 200), () {
_overlayController.hide();
isClose.value = false;
});
logout();
Get.offAll(() => LoginPage());
}
});
Timer? _timer;
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
count.value --;
update();
// 👇
if (count.value == 0) {
print("满足条件,停止执行");
timer.cancel(); //
}
});
SmartDialog.show(
onDismiss: (){
setDialogDismiss(false);
_timer?.cancel();
},
builder: (context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
child: Material(
color: Colors.white,
child: Container(
width: 311.w,
height: 275.w,
padding: EdgeInsets.only(
top: 25.w,
right: 25.w,
left: 25.w
),
child: Column(
children: [
Image.asset(
Assets.imagesLiveErrorIcon,
width: 102.w,
height: 102.w,
),
SizedBox(height: 5.w,),
Text(
"账户封禁",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.w,
fontWeight: FontWeight.w700
),
),
SizedBox(height: 7.w,),
Text(
"你的账号因 涉嫌违规,已被封禁。",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
),
SizedBox(height: 14.w,),
Obx((){
return Text(
"${count.value}秒后返回到登录界面",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
);
}),
],
),
),
),
);
},
);
}
}
},
onError: (error) => print("SSE Error: $error"),
onDone: () => print("SSE Connection Closed"),
);
print("sse链接");
} else { } else {
final message = base.message.isNotEmpty ? base.message : '创建频道失败'; final message = base.message.isNotEmpty ? base.message : '创建频道失败';
SmartDialog.showToast(message); SmartDialog.showToast(message);
@ -1017,7 +794,6 @@ class RoomController extends GetxController with WidgetsBindingObserver {
channelName: channelId, channelName: channelId,
message: json.encode({'type': 'end_live'}), message: json.encode({'type': 'end_live'}),
); );
sseClient.close(connectionId: "connectionId");
} }
} }
} catch (e) { } catch (e) {

257
lib/controller/home/home_controller.dart

@ -1,11 +1,24 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:dating_touchme_app/config/env_config.dart';
import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/controller/overlay_controller.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart';
import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/generated/assets.dart';
import 'package:dating_touchme_app/pages/mine/login_page.dart';
import 'package:dating_touchme_app/rtc/rtc_manager.dart';
import 'package:dating_touchme_app/service/live_chat_message_service.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_http_sse/client/sse_client.dart';
import 'package:flutter_http_sse/enum/request_method_type_enum.dart';
import 'package:flutter_http_sse/model/sse_request.dart';
import 'package:flutter_http_sse/model/sse_response.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get_storage/get_storage.dart';
import 'package:location_plugin/location_plugin.dart'; import 'package:location_plugin/location_plugin.dart';
import '../../network/home_api.dart'; import '../../network/home_api.dart';
import '../../model/home/marriage_data.dart'; import '../../model/home/marriage_data.dart';
@ -66,12 +79,256 @@ class HomeController extends GetxController {
getFriendFootprintInfo(); getFriendFootprintInfo();
}); });
openSSE();
} }
final count = 3.obs;
final request = SSERequest(
requestType: RequestMethodType.get,
url: "${EnvConfig.mainBaseUrl}dating-agency-sse/user/sse/connect",
headers: {
"Authorization": GetStorage().read('token'),
"'X-APP-ID'": '50325897884795885'
},
onData: (data) => print("Received: $data"),
onError: (error) => print("Error: $error"),
onDone: () => print("Stream closed"),
retry: true, // Enables automatic reconnection
);
final sseClient = SSEClient();
openSSE() async {
final Stream<SSEResponse> stream = sseClient.connect("connectionId", request);
stream.listen(
(SSEResponse response) {
print("sseData: ${response.rawResponse}");
String raw = response.rawResponse;
if (raw.startsWith("data:")) {
String result = raw.substring(5);
print(result);
Map<String, dynamic> data = jsonDecode(result);
print(data["data"]["illegalLabel"]);
if (Get.isRegistered<RoomController>()) {
final roomController = Get.find<RoomController>();
if(data["data"]["illegalHandle"] == 1){
RTCManager.instance.publishAudio();
// overlay
if(!roomController.isDialogShowing.value){
SmartDialog.dismiss();
roomController.setDialogDismiss(true);
SmartDialog.show(
onDismiss: (){
roomController.setDialogDismiss(false);
},
builder: (context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
child: Material(
color: Colors.white,
child: Container(
width: 311.w,
height: 315.w,
padding: EdgeInsets.only(
top: 25.w,
right: 25.w,
left: 25.w
),
child: Column(
children: [
Image.asset(
Assets.imagesLiveErrorIcon,
width: 102.w,
height: 102.w,
),
SizedBox(height: 5.w,),
Text(
"系统提醒",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.w,
fontWeight: FontWeight.w700
),
),
SizedBox(height: 7.w,),
Text(
"你的行为涉嫌违反平台社区规范,请注意规范言行。多次违规将会受到限制功能、封禁账号等处罚,请文明交友,理性互动。",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
),
SizedBox(height: 14.w,),
Container(
width: 188.w,
height: 40.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12.w)),
color: const Color.fromRGBO(117, 98, 249, 1)
),
child: Center(
child: Text(
"确认",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
),
),
).onTap(() {
// overlay
SmartDialog.dismiss();
roomController.setDialogDismiss(false);
})
],
),
),
),
);
},
);
}
} else if(data["data"]["illegalHandle"] == 2){
SmartDialog.dismiss();
roomController.setDialogDismiss(true);
Future.delayed(Duration(seconds: 3), () async {
SmartDialog.dismiss();
final isNotBroadcaster = roomController.currentRole != CurrentRole.broadcaster;
if (isNotBroadcaster) {
await roomController.leaveChannel();
// LiveChatMessageService
LiveChatMessageService.instance.handleEndLiveMessage();
roomController.logout();
Get.offAll(() => LoginPage());
} else {
if(roomController.isClose.value) return;
roomController.isClose.value = true;
await roomController.leaveChannel();
SmartDialog.dismiss();
if (Get.isRegistered<RoomController>()) {
final roomController = Get.find<RoomController>();
roomController.chatMessages.clear();
}
// pop Get.back()
final OverlayController _overlayController = Get.find<OverlayController>();
//
Future.delayed(const Duration(milliseconds: 200), () {
_overlayController.hide();
roomController.isClose.value = false;
});
roomController.logout();
Get.offAll(() => LoginPage());
}
});
Timer? _timer;
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
count.value --;
update();
// 👇
if (count.value == 0) {
print("满足条件,停止执行");
timer.cancel(); //
}
});
SmartDialog.show(
onDismiss: (){
roomController.setDialogDismiss(false);
_timer?.cancel();
},
builder: (context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
child: Material(
color: Colors.white,
child: Container(
width: 311.w,
height: 275.w,
padding: EdgeInsets.only(
top: 25.w,
right: 25.w,
left: 25.w
),
child: Column(
children: [
Image.asset(
Assets.imagesLiveErrorIcon,
width: 102.w,
height: 102.w,
),
SizedBox(height: 5.w,),
Text(
"账户封禁",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.w,
fontWeight: FontWeight.w700
),
),
SizedBox(height: 7.w,),
Text(
"你的账号因 涉嫌违规,已被封禁。",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
),
SizedBox(height: 14.w,),
Obx((){
return Text(
"${count.value}秒后返回到登录界面",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
);
}),
],
),
),
),
);
},
);
}
}
}
},
onError: (error) {
print("SSE Error: $error");
sseClient.close(connectionId: "connectionId");
Future.delayed(Duration(seconds: 3), () async {
openSSE();
});
},
onDone: () => print("SSE Connection Closed"),
);
print("sse链接");
}
@override @override
void onClose() { void onClose() {
super.onClose(); super.onClose();
_timer?.cancel(); _timer?.cancel();
sseClient.close(connectionId: "connectionId");
} }
getFriendFootprintInfo() async { getFriendFootprintInfo() async {

2
lib/pages/mine/my_wallet_page.dart

@ -261,7 +261,7 @@ class MyWalletPage extends StatelessWidget {
width: 5.w, width: 5.w,
), ),
Text( Text(
"提现说明:收益到账后满 3 天方可申请提现,提现金额最低 50 ",
"提现说明:发起提现后1-7个工作日到账,提现最低金额50",
style: TextStyle( style: TextStyle(
fontSize: 9.w, fontSize: 9.w,
color: Colors.white color: Colors.white

88
lib/rtc/rtc_manager.dart

@ -370,91 +370,7 @@ class RTCManager {
List<int> vecDistance, List<int> vecDistance,
int numFaces){ int numFaces){
print("当前人脸数:$numFaces"); print("当前人脸数:$numFaces");
if (numFaces > 0) {
// 0
_zeroTimer?.cancel();
_zeroTimer = null;
} else {
// value == 0
//
if (_zeroTimer == null && !isShow) {
_zeroTimer = Timer(const Duration(minutes: 2), () {
isShow = true;
// overlay
SmartDialog.dismiss();
// RoomController
final roomController = Get.isRegistered<RoomController>()
? Get.find<RoomController>()
: Get.put(RoomController());
SmartDialog.show(
onDismiss: (){
isShow = false;
roomController.setDialogDismiss(false);
},
builder: (context) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
child: Material(
color: Colors.white,
child: Container(
width: 311.w,
height: 275.w,
padding: EdgeInsets.only(
top: 25.w,
right: 25.w,
left: 25.w
),
child: Column(
children: [
Image.asset(
Assets.imagesWarningIcon,
width: 102.w,
height: 102.w,
),
SizedBox(height: 12.w,),
Text(
"系统检测到您2分钟内没有露脸,请露脸直播。多次违规后,取消当日前面直播时长,并且关闭直播间。",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.w
),
),
SizedBox(height: 7.w,),
Container(
width: 188.w,
height: 40.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12.w)),
color: const Color.fromRGBO(117, 98, 249, 1)
),
child: Center(
child: Text(
"确认",
style: TextStyle(
fontSize: 14.w,
color: Colors.white
),
),
),
).onTap(() {
// overlay
SmartDialog.dismiss();
isShow = false;
roomController.setDialogDismiss(false);
})
],
),
),
),
);
},
);
});
}
}
}, },
onError: (ErrorCodeType err, String msg) { onError: (ErrorCodeType err, String msg) {
print('RTC Engine 错误:$err,消息:$msg'); print('RTC Engine 错误:$err,消息:$msg');
@ -611,7 +527,7 @@ class RTCManager {
); );
print('正在加入频道:$channelId,UID:$uid,类型:$rtcType'); print('正在加入频道:$channelId,UID:$uid,类型:$rtcType');
if (role == ClientRoleType.clientRoleBroadcaster) { if (role == ClientRoleType.clientRoleBroadcaster) {
await _engine?.enableFaceDetection(true);
// await _engine?.enableFaceDetection(true);
try{ try{
await _engine?.enableContentInspect( await _engine?.enableContentInspect(

Loading…
Cancel
Save