优化声网token刷新逻辑

This commit is contained in:
fuenmao 2025-01-08 09:55:56 +08:00
parent a019645104
commit bc3b05403d
1 changed files with 49 additions and 35 deletions

View File

@ -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) {
// 15signalR 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) {
// 15signalR 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<void> switchCamera() async {
await state.rctEngine.value?.switchCamera();
}
/// Token
Future<void> renewToken(String token) async {
await state.rctEngine.value?.renewToken(token);
}
}