@@ -114,7 +114,7 @@ - (instancetype)initWithAudioSession:(id)audioSession {
114114 options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
115115 context: (__bridge void *)RTC_OBJC_TYPE (RTCAudioSession).class ];
116116
117- self. isRecordingEnabled = [_session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord ];
117+ _isRecordingEnabled = [self sessionCategoryIsRecordingEnabled ];
118118
119119 RTCLog (@" RTC_OBJC_TYPE(RTCAudioSession) (%p ): init." , self);
120120 }
@@ -542,14 +542,13 @@ - (void)handleRouteChangeNotification:(NSNotification *)notification {
542542 RTCLog (@" Audio route changed: OldDeviceUnavailable" );
543543 break ;
544544 case AVAudioSessionRouteChangeReasonCategoryChange:
545- RTCLog (@" Audio route changed: CategoryChange to :%@ " ,
546- self.session .category );
547- if (!self.isRecordingEnabled && [self .session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord]) {
548- self.isRecordingEnabled = true ;
549- [self notifyWillRecord ];
550- }
551- if (self.isRecordingEnabled && [self .session.category isEqualToString: AVAudioSessionCategoryPlayback]) {
552- self.isRecordingEnabled = false ;
545+ RTCLog (@" Audio route changed: CategoryChange to :%@ " , self.session .category );
546+ {
547+ BOOL newValue = [self sessionCategoryIsRecordingEnabled ];
548+ if (_isRecordingEnabled != newValue) {
549+ _isRecordingEnabled = newValue;
550+ [self notifyDidChangeAudioSessionRecordingEnabled ];
551+ }
553552 }
554553 break ;
555554 case AVAudioSessionRouteChangeReasonOverride:
@@ -782,7 +781,7 @@ - (BOOL)unconfigureWebRTCSession:(NSError **)outError {
782781 }
783782 RTCLog (@" Unconfiguring audio session for WebRTC." );
784783 [self setActive: NO error: outError];
785- self. isRecordingEnabled = NO ;
784+ _isRecordingEnabled = NO ;
786785
787786 return YES ;
788787}
@@ -1007,14 +1006,18 @@ - (void)notifyFailedToSetActive:(BOOL)active error:(NSError *)error {
10071006 }
10081007}
10091008
1010- - (void )notifyWillRecord {
1009+ - (void )notifyDidChangeAudioSessionRecordingEnabled {
10111010 for (auto delegate : self.delegates ) {
1012- SEL sel = @selector (audioSessionWillRecord : );
1011+ SEL sel = @selector (audioSessionDidChangeRecordingEnabled : );
10131012 if ([delegate respondsToSelector: sel]) {
1014- [delegate audioSessionWillRecord :self ];
1013+ [delegate audioSessionDidChangeRecordingEnabled :self ];
10151014 }
10161015 }
10171016}
10181017
1018+ -(BOOL )sessionCategoryIsRecordingEnabled {
1019+ return [_session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord] ||
1020+ [_session.category isEqualToString: AVAudioSessionCategoryRecord];
1021+ }
10191022
10201023@end
0 commit comments