修复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) { onUserOffline: (connection, remoteUid, reason) {
print('rtc用户 $remoteUid 离开了频道 (原因: ${reason})'); print('rtc用户 $remoteUid 离开了频道 (原因: ${reason})');
}, },
onTokenPrivilegeWillExpire: ( onTokenPrivilegeWillExpire: (
RtcConnection connection, RtcConnection connection,
String token, String token,
) async { ) async {
var rtcToken = await SCAccountRepository().getRtcToken( var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "", currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "", AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
); isPublisher: isOnMai(),
engine?.renewToken(rtcToken.rtcToken ?? ""); );
}, engine?.renewToken(rtcToken.rtcToken ?? "");
},
onAudioVolumeIndication: initializeAudioVolumeIndicationCallback, onAudioVolumeIndication: initializeAudioVolumeIndicationCallback,
), ),
); );
var rtcToken = await SCAccountRepository().getRtcToken( var rtcToken = await SCAccountRepository().getRtcToken(
currenRoom?.roomProfile?.roomProfile?.id ?? "", currenRoom?.roomProfile?.roomProfile?.id ?? "",
AccountStorage().getCurrentUser()?.userProfile?.id ?? "", AccountStorage().getCurrentUser()?.userProfile?.id ?? "",
); isPublisher: false,
);
await engine?.joinChannel( await engine?.joinChannel(
token: rtcToken.rtcToken ?? "", token: rtcToken.rtcToken ?? "",
channelId: currenRoom?.roomProfile?.roomProfile?.id ?? "", channelId: currenRoom?.roomProfile?.roomProfile?.id ?? "",

View File

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

View File

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