зеркало из https://github.com/nextcloud/talk-ios.git
Change audio route depending on proyimity sensor.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
087efb65dc
Коммит
90e25b2d88
|
@ -57,9 +57,10 @@
|
|||
|
||||
[FIRMessaging messaging].delegate = self;
|
||||
|
||||
RTCAudioSessionConfiguration *webRTCConfig = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
webRTCConfig.categoryOptions = webRTCConfig.categoryOptions | AVAudioSessionCategoryOptionDefaultToSpeaker;
|
||||
[RTCAudioSessionConfiguration setWebRTCConfiguration:webRTCConfig];
|
||||
RTCAudioSessionConfiguration *configuration = [RTCAudioSessionConfiguration webRTCConfiguration];
|
||||
configuration.category = AVAudioSessionCategoryPlayAndRecord;
|
||||
configuration.mode = AVAudioSessionModeVideoChat;
|
||||
[RTCAudioSessionConfiguration setWebRTCConfiguration:configuration];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -126,11 +126,13 @@ typedef NS_ENUM(NSInteger, CallState) {
|
|||
{
|
||||
if ([[UIDevice currentDevice] proximityState] == YES) {
|
||||
[self disableLocalVideo];
|
||||
[_callController setAudioSessionToVoiceChatMode];
|
||||
} else {
|
||||
// Only enable video if it was not disabled by the user.
|
||||
if (!_userDisabledVideo) {
|
||||
[self enableLocalVideo];
|
||||
}
|
||||
[_callController setAudioSessionToVideoChatMode];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ typedef void (^GetUserIdForSessionIdCompletionBlock)(NSString *userId, NSError *
|
|||
- (BOOL)isAudioEnabled;
|
||||
- (void)enableVideo:(BOOL)enable;
|
||||
- (void)enableAudio:(BOOL)enable;
|
||||
- (void)setAudioSessionToVoiceChatMode;
|
||||
- (void)setAudioSessionToVideoChatMode;
|
||||
- (NSString *)getUserIdFromSessionId:(NSString *)sessionId;
|
||||
- (void)getUserIdInServerFromSessionId:(NSString *)sessionId withCompletionBlock:(GetUserIdForSessionIdCompletionBlock)block;
|
||||
|
||||
|
|
|
@ -17,6 +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 "NCSignalingController.h"
|
||||
|
||||
|
@ -54,6 +56,8 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
|
||||
_signalingController = [[NCSignalingController alloc] init];
|
||||
_signalingController.observer = self;
|
||||
|
||||
[self setAudioSessionToVideoChatMode];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -98,6 +102,8 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
_peerConnectionFactory = nil;
|
||||
_connectionsDict = nil;
|
||||
|
||||
[self setAudioSessionToVideoChatMode];
|
||||
|
||||
[[NCAPIController sharedInstance] leaveCall:_room.token withCompletionBlock:^(NSError *error) {
|
||||
if (!error) {
|
||||
[self stopPingCall];
|
||||
|
@ -219,6 +225,41 @@ static NSString * const kNCVideoTrackKind = @"video";
|
|||
[self createLocalVideoTrack];
|
||||
}
|
||||
|
||||
#pragma mark - Audio session configuration
|
||||
|
||||
- (void)setAudioSessionToVoiceChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVoiceChat];
|
||||
}
|
||||
|
||||
- (void)setAudioSessionToVideoChatMode
|
||||
{
|
||||
[self changeAudioSessionConfigurationModeTo:AVAudioSessionModeVideoChat];
|
||||
}
|
||||
|
||||
- (void)changeAudioSessionConfigurationModeTo:(NSString *)mode
|
||||
{
|
||||
RTCAudioSessionConfiguration *configuration = [[RTCAudioSessionConfiguration alloc] init];
|
||||
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];
|
||||
}
|
||||
|
||||
#pragma mark - Peer Connection Wrapper
|
||||
|
||||
- (NCPeerConnection *)getPeerConnectionWrapperForSessionId:(NSString *)sessionId
|
||||
|
|
Загрузка…
Ссылка в новой задаче