diff --git a/wgshare/lib/common/config/request_config.dart b/wgshare/lib/common/config/request_config.dart index 687f419..ba1117d 100644 --- a/wgshare/lib/common/config/request_config.dart +++ b/wgshare/lib/common/config/request_config.dart @@ -5,7 +5,7 @@ class RequestConfig { // static const _devBaseUrl = "https://zyapitest.23544.com:16440"; // 开发 static const _devBaseUrl = "http://192.168.2.9:5192"; // 开发 // static const _proBaseUrl = "http://192.168.2.119:1091"; // 生产 - static const _proBaseUrl = "https://zyapi.23544.com/ipadapi"; // 生产 + static const _proBaseUrl = "http://192.168.2.9:5192"; // 生产 static const imgUrl = 'https://dpc-job-oss.23544.com/'; static RequestConfig? _instance; diff --git a/wgshare/lib/common/request/rest_dio.dart b/wgshare/lib/common/request/rest_dio.dart index 43c3cb7..66c78b6 100644 --- a/wgshare/lib/common/request/rest_dio.dart +++ b/wgshare/lib/common/request/rest_dio.dart @@ -6,6 +6,8 @@ import 'package:dio/dio.dart'; import 'package:wgshare/common/api/retrofit_client.dart'; import 'package:wgshare/common/config/request_config.dart'; import 'package:wgshare/common/store/user_store.dart'; +import 'package:wgshare/utils/anti_shake_throttling.dart'; +import 'package:wgshare/utils/routeUtil.dart'; import 'package:wgshare/utils/storage.dart'; import 'package:wgshare/utils/toast_utils.dart'; import 'package:wgshare/routes/app_routes.dart'; @@ -111,9 +113,9 @@ class ResponseHandle extends Interceptor { ((data['code'] != null && (data['code'] == 401 || data['code'] == '401')) || (data['Code'] != null && (data['Code'] == 401 || data['Code'] == '401'))); - if (statusCode == 401 || flag) { - Future.delayed(const Duration(seconds: 2), () { - StorageService.to.erase(); + if ((statusCode == 401 || flag) && RouteUtil.getRoute() != Routes.loginPage) { + easyThrottle("toLogin",(){ + UserStore.to.erase(); getx.Get.offAllNamed(Routes.loginPage); }); } @@ -163,12 +165,12 @@ class TheError extends Interceptor { switch (statusCode) { case 401: message = '用户登录失效,请重新登录'; - - Future.delayed(const Duration(seconds: 2), () { - // UserStore.to.erase(); - StorageService.to.erase(); - getx.Get.offAllNamed(Routes.loginPage); - }); + if(RouteUtil.getRoute() != Routes.loginPage){ + easyThrottle("toLogin",(){ + UserStore.to.erase(); + getx.Get.offAllNamed(Routes.loginPage); + }); + } break; case 404: message = '无效地址'; diff --git a/wgshare/lib/pages/homePage/home_logic.dart b/wgshare/lib/pages/homePage/home_logic.dart index 55cbad0..a54fb71 100644 --- a/wgshare/lib/pages/homePage/home_logic.dart +++ b/wgshare/lib/pages/homePage/home_logic.dart @@ -134,6 +134,7 @@ class HomeLogic extends GetxController with RequestToolMixin { leftBtnStr: '拒绝', rightBtnStr: '同意', leftBtnCallback: () { + Get.back(); Get.toNamed(Routes.meetingMainPage, arguments: { "roomNumber": state.meetingRooms.value[index].roomNum @@ -142,6 +143,7 @@ class HomeLogic extends GetxController with RequestToolMixin { rightBtnCallback: () { PermissionService.requestPermissions().then((value) { if (value == true) { + Get.back(); Get.toNamed(Routes.meetingMainPage, arguments: { "roomNumber": state.meetingRooms.value[index].roomNum diff --git a/wgshare/lib/pages/loginPage/login_logic.dart b/wgshare/lib/pages/loginPage/login_logic.dart index cb4980a..c41e396 100644 --- a/wgshare/lib/pages/loginPage/login_logic.dart +++ b/wgshare/lib/pages/loginPage/login_logic.dart @@ -20,22 +20,22 @@ import '../../view/upgrade/loadJson/load_network_json.dart'; import 'login_state.dart'; class LoginLogic extends GetxController with RequestToolMixin { - final LoginState state = LoginState(); + late LoginState state; @override void onInit() { - super.onInit(); + print("初始化登录init................"); + state = LoginState(); HideCheckVersion hideCheckVersion = HideCheckVersion(); hideCheckVersion.doHttpHideCheckVersion(); + super.onInit(); } @override void onClose() { + print("销毁onClose................"); + super.onClose(); - state.passwordController.dispose(); - state.userNameController.dispose(); - state.meetingCodeController.dispose(); - state.nickNameCodeController.dispose(); } /// 改变页面状态 @@ -50,24 +50,24 @@ class LoginLogic extends GetxController with RequestToolMixin { /// 登录 Future doHttpLogin() async { - if(state.userNameController.text.isEmpty){ + if(state.userNameController!.text.isEmpty){ ToastUtils.showError("请输入账号"); - }else if(state.passwordController.text.isEmpty){ + }else if(state.passwordController!.text.isEmpty){ ToastUtils.showError("请输入密码"); }else if(state.checkAgreementBool.value != true){ ToastUtils.showError("请阅读并勾选相关协议"); }else{ - BaseStructureResult res = await getClient().login(state.userNameController.text, md5.convert(utf8.encode(state.passwordController.text)).toString()); + BaseStructureResult res = await getClient().login(state.userNameController!.text, md5.convert(utf8.encode(state.passwordController!.text)).toString()); if (null != res.data) { UserStore.to.setToken(res.data!.token); UserStore.to.setRefreshToken(res.data!.refreshToken); UserStore.to.setUserDetailInfo(res.data!); UserStore.to.setLoginType(AppConfig.NORMAL_LOGIN); Get.offAllNamed(Routes.startPage); - state.userNameController.text = ""; - state.passwordController.text = ""; - state.meetingCodeController.text = ""; - state.nickNameCodeController.text = ""; + state.userNameController!.text = ""; + state.passwordController!.text = ""; + state.meetingCodeController!.text = ""; + state.nickNameCodeController!.text = ""; state.checkAgreementBool.value = false; } } @@ -75,26 +75,26 @@ class LoginLogic extends GetxController with RequestToolMixin { /// 直接进入会议(匿名登录) Future doHttpAnonymousLogin() async { - if(state.meetingCodeController.text.isEmpty){ + if(state.meetingCodeController!.text.isEmpty){ ToastUtils.showError("请输入会议号"); - }else if(state.meetingCodeController.text.length != 8){ + }else if(state.meetingCodeController!.text.length != 8){ ToastUtils.showError("请输入正确的会议号"); - }else if(state.nickNameCodeController.text.isEmpty){ + }else if(state.nickNameCodeController!.text.isEmpty){ ToastUtils.showError("请输入昵称"); }else if(state.checkAgreementBool != true){ ToastUtils.showError("请阅读并勾选相关协议"); }else{ - BaseStructureResult res = await getClient().anonLogin(await DeviceInfo.getDeviceId(),state.nickNameCodeController.text, state.meetingCodeController.text); + BaseStructureResult res = await getClient().anonLogin(await DeviceInfo.getDeviceId(),state.nickNameCodeController!.text, state.meetingCodeController!.text); if (null != res.data) { UserStore.to.setToken(res.data!.token); UserStore.to.setRefreshToken(res.data!.refreshToken); UserStore.to.setUserDetailInfo(res.data!); UserStore.to.setLoginType(AppConfig.ANONYMOUS_LOGIN); - Get.toNamed(Routes.meetingMainPage, arguments: {"roomNumber": state.meetingCodeController.text}); - state.userNameController.text = ""; - state.passwordController.text = ""; - state.meetingCodeController.text = ""; - state.nickNameCodeController.text = ""; + Get.toNamed(Routes.meetingMainPage, arguments: {"roomNumber": state.meetingCodeController!.text}); + state.userNameController!.text = ""; + state.passwordController!.text = ""; + state.meetingCodeController!.text = ""; + state.nickNameCodeController!.text = ""; state.checkAgreementBool.value = false; } } @@ -102,16 +102,16 @@ class LoginLogic extends GetxController with RequestToolMixin { /// 检验房间 Future doHttpCheckMeetingRoom() async { - if(state.meetingCodeController.text.isEmpty){ + if(state.meetingCodeController!.text.isEmpty){ ToastUtils.showError("请输入会议号"); - }else if(state.meetingCodeController.text.length != 8){ + }else if(state.meetingCodeController!.text.length != 8){ ToastUtils.showError("请输入正确的会议号"); - }else if(state.nickNameCodeController.text.isEmpty){ + }else if(state.nickNameCodeController!.text.isEmpty){ ToastUtils.showError("请输入昵称"); }else if(state.checkAgreementBool != true){ ToastUtils.showError("请阅读并勾选相关协议"); }else{ - BaseStructureResult res = await getClient().checkout(state.meetingCodeController.text); + BaseStructureResult res = await getClient().checkout(state.meetingCodeController!.text); if (null != res.data) { if(res.data == true){ doHttpAnonymousLogin(); diff --git a/wgshare/lib/pages/loginPage/login_state.dart b/wgshare/lib/pages/loginPage/login_state.dart index 0c0b47b..195cf7b 100644 --- a/wgshare/lib/pages/loginPage/login_state.dart +++ b/wgshare/lib/pages/loginPage/login_state.dart @@ -3,12 +3,14 @@ import 'package:get/get.dart'; class LoginState { - LoginState() {} + TextEditingController? userNameController; + TextEditingController? passwordController; + TextEditingController? meetingCodeController; + TextEditingController? nickNameCodeController; + LoginState() { + + } - late TextEditingController userNameController = TextEditingController(); - late TextEditingController passwordController = TextEditingController(); - late TextEditingController meetingCodeController = TextEditingController(); - late TextEditingController nickNameCodeController = TextEditingController(); /// 页面状态,0:账号,1:会议号 late RxInt pageState = 0.obs; diff --git a/wgshare/lib/pages/loginPage/login_view.dart b/wgshare/lib/pages/loginPage/login_view.dart index 5895080..d16259e 100644 --- a/wgshare/lib/pages/loginPage/login_view.dart +++ b/wgshare/lib/pages/loginPage/login_view.dart @@ -23,6 +23,10 @@ class _LoginPageState extends State { @override void initState() { Utils.hideKeyboard(); + state.userNameController = TextEditingController(); + state.passwordController = TextEditingController(); + state.meetingCodeController = TextEditingController(); + state.nickNameCodeController = TextEditingController(); super.initState(); } @@ -394,4 +398,13 @@ class _LoginPageState extends State { ), ); } + + @override + void dispose() { + state.passwordController?.dispose(); + state.userNameController?.dispose(); + state.meetingCodeController?.dispose(); + state.nickNameCodeController?.dispose(); + super.dispose(); + } } diff --git a/wgshare/lib/pages/metting/meeting_main_logic.dart b/wgshare/lib/pages/metting/meeting_main_logic.dart index a80a221..db8daa6 100644 --- a/wgshare/lib/pages/metting/meeting_main_logic.dart +++ b/wgshare/lib/pages/metting/meeting_main_logic.dart @@ -64,9 +64,9 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { await getClient().getMeetingToken(state.roomNumber.value); state.meetingToken.value = res.data!; - if (isInit == true) { + if (isInit) { signalRSocket(); - }else{ + } else { initRtc(); } } @@ -89,6 +89,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { getMeetingRoomAllUser(results[1].data as List); } finally { ToastUtils.dismiss(); + ToastUtils.showSuccess("${state.isJoinSuccess}--${state.rctEngine.value}--${state.users.isNotEmpty}"); } } @@ -162,15 +163,17 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { } /// 点击grid切换大屏 - void checkLargeScreen(String uid){ + void checkLargeScreen(String uid) { ToastUtils.showSuccess("切换用户成功"); - if(uid == UserStore.to.userInfoEntity.value!.uid) { + if (uid == UserStore.to.userInfoEntity.value!.uid) { state.remoteUid.value = "0"; - }else{ - if(state.isSpeak.value == true && state.isOpenCamera.value == true){ + state.remoteAssistantUid.value = "0"; + } else { + if (state.isSpeak.value == true && state.isOpenCamera.value == true) { state.floating.value?.open(Get.context!); } state.remoteUid.value = uid; + state.remoteAssistantUid.value = uid; } changePageState(0); Future.delayed(const Duration(milliseconds: 200), () { @@ -208,7 +211,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { /// ------------------------------------------------------------------------------麦克风相关(操作) /// 用户开闭麦 Future doHttpSetMicr(bool isOpenMicrophone) async { - if(isOpenMicrophone == false){ + if (isOpenMicrophone == false) { state.spokesman.value = ""; state.spokesmanVolume.value = 0; } @@ -257,9 +260,9 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { isOtherOpenCamera = true; } } - if(isOtherOpenCamera == false){ + if (isOtherOpenCamera == false) { changePageState(0); - }else{ + } else { state.remoteUid.value = ""; changePageState(1); } @@ -270,7 +273,8 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { // 判断当前会议室是否存在全员观看主播 var isCurrentUserIsCamera = false; for (var i = 0; i < state.cacheUsers.value.length; i++) { - if (state.remoteUid.value == state.cacheUsers.value[i].uid && state.cacheUsers.value[i].enableCamera == true) { + if (state.remoteUid.value == state.cacheUsers.value[i].uid && + state.cacheUsers.value[i].enableCamera == true) { isCurrentUserIsCamera = true; } } @@ -398,11 +402,21 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { debugPrint("wgs输出===:SignalR Socket-重连失败$error"); ToastUtils.dismiss(); - if ((state.isNormaExit.value == false && state.isShowOkAlertDialog.value == false) || null == UserStore.to.userInfoEntity.value) { + debugPrint( + "wgs输出===:SignalR Socket-重连打印1${state.isNormaExit.value == false && state.isShowOkAlertDialog.value == false}"); + debugPrint("wgs输出===:SignalR Socket-重连打印2${null != UserStore.to.token}"); + debugPrint( + "wgs输出===:SignalR Socket-重连打印3${UserStore.to.token!.isNotEmpty}"); + debugPrint( + "wgs输出===:SignalR Socket-重连打印4${(state.isNormaExit.value == false && state.isShowOkAlertDialog.value == false) || null != UserStore.to.token || UserStore.to.token!.isNotEmpty}"); + + if ((state.isNormaExit.value == false && + state.isShowOkAlertDialog.value == false) || + (state.isNormaExit.value == false && null != UserStore.to.token)) { showOkAlertDialog( context: Get.context!, title: "提示", - message: "网络错误,请重新加入会议室", + message: "网络错误,请重新加入会议室1", okLabel: "确定", barrierDismissible: false, ).then((OkCancelResult value) { @@ -426,7 +440,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { for (MeetingRoomUser mru in state.cacheUsers.value) { if (mru.uid == meetingRoomUser.uid) { mru.roleId = meetingRoomUser.roleId; - if(state.defaulOpenState.value == 1){ + if (state.defaulOpenState.value == 1) { mru.enableMicr = true; } mru.isRoomManager = meetingRoomUser.isRoomManager; @@ -571,7 +585,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { } state.users.value = state.cacheUsers.value; update(); - if(listDynamic[0] != UserStore.to.userInfoEntity.value!.uid){ + if (listDynamic[0] != UserStore.to.userInfoEntity.value!.uid) { doHttpGetTvAnchor(); } debugPrint("wgs输出===:Socket-远端用户或主播离开会议室:$jsonStr"); @@ -648,8 +662,9 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { if (mru.uid == meetingRoomUser.uid) { mru.enableCamera = true; } - debugPrint("wgs输出===:Socket-用户单独开摄像头---${state.remoteUid.value}--${meetingRoomUser.uid}"); - if(state.remoteUid.value == meetingRoomUser.uid){ + debugPrint( + "wgs输出===:Socket-用户单独开摄像头---${state.remoteUid.value}--${meetingRoomUser.uid}"); + if (state.remoteUid.value == meetingRoomUser.uid) { doHttpGetTvAnchor(); } } @@ -687,14 +702,15 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { muteLocalVideoStream(true); // 停止本地预览 stopPreview(); - // 当前全员观看主播是自己时 - if (state.remoteUid.value == "0") { - state.remoteUid.value = ""; - } // 关闭本地预览悬浮窗 if (state.floating.value?.isShowing == true) { state.floating.value?.close(); } + // 当前全员观看主播是自己时 + if (state.remoteUid.value == "0") { + state.remoteUid.value = ""; + doHttpGetTvAnchor(); + } } } update(); @@ -713,8 +729,12 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { /// 加入会议室 /// isAgain:是否重新加入 Future joinMeetingToSocket(bool isAgain) async { - await state.hubConnection.value?.invoke("joinChannel", - args: [state.roomNumber.value, state.isOpenMicrophone.value, state.isOpenCamera.value, state.isSpeak.value]); + await state.hubConnection.value?.invoke("joinChannel", args: [ + state.roomNumber.value, + state.isOpenMicrophone.value, + state.isOpenCamera.value, + state.isSpeak.value + ]); mergeFetch(isAgain); /*if(isAgain == false){ mergeFetch(isAgain); @@ -765,7 +785,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { // 音频模块默认启动,所以这里不再调用启动方法 // 启用视频模块 - enableVideo(); + await enableVideo(); // 设置默认音频路由为听筒 await state.rctEngine.value?.setDefaultAudioRouteToSpeakerphone(false); // 打开用户音量回调 @@ -775,61 +795,59 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { await state.rctEngine.value ?.setDualStreamMode(mode: SimulcastStreamMode.enableSimulcastStream); - joinMeetingToRtc(); - // 回调 state.rctEngine.value?.registerEventHandler( RtcEngineEventHandler( // 成功加入会议室回调 onJoinChannelSuccess: (RtcConnection connection, int elapsed) { state.isJoinSuccess.value = true; - debugPrint("wgs输出===:RTC-自己加入会议室,ID:${connection.localUid}"); - }, + debugPrint("wgs输出===:RTC-自己加入会议室,ID:${connection.localUid}"); + }, // 成功离开会议室回调 onLeaveChannel: (RtcConnection connection, RtcStats stats) { - debugPrint("wgs输出===:RTC-自己离开会议室,ID:${connection.localUid}"); - }, + debugPrint("wgs输出===:RTC-自己离开会议室,ID:${connection.localUid}"); + }, // 远端用户或主播加入当前会议室回调-主播角色才能接收该回调 onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) { - debugPrint("wgs输出===:RTC-远端用户或主播加入会议室,用户或主机的ID:$remoteUid"); - }, + debugPrint("wgs输出===:RTC-远端用户或主播加入会议室,用户或主机的ID:$remoteUid"); + }, // 远端用户或主播离开当前会议室回调-主播角色才能接收该回调 onUserOffline: (RtcConnection connection, int remoteUid, UserOfflineReasonType reason) async { - // 判断是否用户取消了共享 - if (remoteUid.toString().length == 9) { - for (var i = 0; i < state.cacheUsers.value.length; i++) { - if (remoteUid.toString() == - state.cacheUsers.value[i].screenShareId) { - state.cacheUsers.value[i].enableShare = false; + // 判断是否用户取消了共享 + if (remoteUid.toString().length == 9) { + for (var i = 0; i < state.cacheUsers.value.length; i++) { + if (remoteUid.toString() == + state.cacheUsers.value[i].screenShareId) { + state.cacheUsers.value[i].enableShare = false; + } + } } - } - } - update(); - debugPrint("wgs输出===:RTC-远端用户或主播离开会议室,用户或主机的ID:$remoteUid"); - }, + update(); + debugPrint("wgs输出===:RTC-远端用户或主播离开会议室,用户或主机的ID:$remoteUid"); + }, // 音频路由发生变化回调 onAudioRoutingChanged: (int routing) { - debugPrint("wgs输出===:RTC-音频路由切换:$routing"); - state.communicationMode.value = routing; - if (routing == 1) { - debugPrint("wgs输出===:RTC-音频路由切换为听筒"); - } else if (routing == 3) { - debugPrint("wgs输出===:RTC-音频路由切换为扬声器"); - } else { - debugPrint("wgs输出===:RTC-音频路由切换为外接设备"); - } - }, + debugPrint("wgs输出===:RTC-音频路由切换:$routing"); + state.communicationMode.value = routing; + if (routing == 1) { + debugPrint("wgs输出===:RTC-音频路由切换为听筒"); + } else if (routing == 3) { + debugPrint("wgs输出===:RTC-音频路由切换为扬声器"); + } else { + debugPrint("wgs输出===:RTC-音频路由切换为外接设备"); + } + }, // 音频采集开关回调 onLocalAudioStateChanged: (RtcConnection connection, LocalAudioStreamState state, LocalAudioStreamReason reason) { - debugPrint("wgs输出===:RTC-音频采集开关:$state"); - }, + debugPrint("wgs输出===:RTC-音频采集开关:$state"); + }, // 远端视频状态发生改变回调 onRemoteVideoStateChanged: (RtcConnection connection, @@ -837,56 +855,55 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { RemoteVideoState remoteVideoState, RemoteVideoStateReason remoteVideoStateReason, int elapsed) { - debugPrint( - "wgs输出===:RTC-远端视频状态发生改变:ID-$remoteUid-状态-$remoteVideoStateReason"); - if (remoteVideoStateReason == - RemoteVideoStateReason.remoteVideoStateReasonRemoteMuted) { - // 远端用户停止发送视频流或远端用户禁用视频模块 - if (remoteUid.toString().length != 9) { - // 摄像头 - if (remoteUid.toString() == state.remoteUid.value) { - // 如果停止发送视频流或禁用视频模块的远端用户是当前全员观看主播 - doHttpGetTvAnchor(); + debugPrint( + "wgs输出===:RTC-远端视频状态发生改变:ID-$remoteUid-状态-$remoteVideoStateReason"); + if (remoteVideoStateReason == + RemoteVideoStateReason.remoteVideoStateReasonRemoteMuted) { + // 远端用户停止发送视频流或远端用户禁用视频模块 + if (remoteUid.toString().length != 9) { + // 摄像头 + if (remoteUid.toString() == state.remoteUid.value) { + // 如果停止发送视频流或禁用视频模块的远端用户是当前全员观看主播 + doHttpGetTvAnchor(); + } + } else { + // 共享屏幕(此版本不做) + } } - } else { - // 共享屏幕(此版本不做) - } - } - }, + }, // 用户音量提示回调 onAudioVolumeIndication: (RtcConnection connection, List speakers, int speakerNumber, int totalVolume) { - if (speakers.isNotEmpty) { - - for (AudioVolumeInfo avi in speakers) { - if(avi.uid == 0){ - debugPrint("wgs输出===:RTC-本地用户音量提示:${avi.uid}--${avi.volume}"); - for(MeetingRoomUser mru in state.cacheUsers.value){ - if(UserStore.to.userInfoEntity.value!.uid == mru.uid){ - mru.volume = CountMicrophoneVolume.getVolume(avi.volume!); - state.microphoneVolume.value = - CountMicrophoneVolume.getVolume(avi.volume!); - } - } - }else{ - debugPrint("wgs输出===:RTC-远端用户音量提示:${avi.uid}--${avi.volume}"); - for(MeetingRoomUser mru in state.cacheUsers.value){ - mru.volume = CountMicrophoneVolume.getVolume(avi.volume!); - - if (avi.volume != 0) { - state.spokesman.value = mru.userName; - state.spokesmanVolume.value = - CountMicrophoneVolume.getVolume(avi.volume!); + if (speakers.isNotEmpty) { + for (AudioVolumeInfo avi in speakers) { + if (avi.uid == 0) { + // debugPrint("wgs输出===:RTC-本地用户音量提示:${avi.uid}--${avi.volume}"); + for (MeetingRoomUser mru in state.cacheUsers.value) { + if (UserStore.to.userInfoEntity.value!.uid == mru.uid) { + mru.volume = CountMicrophoneVolume.getVolume(avi.volume!); + state.microphoneVolume.value = + CountMicrophoneVolume.getVolume(avi.volume!); + } + } } else { - state.spokesman.value = ""; - state.spokesmanVolume.value = 0; + // debugPrint("wgs输出===:RTC-远端用户音量提示:${avi.uid}--${avi.volume}"); + for (MeetingRoomUser mru in state.cacheUsers.value) { + mru.volume = CountMicrophoneVolume.getVolume(avi.volume!); + + if (avi.volume != 0) { + state.spokesman.value = mru.userName; + state.spokesmanVolume.value = + CountMicrophoneVolume.getVolume(avi.volume!); + } else { + state.spokesman.value = ""; + state.spokesmanVolume.value = 0; + } + } } - } - } - /*for (MeetingRoomUser mru in state.cacheUsers.value) { + /*for (MeetingRoomUser mru in state.cacheUsers.value) { // 用于更改语音布局里的用户列表麦克风 if (avi.uid == 0) { // debugPrint("wgs输出===:RTC-用户音量提示(自己):${CountMicrophoneVolume.getVolume(avi.volume!)}"); @@ -910,70 +927,87 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { } } }*/ - } - } - }, + } + } + }, // 切换用户角色回调 onClientRoleChanged: (RtcConnection connection, ClientRoleType oldRole, ClientRoleType newRole, ClientRoleOptions newRoleOptions) { - debugPrint( - "wgs输出===:RTC-切换用户角色为:${newRole == ClientRoleType.clientRoleBroadcaster ? "主播" : "观众"}"); - }, + debugPrint( + "wgs输出===:RTC-切换用户角色为:${newRole == ClientRoleType.clientRoleBroadcaster ? "主播" : "观众"}"); + }, // token即将在30秒内过期回调 onTokenPrivilegeWillExpire: (RtcConnection connection, String token) { - doHttpGetMeetingToken(false); - }, + doHttpGetMeetingToken(false); + }, // 本地视频状态发生改变回调 onLocalVideoStateChanged: (VideoSourceType source, LocalVideoStreamState state, LocalVideoStreamReason reason) { - debugPrint("wgs输出===:RTC-本地视频状态发生改变:$source--$state--$reason"); - }, + debugPrint("wgs输出===:RTC-本地视频状态发生改变:$source--$state--$reason"); + }, // 网络连接状态回调 onConnectionStateChanged: (RtcConnection connection, ConnectionStateType stateType, ConnectionChangedReasonType reason) { - debugPrint("wgs输出===:RTC-网络连接状态发生改变:" - "会议室编号(${connection.channelId})," - "网络状态($stateType-${AgoraUtil.getConnectionStateChangedType(stateType)})," - "网络改变原因($reason-${AgoraUtil.getConnectionChangedReasonType(reason)})"); - if (stateType == ConnectionStateType.connectionStateReconnecting) { - if (EasyLoading.isShow == false) { - ToastUtils.showLoadingToMask( - "网络故障,正在重连...", EasyLoadingMaskType.black); - } - } else if (stateType == ConnectionStateType.connectionStateConnected && - reason == - ConnectionChangedReasonType.connectionChangedRejoinSuccess) { - ToastUtils.dismiss(); - if (EasyLoading.isShow == false) { - ToastUtils.showSuccessToMask("重连成功!", EasyLoadingMaskType.black); - } - } else if (reason == - ConnectionChangedReasonType.connectionChangedLost) { - // 和服务器失去连接后,再延迟15秒(和signalR Socket一致),让SDK继续重连,如果重连不上则告知用户需要重新加入 - Future.delayed(const Duration(milliseconds: 15000), () { - ToastUtils.dismiss(); - if (state.isShowOkAlertDialog.value == false) { - showOkAlertDialog( - context: Get.context!, - title: "提示", - message: "网络错误,请重新加入会议室", - okLabel: "确定", - barrierDismissible: false, - ).then((OkCancelResult value) { - Get.back(); - Get.back(); + debugPrint("wgs输出===:RTC-网络连接状态发生改变:" + "会议室编号(${connection.channelId})," + "网络状态($stateType-${AgoraUtil.getConnectionStateChangedType(stateType)})," + "网络改变原因($reason-${AgoraUtil.getConnectionChangedReasonType(reason)})"); + if (stateType == ConnectionStateType.connectionStateReconnecting) { + if (EasyLoading.isShow == false) { + ToastUtils.showLoadingToMask( + "网络故障,正在重连...", EasyLoadingMaskType.black); + } + } else if (stateType == + ConnectionStateType.connectionStateConnected && + reason == + ConnectionChangedReasonType + .connectionChangedRejoinSuccess) { + ToastUtils.dismiss(); + if (EasyLoading.isShow == false) { + ToastUtils.showSuccessToMask( + "重连成功!", EasyLoadingMaskType.black); + } + } else if (reason == + ConnectionChangedReasonType.connectionChangedLost) { + // 和服务器失去连接后,再延迟15秒(和signalR Socket一致),让SDK继续重连,如果重连不上则告知用户需要重新加入 + Future.delayed(const Duration(milliseconds: 15000), () { + ToastUtils.dismiss(); + if (state.isShowOkAlertDialog.value == false) { + showOkAlertDialog( + context: Get.context!, + title: "提示", + message: "网络错误,请重新加入会议室", + okLabel: "确定", + barrierDismissible: false, + ).then((OkCancelResult value) { + Get.back(); + Get.back(); + }); + } }); } - }); - } - } + }, + + // 渲染器已接收首帧远端视频回调 + onFirstRemoteVideoFrame: (RtcConnection connection, int remoteUid, + int width, int height, int elapsed) async { + debugPrint("wgs输出===:RTC-渲染器已接收首帧远端视频回调:${remoteUid}--${width}--${height}--${elapsed}"); + + + }, + + // 已接收到远端视频并完成解码回调 + onFirstRemoteVideoDecoded: (RtcConnection connection, int remoteUid, + int width, int height, int elapsed) { + debugPrint("wgs输出===:RTC-已接收到远端视频并完成解码回调:${remoteUid}--${width}--${height}--${elapsed}"); + } // 获取设备权限出错回调 /*onPermissionError: (PermissionType permissionType){ @@ -986,6 +1020,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { }*/ ), ); + await joinMeetingToRtc(); } /// 加入会议室 diff --git a/wgshare/lib/pages/metting/meeting_main_state.dart b/wgshare/lib/pages/metting/meeting_main_state.dart index bdfd7b9..e41538b 100644 --- a/wgshare/lib/pages/metting/meeting_main_state.dart +++ b/wgshare/lib/pages/metting/meeting_main_state.dart @@ -101,7 +101,7 @@ class MeetingMainState { /// 声网相关 final String appId = "4a4f7be64fa1404ebda74784fe9ac381"; - late Rx rctEngine = Rx(null); + Rx rctEngine = Rx(null); /// 是否自动订阅所有视频流 late RxBool isAutoSubscribeVideo = false.obs; /// 是否自动订阅所有音频流 diff --git a/wgshare/lib/pages/metting/meeting_main_view.dart b/wgshare/lib/pages/metting/meeting_main_view.dart index 4cdb332..57a05f6 100644 --- a/wgshare/lib/pages/metting/meeting_main_view.dart +++ b/wgshare/lib/pages/metting/meeting_main_view.dart @@ -222,8 +222,7 @@ class MeetingMainPageState extends State { visible: state.pageState.value == 1, child: state.isJoinSuccess.value == true && null != state.rctEngine.value && - null != state.users.value && - state.users.value.isNotEmpty + state.users.isNotEmpty ? Stack( alignment: Alignment.center, children: [ @@ -305,7 +304,7 @@ class MeetingMainPageState extends State { ], ) : Container( - color: ColorUtil.Color_57_57_57, + color: Colors.red, /*child: Text('加载反馈:是否成功加入会议室${state.isJoinSuccess.value}-会议室对象${state.rctEngine.value}-成员列表${state.users.value.length}-全员观看ID${state.remoteUid.value}'),*/ )),