|
|
|
@ -1,11 +1,24 @@ |
|
|
|
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/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/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:get/get.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 '../../network/home_api.dart'; |
|
|
|
import '../../model/home/marriage_data.dart'; |
|
|
|
@ -66,12 +79,256 @@ class HomeController extends GetxController { |
|
|
|
|
|
|
|
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 |
|
|
|
void onClose() { |
|
|
|
super.onClose(); |
|
|
|
_timer?.cancel(); |
|
|
|
sseClient.close(connectionId: "connectionId"); |
|
|
|
} |
|
|
|
|
|
|
|
getFriendFootprintInfo() async { |
|
|
|
|