声网服务调试

This commit is contained in:
fengshuo
2021-10-20 14:21:57 +08:00
parent 92883d25d4
commit 383d670f07
12 changed files with 197 additions and 59 deletions

View File

@@ -104,6 +104,7 @@
E81C27A226EF23490031E639 /* XPEnum.h in Sources */ = {isa = PBXBuildFile; fileRef = E81C27A126EF23370031E639 /* XPEnum.h */; };
E81C27AB26EF2D920031E639 /* ThirdUserInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */; };
E81C27AE26EF39AB0031E639 /* AppDelegate+ThirdConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */; };
E81D587E271FC1EB003063FE /* XPRoomViewController+SDKConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = E81D587D271FC1EB003063FE /* XPRoomViewController+SDKConfig.m */; };
E82109AD26F1C8A000FC3319 /* CountDownHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E82109AC26F1C8A000FC3319 /* CountDownHelper.m */; };
E82109B026F1D83500FC3319 /* LoginBindPhonePresent.m in Sources */ = {isa = PBXBuildFile; fileRef = E82109AF26F1D83500FC3319 /* LoginBindPhonePresent.m */; };
E824543526F57D6E00BE8163 /* XPLoginVerifBindPhoneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E824543426F57D6E00BE8163 /* XPLoginVerifBindPhoneViewController.m */; };
@@ -418,6 +419,9 @@
E81C27AA26EF2D920031E639 /* ThirdUserInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ThirdUserInfo.m; sourceTree = "<group>"; };
E81C27AC26EF39AB0031E639 /* AppDelegate+ThirdConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+ThirdConfig.h"; sourceTree = "<group>"; };
E81C27AD26EF39AB0031E639 /* AppDelegate+ThirdConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+ThirdConfig.m"; sourceTree = "<group>"; };
E81D587B271FBC3B003063FE /* RtcInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RtcInterface.h; sourceTree = "<group>"; };
E81D587C271FC1EB003063FE /* XPRoomViewController+SDKConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XPRoomViewController+SDKConfig.h"; sourceTree = "<group>"; };
E81D587D271FC1EB003063FE /* XPRoomViewController+SDKConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XPRoomViewController+SDKConfig.m"; sourceTree = "<group>"; };
E82109AB26F1C8A000FC3319 /* CountDownHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CountDownHelper.h; sourceTree = "<group>"; };
E82109AC26F1C8A000FC3319 /* CountDownHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CountDownHelper.m; sourceTree = "<group>"; };
E82109AE26F1D83500FC3319 /* LoginBindPhonePresent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginBindPhonePresent.h; sourceTree = "<group>"; };
@@ -694,6 +698,7 @@
18486216271EAB8C005FC5DC /* BaseRtcImpl.m */,
18486233271EB794005FC5DC /* AgoraRtcImpl.h */,
18486234271EB794005FC5DC /* AgoraRtcImpl.m */,
E81D587B271FBC3B003063FE /* RtcInterface.h */,
);
path = RTC;
sourceTree = "<group>";
@@ -1429,6 +1434,8 @@
children = (
E88F5EAF271ECEF000FF9B33 /* XPRoomViewController+RoomInfoContainerView.h */,
E88F5EAE271ECEF000FF9B33 /* XPRoomViewController+RoomInfoContainerView.m */,
E81D587C271FC1EB003063FE /* XPRoomViewController+SDKConfig.h */,
E81D587D271FC1EB003063FE /* XPRoomViewController+SDKConfig.m */,
);
path = Category;
sourceTree = "<group>";
@@ -1975,6 +1982,7 @@
18E7B22626E8CDCF0064BC9B /* XplanFlutterBoostDelegate.m in Sources */,
E8EEB8F326FC2050007C6EBA /* SDWaitingView.m in Sources */,
E8B846CB26FDD7CD00A777FE /* XPMineRechargeViewController.m in Sources */,
E81D587E271FC1EB003063FE /* XPRoomViewController+SDKConfig.m in Sources */,
E86596512701A1C000846EBD /* StatisticsService.m in Sources */,
E824544026F58F9400BE8163 /* XPMinePayPwdViewController.m in Sources */,
E8AC723D26F4B6AA007D6E91 /* XPLoginBindPhoneResultViewController.m in Sources */,

View File

@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSMicrophoneUsageDescription</key>
<string>“耳萌”需要您的同意,才可以进行语音聊天</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>“音游”需要您的同意,才可以存储相片到相册</string>
<key>NSPhotoLibraryUsageDescription</key>

View File

@@ -6,7 +6,7 @@
//
#import "BaseRtcImpl.h"
#import "RtcDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@interface AgoraRtcImpl : BaseRtcImpl

View File

