Files
featherVoice/QXLive/Manager/QXAgoraEngineEx.m
2025-10-20 09:43:10 +08:00

98 lines
4.5 KiB
Objective-C

//
// QXAgoraEngineEx.m
// QXLive
//
// Created by 启星 on 2025/7/2.
//
#import "QXAgoraEngineEx.h"
#import "QXAgoraEngine.h"
@interface QXAgoraEngineEx()<AgoraRtcEngineDelegate>
@property (nonatomic,strong)NSString*channel;
@property (nonatomic,strong)AgoraRtcConnection *connection;
@property (nonatomic,strong)AgoraRtcChannelMediaOptions *option;
@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{
// AgoraRtcChannelMediaOptions *option = [AgoraRtcChannelMediaOptions new];
// option.publishMicrophoneTrack = YES;
// option.publishMediaPlayerAudioTrack = YES;
// option.enableAudioRecordingOrPlayout = YES;
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: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<AgoraRtcAudioVolumeInfo *> *)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];;
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