зеркало из https://github.com/nextcloud/talk-ios.git
Create NCAudioController class to handle RTCAudioSession.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
2d6eb21e4b
Коммит
8085268176
|
@ -35,6 +35,7 @@
|
|||
2C4D7D721F309DA500FF4A0D /* RTCIceCandidate+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D6E1F309DA500FF4A0D /* RTCIceCandidate+JSON.m */; };
|
||||
2C4D7D731F309DA500FF4A0D /* RTCSessionDescription+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D701F309DA500FF4A0D /* RTCSessionDescription+JSON.m */; };
|
||||
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */; };
|
||||
2C4DE9F221F732B40096940D /* NCAudioController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4DE9F121F732B40096940D /* NCAudioController.m */; };
|
||||
2C4E758F214B942D003910D5 /* OpenInFirefoxControllerObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4E758E214B942D003910D5 /* OpenInFirefoxControllerObjC.m */; };
|
||||
2C604BD9211988A700D34DCD /* SystemMessageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */; };
|
||||
2C7381562106136000CDB8DB /* NCChatTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7381552106136000CDB8DB /* NCChatTitleView.m */; };
|
||||
|
@ -179,6 +180,8 @@
|
|||
2C4D7D701F309DA500FF4A0D /* RTCSessionDescription+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RTCSessionDescription+JSON.m"; sourceTree = "<group>"; };
|
||||
2C4D7D741F30F7B600FF4A0D /* ARDUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARDUtilities.h; sourceTree = "<group>"; };
|
||||
2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARDUtilities.m; sourceTree = "<group>"; };
|
||||
2C4DE9F021F732B40096940D /* NCAudioController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCAudioController.h; sourceTree = "<group>"; };
|
||||
2C4DE9F121F732B40096940D /* NCAudioController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCAudioController.m; sourceTree = "<group>"; };
|
||||
2C4E758D214B942D003910D5 /* OpenInFirefoxControllerObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenInFirefoxControllerObjC.h; sourceTree = "<group>"; };
|
||||
2C4E758E214B942D003910D5 /* OpenInFirefoxControllerObjC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenInFirefoxControllerObjC.m; sourceTree = "<group>"; };
|
||||
2C604BD7211988A700D34DCD /* SystemMessageTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemMessageTableViewCell.h; sourceTree = "<group>"; };
|
||||
|
@ -603,6 +606,8 @@
|
|||
2C8CDD0521C2EDE8004E2997 /* AvatarBackgroundImageView.m */,
|
||||
2C4987BB21E640E20060AC27 /* CallKitManager.h */,
|
||||
2C4987BC21E640E20060AC27 /* CallKitManager.m */,
|
||||
2C4DE9F021F732B40096940D /* NCAudioController.h */,
|
||||
2C4DE9F121F732B40096940D /* NCAudioController.m */,
|
||||
);
|
||||
name = Calls;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1082,6 +1087,7 @@
|
|||
2C7A12422017872600864818 /* AddParticipantsTableViewController.m in Sources */,
|
||||
2C063318205ACB140043481A /* VideoResolutionsViewController.m in Sources */,
|
||||
2C43BA7621309A1000B3068A /* NCMessageParameter.m in Sources */,
|
||||
2C4DE9F221F732B40096940D /* NCAudioController.m in Sources */,
|
||||
2C42ADB420B58E6300296DEA /* NCRoomController.m in Sources */,
|
||||
2CA15541208E350300CE8EF0 /* NCChatMessage.m in Sources */,
|
||||
2CA1CC911F014354002FE6A2 /* NCConnectionController.m in Sources */,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#import <WebRTC/RTCAudioSessionConfiguration.h>
|
||||
|
||||
#import "OpenInFirefoxControllerObjC.h"
|
||||
#import "NCAudioController.h"
|
||||
#import "NCConnectionController.h"
|
||||
#import "NCNotificationController.h"
|
||||
#import "NCPushNotification.h"
|
||||
|
@ -44,10 +45,8 @@
|
|||
pushRegistry.delegate = self;
|
||||
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
|
||||
|
||||
RTCAudioSessionConfiguration *configuration = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
configuration.category = AVAudioSessionCategoryPlayAndRecord;
|
||||
configuration.mode = AVAudioSessionModeVideoChat;
|
||||
[RTCAudioSessionConfiguration setWebRTCConfiguration:configuration];
|
||||
NSLog(@"Configure Audio Session");
|
||||
[NCAudioController sharedInstance];
|
||||
|
||||
// Check supported browsers
|
||||
NSMutableArray *supportedBrowsers = [[NSMutableArray alloc] initWithObjects:@"Safari", nil];
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import <CallKit/CallKit.h>
|
||||
#import <CallKit/CXError.h>
|
||||
|
||||
#import "NCAudioController.h"
|
||||
#import "NCRoomsManager.h"
|
||||
|
||||
NSString * const CallKitManagerDidAnswerCallNotification = @"CallKitManagerDidAnswerCallNotification";
|
||||
|
@ -122,7 +123,14 @@ NSString * const CallKitManagerDidAnswerCallNotification = @"CallKitManagerDidA
|
|||
|
||||
- (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession
|
||||
{
|
||||
NSLog(@"Provider:didActivateAudioSession");
|
||||
NSLog(@"Provider:didActivateAudioSession - %@", audioSession);
|
||||
[[NCAudioController sharedInstance] providerDidActivateAudioSession:audioSession];
|
||||
}
|
||||
|
||||
- (void)provider:(CXProvider *)provider didDeactivateAudioSession:(nonnull AVAudioSession *)audioSession
|
||||
{
|
||||
NSLog(@"Provider:didDeactivateAudioSession - %@", audioSession);
|
||||
[[NCAudioController sharedInstance] providerDidDeactivateAudioSession:audioSession];
|
||||
}
|
||||
|
||||
- (void)provider:(CXProvider *)provider performStartCallAction:(nonnull CXStartCallAction *)action
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#import "NBMPeersFlowLayout.h"
|
||||
#import "NCCallController.h"
|
||||
#import "NCAPIController.h"
|
||||
#import "NCAudioController.h"
|
||||
#import "NCRoomController.h"
|
||||
#import "NCRoomsManager.h"
|
||||
#import "NCSettingsController.h"
|
||||
|
@ -218,13 +219,13 @@ typedef NS_ENUM(NSInteger, CallState) {
|
|||
if (!_isAudioOnly) {
|
||||
if ([[UIDevice currentDevice] proximityState] == YES) {
|
||||
[self disableLocalVideo];
|
||||
[_callController setAudioSessionToVoiceChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVoiceChatMode];
|
||||
} else {
|
||||
// Only enable video if it was not disabled by the user.
|
||||
if (!_userDisabledVideo) {
|
||||
[self enableLocalVideo];
|
||||
}
|
||||
[_callController setAudioSessionToVideoChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVideoChatMode];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -465,7 +466,7 @@ typedef NS_ENUM(NSInteger, CallState) {
|
|||
|
||||
- (IBAction)speakerButtonPressed:(id)sender
|
||||
{
|
||||
if ([_callController isSpeakerActive]) {
|
||||
if ([[NCAudioController sharedInstance] isSpeakerActive]) {
|
||||
[self disableSpeaker];
|
||||
} else {
|
||||
[self enableSpeaker];
|
||||
|
@ -474,13 +475,13 @@ typedef NS_ENUM(NSInteger, CallState) {
|
|||
|
||||
- (void)disableSpeaker
|
||||
{
|
||||
[_callController setAudioSessionToVoiceChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVoiceChatMode];
|
||||
[_speakerButton setImage:[UIImage imageNamed:@"speaker-off"] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)enableSpeaker
|
||||
{
|
||||
[_callController setAudioSessionToVideoChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVideoChatMode];
|
||||
[_speakerButton setImage:[UIImage imageNamed:@"speaker"] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// NCAudioController.h
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 22.01.19.
|
||||
// Copyright © 2019 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <WebRTC/RTCAudioSession.h>
|
||||
#import <WebRTC/RTCAudioSessionConfiguration.h>
|
||||
|
||||
@interface NCAudioController : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
- (void)setAudioSessionToVoiceChatMode;
|
||||
- (void)setAudioSessionToVideoChatMode;
|
||||
- (void)changeAudioSessionConfigurationModeTo:(NSString *)mode;
|
||||
- (void)disableAudioSession;
|
||||
- (BOOL)isSpeakerActive;
|
||||
- (void)providerDidActivateAudioSession:(AVAudioSession *)audioSession;
|
||||
- (void)providerDidDeactivateAudioSession:(AVAudioSession *)audioSession;
|
||||
|
||||
@end
|
|
@ -0,0 +1,114 @@
|
|||
//
|
||||
// NCAudioController.m
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 22.01.19.
|
||||
// Copyright © 2019 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NCAudioController.h"
|
||||
|
||||
@interface NCAudioController () <RTCAudioSessionDelegate>
|
||||
|
||||
@property (nonatomic, strong) RTCAudioSession *rtcAudioSession;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NCAudioController
|
||||
|
||||
+ (NCAudioController *)sharedInstance
|
||||
{
|
||||
static NCAudioController *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[NCAudioController alloc] init];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
RTCAudioSessionConfiguration *configuration = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
configuration.category = AVAudioSessionCategoryPlayAndRecord;
|
||||
configuration.mode = AVAudioSessionModeVideoChat;
|
||||
[RTCAudioSessionConfiguration setWebRTCConfiguration:configuration];
|
||||
|
||||
_rtcAudioSession = [RTCAudioSession sharedInstance];
|
||||
[_rtcAudioSession lockForConfiguration];
|
||||
NSError *error = nil;
|
||||
[_rtcAudioSession setConfiguration:configuration error:&error];
|
||||
if (error) {
|
||||
NSLog(@"Error setting configuration: %@", error.localizedDescription);
|
||||
}
|
||||
[_rtcAudioSession unlockForConfiguration];
|
||||
_rtcAudioSession.useManualAudio = YES;
|
||||
[_rtcAudioSession addDelegate:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Audio session configuration
|
||||
|
||||
- (void)setAudioSessionToVoiceChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVoiceChat];
|
||||
}
|
||||
|
||||
- (void)setAudioSessionToVideoChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVideoChat];
|
||||
}
|
||||
|
||||
- (void)changeAudioSessionConfigurationModeTo:(NSString *)mode
|
||||
{
|
||||
RTCAudioSessionConfiguration *configuration = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
configuration.category = AVAudioSessionCategoryPlayAndRecord;
|
||||
configuration.mode = mode;
|
||||
|
||||
[_rtcAudioSession lockForConfiguration];
|
||||
BOOL hasSucceeded = NO;
|
||||
NSError *error = nil;
|
||||
if (_rtcAudioSession.isActive) {
|
||||
hasSucceeded = [_rtcAudioSession setConfiguration:configuration error:&error];
|
||||
} else {
|
||||
hasSucceeded = [_rtcAudioSession setConfiguration:configuration
|
||||
active:YES
|
||||
error:&error];
|
||||
}
|
||||
if (!hasSucceeded) {
|
||||
NSLog(@"Error setting configuration: %@", error.localizedDescription);
|
||||
}
|
||||
[_rtcAudioSession unlockForConfiguration];
|
||||
}
|
||||
|
||||
- (void)disableAudioSession
|
||||
{
|
||||
[_rtcAudioSession lockForConfiguration];
|
||||
NSError *error = nil;
|
||||
BOOL hasSucceeded = [_rtcAudioSession setActive:NO error:&error];
|
||||
if (!hasSucceeded) {
|
||||
NSLog(@"Error setting configuration: %@", error.localizedDescription);
|
||||
}
|
||||
[_rtcAudioSession unlockForConfiguration];
|
||||
}
|
||||
|
||||
- (BOOL)isSpeakerActive
|
||||
{
|
||||
return [_rtcAudioSession mode] == AVAudioSessionModeVideoChat;
|
||||
}
|
||||
|
||||
- (void)providerDidActivateAudioSession:(AVAudioSession *)audioSession
|
||||
{
|
||||
[_rtcAudioSession audioSessionDidActivate:audioSession];
|
||||
_rtcAudioSession.isAudioEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)providerDidDeactivateAudioSession:(AVAudioSession *)audioSession
|
||||
{
|
||||
[_rtcAudioSession audioSessionDidDeactivate:audioSession];
|
||||
_rtcAudioSession.isAudioEnabled = NO;
|
||||
}
|
||||
|
||||
@end
|
|
@ -47,11 +47,8 @@ typedef void (^GetUserIdForSessionIdCompletionBlock)(NSString *userId, NSError *
|
|||
- (void)leaveCall;
|
||||
- (BOOL)isVideoEnabled;
|
||||
- (BOOL)isAudioEnabled;
|
||||
- (BOOL)isSpeakerActive;
|
||||
- (void)enableVideo:(BOOL)enable;
|
||||
- (void)enableAudio:(BOOL)enable;
|
||||
- (void)setAudioSessionToVoiceChatMode;
|
||||
- (void)setAudioSessionToVideoChatMode;
|
||||
- (NSString *)getUserIdFromSessionId:(NSString *)sessionId;
|
||||
- (void)getUserIdInServerFromSessionId:(NSString *)sessionId withCompletionBlock:(GetUserIdForSessionIdCompletionBlock)block;
|
||||
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
#import <WebRTC/RTCVideoTrack.h>
|
||||
#import <WebRTC/RTCVideoCapturer.h>
|
||||
#import <WebRTC/RTCCameraVideoCapturer.h>
|
||||
#import <WebRTC/RTCAudioSession.h>
|
||||
#import <WebRTC/RTCAudioSessionConfiguration.h>
|
||||
#import "NCAPIController.h"
|
||||
#import "NCAudioController.h"
|
||||
#import "NCSettingsController.h"
|
||||
#import "NCSignalingController.h"
|
||||
#import "NCExternalSignalingController.h"
|
||||
|
@ -73,9 +72,9 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
_signalingController.observer = self;
|
||||
|
||||
if (audioOnly) {
|
||||
[self setAudioSessionToVoiceChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVoiceChatMode];
|
||||
} else {
|
||||
[self setAudioSessionToVideoChatMode];
|
||||
[[NCAudioController sharedInstance] setAudioSessionToVideoChatMode];
|
||||
}
|
||||
|
||||
[self initRecorder];
|
||||
|
@ -148,6 +147,8 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
_joinCallTask = nil;
|
||||
[self.delegate callControllerDidEndCall:self];
|
||||
}
|
||||
|
||||
[[NCAudioController sharedInstance] disableAudioSession];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
@ -288,46 +289,6 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark - Audio session configuration
|
||||
|
||||
- (void)setAudioSessionToVoiceChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVoiceChat];
|
||||
}
|
||||
|
||||
- (void)setAudioSessionToVideoChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVideoChat];
|
||||
}
|
||||
|
||||
- (void)changeAudioSessionConfigurationModeTo:(NSString *)mode
|
||||
{
|
||||
RTCAudioSessionConfiguration *configuration = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
configuration.category = AVAudioSessionCategoryPlayAndRecord;
|
||||
configuration.mode = mode;
|
||||
|
||||
RTCAudioSession *session = [RTCAudioSession sharedInstance];
|
||||
[session lockForConfiguration];
|
||||
BOOL hasSucceeded = NO;
|
||||
NSError *error = nil;
|
||||
if (session.isActive) {
|
||||
hasSucceeded = [session setConfiguration:configuration error:&error];
|
||||
} else {
|
||||
hasSucceeded = [session setConfiguration:configuration
|
||||
active:YES
|
||||
error:&error];
|
||||
}
|
||||
if (!hasSucceeded) {
|
||||
NSLog(@"Error setting configuration: %@", error.localizedDescription);
|
||||
}
|
||||
[session unlockForConfiguration];
|
||||
}
|
||||
|
||||
- (BOOL)isSpeakerActive
|
||||
{
|
||||
return [[RTCAudioSession sharedInstance] mode] == AVAudioSessionModeVideoChat;
|
||||
}
|
||||
|
||||
#pragma mark - Peer Connection Wrapper
|
||||
|
||||
- (NCPeerConnection *)getPeerConnectionWrapperForSessionId:(NSString *)sessionId
|
||||
|
|
Загрузка…
Ссылка в новой задаче