@@ -8,17 +8,18 @@
#import "AgoraRtcImpl.h"
#import "XPConstant.h"
#import <AgoraRtcKit/AgoraRtcEngineKit.h>
#import "RtcInterface.h"
@interface AgoraRtcImpl()<AgoraRtcEngineDelegate>
@property(nonatomic, strong) AgoraRtcEngineKit *engine;
///
@property(nonatomic, strong) NSMutableArray *speakingArray;
@end
@implementation AgoraRtcImpl
- (instancetype)init
{
- (instancetype)init {
self = [super init];
if (self) {
_engine = [AgoraRtcEngineKit sharedEngineWithAppId:KeyWithType(KeyType_Agora) delegate:self];
@@ -38,16 +39,21 @@
return self;
}
#pragma mark - RtcDelegate impl
#pragma mark - RtcInterface impl
- (void)joinChannel:(nonnull NSString *)channelId {
[self.engine setClientRole:AgoraClientRoleAudience];
int code = [self.engine joinChannelByToken:nil channelId:channelId info:nil uid:[[[AccountInfoStorage instance] getUid] integerValue] joinSuccess:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) {
// TODO: success
}];
if (code != 0) {
// TODO: fail
}
if (self.delegate && [self.delegate respondsToSelector:@selector(joinChannelFail)]) {
[self.delegate joinChannelFail];
}
} else {
if (self.delegate && [self.delegate respondsToSelector:@selector(joinChannelSuccess)]) {
[self.delegate joinChannelSuccess];
}
}
}
- (void)broadcast:(BOOL)on {
@@ -63,4 +69,61 @@
[AgoraRtcEngineKit destroy];
}
#pragma mark - AgoraRtcEngineDelegate
///
- (void)rtcEngine:(AgoraRtcEngineKit *)engine lastmileQuality:(AgoraNetworkQuality)quality {
if (quality >= 3) {
if (self.delegate && [self.delegate respondsToSelector:@selector(channelQualityDown)]) {
[self.delegate channelQualityDown];
}
}
}
///
- (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *)engine {
if (self.delegate && [self.delegate respondsToSelector:@selector(channelQualityBad)]) {
[self.delegate channelQualityBad];
}
}
///
- (void)rtcEngine:(AgoraRtcEngineKit *)engine reportAudioVolumeIndicationOfSpeakers:(NSArray *)speakers totalVolume:(NSInteger)totalVolume {
[self onSpeakingUsersReport:speakers];
}
- (void)rtcEngineLocalAudioMixingDidFinish:(AgoraRtcEngineKit *)engine{
}
#pragma mark - Private Method
//
- (void)onSpeakingUsersReport:(NSArray *)report {
NSMutableArray *uids = [NSMutableArray array];
if (report != nil && report.count > 0) {
for (AgoraRtcAudioVolumeInfo *userInfo in report) {
NSString *uid = [NSString stringWithFormat:@"%ld",(long)userInfo.uid];
if (userInfo.volume > 15){
if (uid.integerValue == 0) {
[uids addObject:[[AccountInfoStorage instance] getUid]];
}else {
[uids addObject:uid];
}
}
}
self.speakingArray = uids;
if (self.delegate && [self.delegate respondsToSelector:@selector(speakingUsersReportSuccess:)]) {
[self.delegate speakingUsersReportSuccess:self.speakingArray];
}
} else {
if (self.speakingArray != nil) {
self.speakingArray = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(speakingUsersReportSuccess:)]) {
[self.delegate speakingUsersReportSuccess:nil];
}
}
}
}
@end

View File

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

View File

@@ -10,27 +10,19 @@
NS_ASSUME_NONNULL_BEGIN
@protocol RtcDelegate <NSObject>
@optional
///加入成功
- (void)joinChannelSuccess;
///加入失败
- (void)joinChannelFail;
/**
加入频道(房间)
*/
- (void)joinChannel:(NSString *)channelId;
/**
上下麦(说话)
*/
- (void)broadcast:(BOOL)on;
/**
加入频道同时上麦
*/
- (void)joinChannel:(NSString *)channelId broadcast:(BOOL)on;
/**
退出频道
*/
- (void)exitChannel;
/**
销毁引擎
*/
- (void)destory;
///说话者声音的回调
- (void)speakingUsersReportSuccess:(NSMutableArray * _Nullable)speakings;
///掉线
- (void)channelQualityDown;
///网络不好
- (void)channelQualityBad;
@end

View File

@@ -0,0 +1,35 @@
//
// RtcInterface.h
// xplan-ios
//
// Created by 冯硕 on 2021/10/20.
//
///需要暴露的接口
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol RtcInterface <NSObject>
/**
加入频道(房间)
*/
- (void)joinChannel:(NSString *)channelId;
/**
上下麦(说话)
*/
- (void)broadcast:(BOOL)on;
/**
加入频道同时上麦
*/
- (void)joinChannel:(NSString *)channelId broadcast:(BOOL)on;
/**
退出频道
*/
- (void)exitChannel;
/**
销毁引擎
*/
- (void)destory;
@end
NS_ASSUME_NONNULL_END

