// // QXAgoraEngineEx.m // QXLive // // Created by 启星 on 2025/7/2. // #import "QXAgoraEngineEx.h" #import "QXAgoraEngine.h" @interface QXAgoraEngineEx() @property (nonatomic,strong)NSString*channel; @property (nonatomic,strong)AgoraRtcConnection *connection; @property (nonatomic,strong)AgoraRtcChannelMediaOptions *option; @property (nonatomic,strong)NSString *pkUserId; @end @implementation QXAgoraEngineEx +(instancetype)sharedEngine { static dispatch_once_t onceToken; static QXAgoraEngineEx *instance; dispatch_once(&onceToken, ^{ instance = [[QXAgoraEngineEx alloc] init]; }); return instance; } -(void)joinExWithAgora_token:(NSString*)agora_token channel:(NSString*)channel pkUserId:(NSString*)pkUserId{ // AgoraRtcChannelMediaOptions *option = [AgoraRtcChannelMediaOptions new]; // option.publishMicrophoneTrack = YES; // option.publishMediaPlayerAudioTrack = YES; // option.enableAudioRecordingOrPlayout = YES; _pkUserId = pkUserId; AgoraRtcConnection *connection = [[AgoraRtcConnection alloc] initWithChannelId:channel localUid:QXGlobal.shareGlobal.loginModel.user_id.longLongValue]; _channel = channel; _connection = connection; MJWeakSelf int result = [[QXAgoraEngine sharedEngine].agoraKit joinChannelExByToken:agora_token connection:connection delegate:self mediaOptions:self.option joinSuccess:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) { /// 此处为:声网加入扩展流成功回调 /// 打开自己在扩展流的推流权限 [[QXAgoraEngine sharedEngine].agoraKit muteLocalAudioStreamEx:NO connection:connection]; /// 屏蔽扩展流中所有人的流 [[QXAgoraEngine sharedEngine].agoraKit muteAllRemoteAudioStreamsEx:YES connection:connection];; /// 只接收扩展流中对方主持的流 pkUserId [[QXAgoraEngine sharedEngine].agoraKit muteRemoteAudioStreamEx:pkUserId.longLongValue mute:NO connection:connection];; }]; QXLOG(@"声网加入扩展流result---->%d",result) } -(void)rtcEngine:(AgoraRtcEngineKit *)engine didJoinChannel:(NSString *)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{ QXLOG(@"声网加入扩展流channel------ %@",channel); } -(void)rtcEngine:(AgoraRtcEngineKit *)engine didOccurError:(AgoraErrorCode)errorCode{ QXLOG(@"声网加入扩展流errorCodel------ %ld",errorCode); } -(void)rtcEngine:(AgoraRtcEngineKit *)engine reportAudioVolumeIndicationOfSpeakers:(NSArray *)speakers totalVolume:(NSInteger)totalVolume{ for (AgoraRtcAudioVolumeInfo *info in speakers) { [[NSNotificationCenter defaultCenter] postNotificationName:noticeUserSpeak object:info]; } } -(void)muteLocalEXAudioStream:(BOOL)mute fromUserInfo:(nonnull QXUserHomeModel *)fromUserInfo{ // AgoraRtcChannelMediaOptions *option = [AgoraRtcChannelMediaOptions new]; // option.publishMicrophoneTrack = mute?NO:YES; // option.publishMediaPlayerAudioTrack = mute?NO:YES;; // option.enableAudioRecordingOrPlayout = mute?NO:YES;; // option.clientRoleType = mute?AgoraClientRoleAudience:AgoraClientRoleBroadcaster; // self.option.autoSubscribeAudio = mute?NO:YES; // self.option.autoSubscribeVideo = mute?NO:YES; // self.option.clientRoleType = mute?AgoraClientRoleAudience:AgoraClientRoleBroadcaster; // [[QXAgoraEngine sharedEngine].agoraKit updateChannelExWithMediaOptions:self.option connection:_connection]; int result = [[QXAgoraEngine sharedEngine].agoraKit muteLocalAudioStreamEx:mute connection:_connection]; // [[QXAgoraEngine sharedEngine].agoraKit muteRemoteAudioStream:fromUserInfo.user_id.integerValue mute:mute]; QXLOG(@"声网停止ex频道推流result---->%d",result) } -(void)rtcEngine:(AgoraRtcEngineKit *)engine remoteAudioStateChangedOfUid:(NSUInteger)uid state:(AgoraAudioRemoteState)state reason:(AgoraAudioRemoteReason)reason elapsed:(NSInteger)elapsed{ } -(void)muteRemoteEXAudioStream:(BOOL)mute{ // int result = [[QXAgoraEngine sharedEngine].agoraKit muteAllRemoteAudioStreamsEx:mute connection:_connection];; int result = [[QXAgoraEngine sharedEngine].agoraKit muteRemoteAudioStreamEx:_pkUserId.longLongValue mute:mute connection:_connection];; QXLOG(@"声网屏蔽远端声音result---->%d",result) } -(void)quitEXChannelWithLastPkRoomId:(NSString *)last_pk_room_id{ if (_connection == nil) { _connection = [[AgoraRtcConnection alloc] initWithChannelId:last_pk_room_id localUid:QXGlobal.shareGlobal.loginModel.user_id.longLongValue]; } int result = [[QXAgoraEngine sharedEngine].agoraKit leaveChannelEx:_connection leaveChannelBlock:^(AgoraChannelStats * _Nonnull stat) { }]; QXLOG(@"声网退出频道result---->%d",result) // [[QXAgoraEngine sharedEngine].agoraKit ]; } -(AgoraRtcChannelMediaOptions *)option{ if (!_option) { _option = [AgoraRtcChannelMediaOptions new]; _option.publishMicrophoneTrack = YES; _option.publishMediaPlayerAudioTrack = YES; _option.enableAudioRecordingOrPlayout = YES; _option.clientRoleType = AgoraClientRoleBroadcaster; } return _option; } @end