修复rtc

This commit is contained in:
hy 2026-04-16 16:31:07 +08:00
parent b076e43180
commit 144cfc8e22
3 changed files with 43 additions and 29 deletions

View File

@ -135,23 +135,25 @@ class RealTimeCommunicationManager extends ChangeNotifier {
onUserOffline: (connection, remoteUid, reason) {
print('rtc用户 $remoteUid 离开了频道 (原因: ${reason})');
},
onTokenPrivilegeWillExpire: (
RtcConnection connection,
String token,
) async {
var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
);
engine?.renewToken(rtcToken.rtcToken ?? "");
},
onTokenPrivilegeWillExpire: (
RtcConnection connection,
String token,
) async {
var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
isPublisher: isOnMai(),
);
engine?.renewToken(rtcToken.rtcToken ?? "");
},
onAudioVolumeIndication: initializeAudioVolumeIndicationCallback,
),
);
var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
);
var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
isPublisher: false,
);
await engine?.joinChannel(
token: rtcToken.rtcToken ?? "",
channelId: currenRoom?.roomProfile?.roomProfile?.id ?? "",

View File

@ -63,11 +63,15 @@ abstract class SocialChatUserRepository {
///
Future heartbeat(String status, bool upMick, {String? roomId});
///
Future anchorHeartbeat(String roomId);
///token
Future<SCRtcTokenRes> getRtcToken(String channel, String userId);
///
Future anchorHeartbeat(String roomId);
///token
Future<SCRtcTokenRes> getRtcToken(
String channel,
String userId, {
bool isPublisher = false,
});
///退
Future<bool> quitRoom(String roomId);

View File

@ -209,16 +209,24 @@ class SCAccountRepository implements SocialChatUserRepository {
return result;
}
///external/im-trtc/tmp/agora/sig
@override
Future<SCRtcTokenRes> getRtcToken(String channel, String userId) async {
final result = await http.get(
"2572c69d25a0946b0cb35b24bdfcd61c9bcef4afdaced7dfc47a641bd9584f96",
queryParams: {"channelName": channel, "userId": userId},
fromJson: (json) => SCRtcTokenRes.fromJson(json),
);
return result;
}
///external/im-trtc/tmp/agora/sig
@override
Future<SCRtcTokenRes> getRtcToken(
String channel,
String userId, {
bool isPublisher = false,
}) async {
final result = await http.get(
"2572c69d25a0946b0cb35b24bdfcd61c9bcef4afdaced7dfc47a641bd9584f96",
queryParams: {
"channelName": channel,
"userId": userId,
"isPublisher": isPublisher,
},
fromJson: (json) => SCRtcTokenRes.fromJson(json),
);
return result;
}
///live/room/quit
@override