From 144cfc8e22ac0f9e73d6bc91ff88a120e86285b0 Mon Sep 17 00:00:00 2001 From: hy Date: Thu, 16 Apr 2026 16:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/audio/rtc_manager.dart | 30 ++++++++++--------- .../repositories/user_repository.dart | 14 +++++---- .../repositories/sc_user_repository_impl.dart | 28 ++++++++++------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/lib/services/audio/rtc_manager.dart b/lib/services/audio/rtc_manager.dart index eaf4d0a..dc65103 100644 --- a/lib/services/audio/rtc_manager.dart +++ b/lib/services/audio/rtc_manager.dart @@ -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 ?? "", diff --git a/lib/shared/business_logic/repositories/user_repository.dart b/lib/shared/business_logic/repositories/user_repository.dart index f741fdc..4bcbbdd 100644 --- a/lib/shared/business_logic/repositories/user_repository.dart +++ b/lib/shared/business_logic/repositories/user_repository.dart @@ -63,11 +63,15 @@ abstract class SocialChatUserRepository { ///发送心跳 Future heartbeat(String status, bool upMick, {String? roomId}); - ///上麦心跳 - Future anchorHeartbeat(String roomId); - - ///声网token - Future getRtcToken(String channel, String userId); + ///上麦心跳 + Future anchorHeartbeat(String roomId); + + ///声网token + Future getRtcToken( + String channel, + String userId, { + bool isPublisher = false, + }); ///退出房间 Future quitRoom(String roomId); diff --git a/lib/shared/data_sources/sources/repositories/sc_user_repository_impl.dart b/lib/shared/data_sources/sources/repositories/sc_user_repository_impl.dart index a4027d5..1bbd5f5 100644 --- a/lib/shared/data_sources/sources/repositories/sc_user_repository_impl.dart +++ b/lib/shared/data_sources/sources/repositories/sc_user_repository_impl.dart @@ -209,16 +209,24 @@ class SCAccountRepository implements SocialChatUserRepository { return result; } - ///external/im-trtc/tmp/agora/sig - @override - Future 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 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