优化声网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,6 +209,10 @@ class MeetingMainLogic extends GetxController with RequestToolMixin {
"会议室编号(${connection.channelId}"
"网络状态($stateType-${AgoraUtil.getConnectionStateChangedType(stateType)}"
"网络改变原因($reason-${AgoraUtil.getConnectionChangedReasonType(reason)}");
if(reason == ConnectionChangedReasonType.connectionChangedTokenExpired){
// 使token已过期
doHttpGetMeetingToken(false);
}else{
if (stateType == ConnectionStateType.connectionStateReconnecting) {
if (EasyLoading.isShow == false) {
ToastUtils.showLoadingToMask(
@ -238,14 +247,13 @@ 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);
}
}