|
|
|
@ -1,8 +1,10 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
import 'package:agora_rtc_engine/agora_rtc_engine.dart'; |
|
|
|
import 'package:dating_touchme_app/config/env_config.dart'; |
|
|
|
import 'package:dating_touchme_app/controller/global.dart'; |
|
|
|
import 'package:dating_touchme_app/controller/message/conversation_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'; |
|
|
|
@ -17,6 +19,7 @@ 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'; |
|
|
|
import 'package:dating_touchme_app/pages/mine/edit_info_page.dart'; |
|
|
|
import 'package:dating_touchme_app/pages/mine/login_page.dart'; |
|
|
|
import 'package:dating_touchme_app/pages/setting/match_league_page.dart'; |
|
|
|
import 'package:dating_touchme_app/rtc/rtc_manager.dart'; |
|
|
|
import 'package:dating_touchme_app/rtc/rtm_manager.dart'; |
|
|
|
@ -479,6 +482,47 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
|
|
|
|
|
final sseClient = SSEClient(); |
|
|
|
|
|
|
|
logout() async { |
|
|
|
// 退出直播间 |
|
|
|
if (Get.isRegistered<RoomController>()) { |
|
|
|
try { |
|
|
|
final roomController = Get.find<RoomController>(); |
|
|
|
await roomController.leaveChannel(); |
|
|
|
} catch (e) { |
|
|
|
print('退出直播间失败: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 取消小窗口 |
|
|
|
if (Get.isRegistered<OverlayController>()) { |
|
|
|
try { |
|
|
|
final overlayController = Get.find<OverlayController>(); |
|
|
|
overlayController.hide(); // 隐藏直播房间小窗 |
|
|
|
overlayController.hideVideoCall(); // 隐藏视频通话小窗 |
|
|
|
} catch (e) { |
|
|
|
print('取消小窗口失败: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 先退出 IM 登录 |
|
|
|
if(IMManager.instance.isInitialized){ |
|
|
|
await IMManager.instance.logout(); |
|
|
|
} |
|
|
|
// 清除会话列表和用户信息缓存 |
|
|
|
if (Get.isRegistered<ConversationController>()) { |
|
|
|
final conversationController = Get.find<ConversationController>(); |
|
|
|
conversationController.clearConversations(); |
|
|
|
} |
|
|
|
// App清除本地存储,有待处理, |
|
|
|
// storage.erase(); |
|
|
|
GetStorage().remove('userId'); |
|
|
|
GetStorage().remove('token'); |
|
|
|
// storage.write('hasAgreedUserAgreement', true); |
|
|
|
// 清除全局数据 |
|
|
|
GlobalData().logout(); |
|
|
|
} |
|
|
|
|
|
|
|
final count = 3.obs; |
|
|
|
/// 调用接口创建 RTC 频道 |
|
|
|
Future<void> createRtcChannel() async { |
|
|
|
if (isLive.value) { |
|
|
|
@ -524,7 +568,206 @@ class RoomController extends GetxController with WidgetsBindingObserver { |
|
|
|
final Stream<SSEResponse> stream = sseClient.connect("connectionId", request); |
|
|
|
stream.listen( |
|
|
|
(SSEResponse response) { |
|
|
|
print("Received event: ${response.event}, data: ${response.data}"); |
|
|
|
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"), |
|
|
|
|