Files
yinmeng-ios/xplan-ios/Main/RTC/RtcManager.m
2021-10-21 09:50:35 +08:00

91 lines
1.9 KiB
Objective-C

//
// RTCManager.m
// xplan-ios
//
// Created by zu on 2021/10/19.
//
#import "RtcManager.h"
#import "RtcImplDelegate.h"
#import "AgoraRtcImpl.h"
@interface RtcManager()<RtcImplDelegate>
@property (nonatomic, strong) id<RtcInterface> engine;
@property (nonatomic, weak) id<RtcDelegate> engineDelegate;
@property (nonatomic, assign) RtcEngineType engineType;
@end
@implementation RtcManager
+ (instancetype)instance {
static dispatch_once_t onceToken;
static RtcManager *instance = nil;
dispatch_once(&onceToken,^{
instance = [[self alloc] init];
});
return instance;
}
+ (instancetype)initEngineWithType:(RtcEngineType)type delegate:(id<RtcDelegate> _Nullable)delegate{
RtcManager* rtcManager = [self instance];
[rtcManager setEngineType:type];
[rtcManager setEngineDelegate:delegate];
return rtcManager;
}
- (BOOL)enterRoom:(NSString *)roomUid {
return [self.engine joinChannel:roomUid];
}
- (void)broadcast:(BOOL)on {
[self.engine broadcast:on];
}
- (void)exitRoom {
[self.engine exitChannel];
}
- (void)destory {
[self.engine destory];
}
- (void)usersSpeaking:(NSMutableArray *)uids {
if (self.engineDelegate) {
[self.engineDelegate usersSpeaking:uids];
}
}
- (void)setEngineType:(RtcEngineType)type {
if (_engine && type != _engineType) {
[_engine exitChannel];
[_engine destory];
_engine = nil;
}
_engineType = type;
}
- (void)setEngineDelegate:(id<RtcDelegate>)delegate {
_engineDelegate = delegate;
}
- (id<RtcInterface>)engine {
if (!_engine) {
switch (_engineType) {
case RtcEngineType_Agora:
{
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
default:
{
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
}
}
return _engine;
}
@end