From bc3b05403d8c2758f8e5088519507c059563ace8 Mon Sep 17 00:00:00 2001 From: fuenmao <980740792@qq.com> Date: Wed, 8 Jan 2025 09:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A3=B0=E7=BD=91token?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/pages/metting/meeting_main_logic.dart | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/wgshare/lib/pages/metting/meeting_main_logic.dart b/wgshare/lib/pages/metting/meeting_main_logic.dart index 5a38319..66d2857 100644 --- a/wgshare/lib/pages/metting/meeting_main_logic.dart +++ b/wgshare/lib/pages/metting/meeting_main_logic.dart @@ -190,6 +190,11 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { doHttpGetMeetingToken(false); }, + // token已过期 + onRequestToken: (RtcConnection connection){ + doHttpGetMeetingToken(false); + }, + // 本地视频状态发生改变回调 onLocalVideoStateChanged: (VideoSourceType source, LocalVideoStreamState state, LocalVideoStreamReason reason) { @@ -204,39 +209,44 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { "会议室编号(${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(); - }); + if(reason == ConnectionChangedReasonType.connectionChangedTokenExpired){ + // 当前使用的token已过期 + doHttpGetMeetingToken(false); + }else{ + 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(); + }); + } + }); + } } }, @@ -244,8 +254,6 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { onFirstRemoteVideoFrame: (RtcConnection connection, int remoteUid, int width, int height, int elapsed) async { debugPrint("wgs输出===:RTC-渲染器已接收首帧远端视频回调:${remoteUid}--${width}--${height}--${elapsed}"); - - }, // 已接收到远端视频并完成解码回调 @@ -301,7 +309,8 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { if (isInit) { signalRSocket(); } else { - initRtc(); + renewToken(state.meetingToken.value); + // initRtc(); } } @@ -1122,4 +1131,9 @@ class MeetingMainLogic extends GetxController with RequestToolMixin { Future switchCamera() async { await state.rctEngine.value?.switchCamera(); } + + /// 更新 Token + Future renewToken(String token) async { + await state.rctEngine.value?.renewToken(token); + } }