优化声网token刷新逻辑
This commit is contained in:
parent
a019645104
commit
bc3b05403d
|
|
@ -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<void> switchCamera() async {
|
||||
await state.rctEngine.value?.switchCamera();
|
||||
}
|
||||
|
||||
/// 更新 Token
|
||||
Future<void> renewToken(String token) async {
|
||||
await state.rctEngine.value?.renewToken(token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue