RtcManager 外部协议调整;新增内部协议

This commit is contained in:
zu
2021-10-21 00:50:48 +08:00
parent 74807f8bc3
commit 70a30cd7d0
10 changed files with 78 additions and 42 deletions

View File

@@ -384,6 +384,7 @@
7DB00EC07F1D0ADFF900B38D /* Pods-xplan-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.debug.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.debug.xcconfig"; sourceTree = "<group>"; };
9B0E1C5726E77022005D4442 /* BaseNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = "<group>"; };
9B0E1C5826E77022005D4442 /* BaseNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
9BB865B4272076140029CDE0 /* RtcImplDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RtcImplDelegate.h; sourceTree = "<group>"; };
B66633E061B1B34177CD011C /* Pods-xplan-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.release.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.release.xcconfig"; sourceTree = "<group>"; };
CACF623970097D653132D69A /* Pods_xplan_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_xplan_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E80487632717DDD9008595F2 /* XPRoomMenuItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomMenuItem.h; sourceTree = "<group>"; };
@@ -710,6 +711,7 @@
18486233271EB794005FC5DC /* AgoraRtcImpl.h */,
18486234271EB794005FC5DC /* AgoraRtcImpl.m */,
E81D587B271FBC3B003063FE /* RtcInterface.h */,
9BB865B4272076140029CDE0 /* RtcImplDelegate.h */,
);
path = RtcImpl;
sourceTree = "<group>";

View File

@@ -10,10 +10,9 @@
NS_ASSUME_NONNULL_BEGIN
@protocol RtcDelegate <NSObject>
@optional
///说话者声音的回调
- (void)usersSpeaking:(NSMutableArray * _Nullable)speakings;
- (void)usersSpeaking:(NSMutableArray * _Nullable)uids;
@end

View File

@@ -18,8 +18,8 @@
@implementation AgoraRtcImpl
- (instancetype)init {
self = [super init];
- (instancetype)initWithDelegate:(id<RtcImplDelegate>)delegate {
self = [super initWithDelegate:delegate];
if (self) {
_engine = [AgoraRtcEngineKit sharedEngineWithAppId:KeyWithType(KeyType_Agora) delegate:self];
[_engine setChannelProfile:AgoraChannelProfileLiveBroadcasting];
@@ -71,9 +71,7 @@
}
}
}
if (self.delegate && [self.delegate respondsToSelector:@selector(usersSpeaking:)]) {
[self.delegate usersSpeaking:uids];
}
}

View File

@@ -7,15 +7,16 @@
#import <Foundation/Foundation.h>
#import "RtcInterface.h"
#import "RtcDelegate.h"
#import "RtcImplDelegate.h"
#import "AccountInfoStorage.h"
NS_ASSUME_NONNULL_BEGIN
@interface BaseRtcImpl : NSObject <RtcInterface>
///代理
@property (nonatomic,weak) id<RtcDelegate> delegate;
@property (nonatomic,weak) id<RtcImplDelegate> delegate;
- (instancetype)initWithDelegate:(id<RtcImplDelegate>)delegate;
@end

View File

@@ -7,15 +7,30 @@
#import "BaseRtcImpl.h"
@interface BaseRtcImpl()
@end
@implementation BaseRtcImpl
- (BOOL)joinChannel:(NSString *)channelId broadcast:(BOOL)on {
[self broadcast:on];
return [self joinChannel:channelId];
- (instancetype)initWithDelegate:(id<RtcImplDelegate>)delegate{
self = [super init];
if (self) {
self.delegate = delegate;
}
return self;
}
- (void)broadcast:(BOOL)on {
}
- (void)destory {
}
- (void)exitChannel {
}
- (BOOL)joinChannel:(nonnull NSString *)channelId {
return NO;
}
@end

View File

@@ -0,0 +1,19 @@
//
// RtcImplDelegate.h
// xplan-ios
//
// Created by zu on 2021/10/21.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol RtcImplDelegate <NSObject>
/** 发言用户回调。 */
- (void)usersSpeaking:(NSMutableArray * _Nullable)uids;
@end
NS_ASSUME_NONNULL_END

View File

@@ -18,10 +18,6 @@ NS_ASSUME_NONNULL_BEGIN
上下麦(说话)
*/
- (void)broadcast:(BOOL)on;
/**
加入频道同时上麦
*/
- (BOOL)joinChannel:(NSString *)channelId broadcast:(BOOL)on;
/**
退出频道
*/

View File

@@ -16,6 +16,14 @@ typedef enum : NSUInteger {
RtcEngineType_AgoraFast,//声网急速
} RtcEngineType;
/** 音频服务管理单例,对所有音频服务 SDK 的封装。
**Note:**
- 外部调用者只需要调用 RtcManager 。
- 不要侵入 RctImpl 内的逻辑。
*/
@interface RtcManager : NSObject
/** 初始化/重新初始化 RtcManager 实例,设置音频服务类型和 RtcDelegate。
@@ -48,16 +56,13 @@ typedef enum : NSUInteger {
- (id)mutableCopy NS_UNAVAILABLE;
/** 加入频道(房间)*/
- (BOOL)joinChannel:(NSString *)channelId;
- (BOOL)enterRoom:(NSString *)roomUid;
/** 上下麦(说话)*/
- (void)broadcast:(BOOL)on;
/** 加入频道同时上麦 */
- (BOOL)joinChannel:(NSString *)channelId broadcast:(BOOL)on;
/** 退出频道 */
- (void)exitChannel;
- (void)exitRoom;
/** 销毁引擎(理论上不需要调用) */
- (void)destory;

View File

@@ -6,12 +6,13 @@
//
#import "RtcManager.h"
#import "RtcImplDelegate.h"
#import "AgoraRtcImpl.h"
@interface RtcManager()
@interface RtcManager()<RtcImplDelegate>
@property (nonatomic, strong) id<RtcInterface> engine;
@property (nonatomic,assign) id<RtcDelegate> engineDelegate;
@property (nonatomic, weak) id<RtcDelegate> engineDelegate;
@property (nonatomic, assign) RtcEngineType engineType;
@end
@@ -34,19 +35,15 @@
return rtcManager;
}
- (BOOL)joinChannel:(NSString *)channelId {
return [self.engine joinChannel:channelId];
- (BOOL)enterRoom:(NSString *)roomUid {
return [self.engine joinChannel:roomUid];
}
- (void)broadcast:(BOOL)on {
[self.engine broadcast:on];
}
- (BOOL)joinChannel:(NSString *)channelId broadcast:(BOOL)on {
return [self.engine joinChannel:channelId broadcast:on];
}
- (void)exitChannel {
- (void)exitRoom {
[self.engine exitChannel];
}
@@ -54,6 +51,12 @@
[self.engine destory];
}
- (void)usersSpeaking:(NSMutableArray *)uids {
if (self.engineDelegate) {
[self.engineDelegate usersSpeaking:uids];
}
}
- (void)setEngineType:(RtcEngineType)type {
if (_engine && type != _engineType) {
[_engine exitChannel];
@@ -72,19 +75,16 @@
switch (_engineType) {
case RtcEngineType_Agora:
{
_engine = [[AgoraRtcImpl alloc] init];
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
default:
{
_engine = [[AgoraRtcImpl alloc] init];
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
}
}
if ([_engine isKindOfClass:[BaseRtcImpl class]]) {
((BaseRtcImpl*)_engine).delegate = self.engineDelegate;
}
return _engine;
}

View File

@@ -13,11 +13,12 @@
- (void)configEnterRoomSDK {
[RtcManager initEngineWithType:RtcEngineType_Agora delegate:self];
[[RtcManager instance] joinChannel:[NSString stringWithFormat:@"%ld", (long)self.roomInfo.uid] broadcast:YES];
[[RtcManager instance] enterRoom:[NSString stringWithFormat:@"%ld", (long)self.roomInfo.uid]];
[[RtcManager instance] broadcast:YES];
}
#pragma mark - RtcDelegate
- (void)usersSpeaking:(NSMutableArray *)speakings {
- (void)usersSpeaking:(NSMutableArray *)uids {
}