Files
yinmeng-ios/xplan-ios/Main/RTC/RtcManager.m

91 lines
1.9 KiB
Mathematica
Raw Normal View History

//
// RTCManager.m
// xplan-ios
//
// Created by zu on 2021/10/19.
//
#import "RtcManager.h"
#import "RtcImplDelegate.h"
#import "AgoraRtcImpl.h"
@interface RtcManager()<RtcImplDelegate>
2021-10-20 14:21:57 +08:00
@property (nonatomic, strong) id<RtcInterface> engine;
@property (nonatomic, weak) id<RtcDelegate> engineDelegate;
@property (nonatomic, assign) RtcEngineType engineType;
@end
@implementation RtcManager
2021-10-20 17:06:31 +08:00
+ (instancetype)instance {
static dispatch_once_t onceToken;
static RtcManager *instance = nil;
dispatch_once(&onceToken,^{
instance = [[self alloc] init];
});
return instance;
}
2021-10-20 17:06:31 +08:00
+ (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];
2021-10-19 19:29:25 +08:00
}
2021-10-20 17:06:31 +08:00
- (void)broadcast:(BOOL)on {
[self.engine broadcast:on];
}
- (void)exitRoom {
2021-10-20 17:06:31 +08:00
[self.engine exitChannel];
}
- (void)destory {
[self.engine destory];
}
- (void)usersSpeaking:(NSMutableArray *)uids {
if (self.engineDelegate) {
[self.engineDelegate usersSpeaking:uids];
}
}
2021-10-20 17:06:31 +08:00
- (void)setEngineType:(RtcEngineType)type {
if (_engine && type != _engineType) {
[_engine exitChannel];
[_engine destory];
_engine = nil;
}
_engineType = type;
}
2021-10-20 17:06:31 +08:00
- (void)setEngineDelegate:(id<RtcDelegate>)delegate {
_engineDelegate = delegate;
}
2021-10-20 14:21:57 +08:00
- (id<RtcInterface>)engine {
if (!_engine) {
switch (_engineType) {
2021-10-20 14:21:57 +08:00
case RtcEngineType_Agora:
2021-10-20 17:06:31 +08:00
{
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
2021-10-20 14:21:57 +08:00
default:
2021-10-20 17:06:31 +08:00
{
_engine = [[AgoraRtcImpl alloc] initWithDelegate:self];
}
break;
}
}
return _engine;
}
@end