View File

@@ -6,8 +6,8 @@
//
#import <Foundation/Foundation.h>
#import "RtcInterface.h"
#import "RtcDelegate.h"
NS_ASSUME_NONNULL_BEGIN
typedef enum : NSUInteger {
@@ -17,8 +17,10 @@ typedef enum : NSUInteger {
RtcEngineType_AgoraFast,//声网急速
} RtcEngineType;
@interface RtcManager : NSObject<RtcDelegate>
@interface RtcManager : NSObject
@property (nonatomic, strong, readonly) id<RtcInterface> engine;
///代理
@property (nonatomic,assign) id<RtcDelegate> delegate;
/**
切换音频必须重新调用该方法重新初始化
*/
@@ -26,7 +28,7 @@ typedef enum : NSUInteger {
/**
确保RtcEngineType正确可以直接调用获取instance
*/
+ (instancetype _Nonnull)intance;
+ (instancetype _Nonnull)instance;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (id)copy NS_UNAVAILABLE;

View File

@@ -10,9 +10,10 @@
@interface RtcManager()
@property (nonatomic, strong) id<RtcDelegate> engine;
@property (nonatomic, strong) id<RtcInterface> engine;
@property (nonatomic, assign) RtcEngineType engineType;
///
@property (nonatomic,strong) AgoraRtcImpl *agoraImpl;
@end
@implementation RtcManager
@@ -28,7 +29,7 @@ static RtcManager *instance = nil;
return instance;
}
+ (instancetype)intance {
+ (instancetype)instance {
dispatch_once(&onceToken,^{
instance = [[self alloc] init];
});
@@ -44,16 +45,17 @@ static RtcManager *instance = nil;
_engineType = type;
}
- (id<RtcDelegate>)engine {
- (id<RtcInterface>)engine {
if (!_engine) {
switch (_engineType) {
case RtcEngineType_Agora: {
_engine = [[AgoraRtcImpl alloc] init];
case RtcEngineType_Agora:
{
_engine = self.agoraImpl;
}
break;
default: {
_engine = [[AgoraRtcImpl alloc] init];
default:
{
_engine = self.agoraImpl;
}
break;
}
@@ -61,24 +63,14 @@ static RtcManager *instance = nil;
return _engine;
}
- (void)broadcast:(BOOL)on {
[self.engine broadcast:on];
- (AgoraRtcImpl *)agoraImpl {
if (!_agoraImpl) {
_agoraImpl = [[AgoraRtcImpl alloc] init];
_agoraImpl.delegate = self.delegate;
}
return _agoraImpl;
}
- (void)destory {
[self.engine destory];
}
- (void)exitChannel {
[self.engine destory];
}
- (void)joinChannel:(nonnull NSString *)channelId {
[self.engine joinChannel:channelId];
}
- (void)joinChannel:(nonnull NSString *)channelId broadcast:(BOOL)on {
[self.engine joinChannel:channelId broadcast:on];
}
@end

View File

@@ -0,0 +1,16 @@
//
// XPRoomViewController+SDKConfig.h
// xplan-ios
//
// Created by 冯硕 on 2021/10/20.
//
#import "XPRoomViewController.h"
#import "RtcManager.h"
NS_ASSUME_NONNULL_BEGIN
@interface XPRoomViewController (SDKConfig)<RtcDelegate>
- (void)configEnterRoomSDK;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,24 @@
//
// XPRoomViewController+SDKConfig.m
// xplan-ios
//
// Created by on 2021/10/20.
//
#import "XPRoomViewController+SDKConfig.h"
///Model
#import "RoomInfoModel.h"
@implementation XPRoomViewController (SDKConfig)
- (void)configEnterRoomSDK {
[RtcManager instance].delegate = self;
[[RtcManager instance].engine joinChannel:[NSString stringWithFormat:@"%ld", self.roomInfo.uid] broadcast:YES];
}
#pragma mark - RtcDelegate
- (void)speakingUsersReportSuccess:(NSMutableArray *)speakings {
}
@end

View File

@@ -26,6 +26,7 @@
#import "XPRoomProtocol.h"
///Category
#import "XPRoomViewController+RoomInfoContainerView.h"
#import "XPRoomViewController+SDKConfig.h"
@interface XPRoomViewController ()<XPRoomProtocol>
///
@@ -145,6 +146,7 @@
- (void)enterChatRoomWithUseInfo:(UserInfoModel *)userInfo {
///
#warning to do -
[self configEnterRoomSDK];
}
#pragma mark - XPRoomProtocol