зеркало из https://github.com/nextcloud/talk-ios.git
Make sure the speaker state is determined on the correct thread
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Родитель
c8759088f1
Коммит
793de4c867
|
@ -161,6 +161,7 @@ typedef void (^UpdateCallParticipantViewCellBlock)(CallParticipantViewCell *cell
|
|||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(providerWantsToUpgradeToVideoCall:) name:CallKitManagerWantsToUpgradeToVideoCall object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidChangeRoute:) name:AudioSessionDidChangeRouteNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidActivate:) name:AudioSessionWasActivatedByProviderNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidChangeSpeaker:) name:AudioSessionDidChangeSpeakerIsActiveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
|
||||
|
||||
|
@ -464,6 +465,15 @@ typedef void (^UpdateCallParticipantViewCellBlock)(CallParticipantViewCell *cell
|
|||
[self adjustSpeakerButton];
|
||||
}
|
||||
|
||||
- (void)audioSessionDidChangeSpeaker:(NSNotification *)notification
|
||||
{
|
||||
[self adjustSpeakerButton];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self adjustMoreButtonMenu];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Local video
|
||||
|
||||
- (void)setLocalVideoRect
|
||||
|
@ -846,7 +856,7 @@ typedef void (^UpdateCallParticipantViewCellBlock)(CallParticipantViewCell *cell
|
|||
UIImage *speakerImage = [[UIImage imageNamed:@"speaker"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
||||
NSString *speakerActionTitle = NSLocalizedString(@"Speaker", nil);
|
||||
|
||||
if ([[NCAudioController sharedInstance] isSpeakerActive]) {
|
||||
if (![NCAudioController sharedInstance].isSpeakerActive) {
|
||||
speakerImage = [[UIImage imageNamed:@"speaker-off"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
||||
}
|
||||
|
||||
|
@ -899,21 +909,12 @@ typedef void (^UpdateCallParticipantViewCellBlock)(CallParticipantViewCell *cell
|
|||
- (void)adjustSpeakerButton
|
||||
{
|
||||
[[WebRTCCommon shared] dispatch:^{
|
||||
AVAudioSession *audioSession = [NCAudioController sharedInstance].rtcAudioSession.session;
|
||||
AVAudioSessionPortDescription *currentOutput = nil;
|
||||
|
||||
if (audioSession.currentRoute.outputs.count > 0) {
|
||||
currentOutput = audioSession.currentRoute.outputs[0];
|
||||
}
|
||||
|
||||
if ([currentOutput.portType isEqualToString:AVAudioSessionPortBuiltInSpeaker]) {
|
||||
[self setSpeakerButtonActive:YES];
|
||||
} else {
|
||||
[self setSpeakerButtonActive:NO];
|
||||
}
|
||||
|
||||
NCAudioController *audioController = [NCAudioController sharedInstance];
|
||||
AVAudioSession *audioSession = audioController.rtcAudioSession.session;
|
||||
NSUInteger numberOfAvailableInputs = audioSession.availableInputs.count;
|
||||
|
||||
[self setSpeakerButtonActive:audioController.isSpeakerActive];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Show AirPlay button if there are more audio routes available
|
||||
if (numberOfAvailableInputs > 1) {
|
||||
|
@ -1140,7 +1141,7 @@ typedef void (^UpdateCallParticipantViewCellBlock)(CallParticipantViewCell *cell
|
|||
|
||||
- (IBAction)speakerButtonPressed:(id)sender
|
||||
{
|
||||
if ([[NCAudioController sharedInstance] isSpeakerActive]) {
|
||||
if ([NCAudioController sharedInstance].isSpeakerActive) {
|
||||
[self disableSpeaker];
|
||||
_userDisabledSpeaker = YES;
|
||||
} else {
|
||||
|
|
|
@ -27,17 +27,18 @@
|
|||
|
||||
extern NSString * const AudioSessionDidChangeRouteNotification;
|
||||
extern NSString * const AudioSessionWasActivatedByProviderNotification;
|
||||
extern NSString * const AudioSessionDidChangeSpeakerIsActiveNotification;
|
||||
|
||||
@interface NCAudioController : NSObject <RTCAudioSessionDelegate>
|
||||
|
||||
@property (nonatomic, strong) RTCAudioSession *rtcAudioSession;
|
||||
@property (nonatomic, assign) BOOL isSpeakerActive;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
- (void)setAudioSessionToVoiceChatMode;
|
||||
- (void)setAudioSessionToVideoChatMode;
|
||||
- (void)disableAudioSession;
|
||||
- (BOOL)isSpeakerActive;
|
||||
- (void)providerDidActivateAudioSession:(AVAudioSession *)audioSession;
|
||||
- (void)providerDidDeactivateAudioSession:(AVAudioSession *)audioSession;
|
||||
|
||||
|
|
|
@ -26,8 +26,9 @@
|
|||
|
||||
#import "NextcloudTalk-Swift.h"
|
||||
|
||||
NSString * const AudioSessionDidChangeRouteNotification = @"AudioSessionDidChangeRouteNotification";
|
||||
NSString * const AudioSessionWasActivatedByProviderNotification = @"AudioSessionWasActivatedByProviderNotification";
|
||||
NSString * const AudioSessionDidChangeRouteNotification = @"AudioSessionDidChangeRouteNotification";
|
||||
NSString * const AudioSessionWasActivatedByProviderNotification = @"AudioSessionWasActivatedByProviderNotification";
|
||||
NSString * const AudioSessionDidChangeSpeakerIsActiveNotification = @"AudioSessionDidChangeSpeakerIsActiveNotification";
|
||||
|
||||
@implementation NCAudioController
|
||||
|
||||
|
@ -64,6 +65,8 @@ NSString * const AudioSessionWasActivatedByProviderNotification = @"AudioSession
|
|||
}
|
||||
|
||||
[_rtcAudioSession addDelegate:self];
|
||||
|
||||
[self updateIsSpeakerActive];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -105,6 +108,8 @@ NSString * const AudioSessionWasActivatedByProviderNotification = @"AudioSession
|
|||
}
|
||||
|
||||
[_rtcAudioSession unlockForConfiguration];
|
||||
|
||||
[self updateIsSpeakerActive];
|
||||
}
|
||||
|
||||
- (void)disableAudioSession
|
||||
|
@ -123,9 +128,24 @@ NSString * const AudioSessionWasActivatedByProviderNotification = @"AudioSession
|
|||
[_rtcAudioSession unlockForConfiguration];
|
||||
}
|
||||
|
||||
- (BOOL)isSpeakerActive
|
||||
- (void)updateIsSpeakerActive
|
||||
{
|
||||
return [_rtcAudioSession mode] == AVAudioSessionModeVideoChat;
|
||||
AVAudioSession *audioSession = self.rtcAudioSession.session;
|
||||
AVAudioSessionPortDescription *currentOutput = nil;
|
||||
|
||||
if (audioSession.currentRoute.outputs.count > 0) {
|
||||
currentOutput = audioSession.currentRoute.outputs[0];
|
||||
}
|
||||
|
||||
if ([_rtcAudioSession mode] == AVAudioSessionModeVideoChat || [currentOutput.portType isEqualToString:AVAudioSessionPortBuiltInSpeaker]) {
|
||||
self.isSpeakerActive = YES;
|
||||
} else {
|
||||
self.isSpeakerActive = NO;
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:AudioSessionDidChangeSpeakerIsActiveNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (void)providerDidActivateAudioSession:(AVAudioSession *)audioSession
|
||||
|
|
Загрузка…
Ссылка в новой задаче