TCRAudioSessionDelegate Protocol Reference
| Conforms to | NSObject |
|---|---|
| Declared in | TcrSession.h |
Overview
Advanced escape hatch for taking over AVAudioSession management.
For most audio-coexistence scenarios (e.g. running alongside third-party audio SDKs), prefer the
declarative keys audioSessionCategoryOptions / audioSessionMode of initWithParams:andDelegate:,
which require no method implementation and carry no risk. Use this delegate only when you need
dynamic per-call decisions, or need to intercept setActive: as well.
How it works: once set via +setAudioSessionDelegate:, the SDK swizzles RTCAudioSession’s setCategory:withOptions:error: / setMode:error: / setActive:error: and forwards them to the corresponding onSetXxx methods — but only the methods your delegate implements at the moment of setting are taken over; the rest keep the SDK default behavior. All AVAudioSession writes going through RTCAudioSession are intercepted, including the SDK’s internal ones. Priority: TCRAudioSessionDelegate > initWithParams audio keys > SDK defaults.
Note: if you implement onSetActive:error:, it will additionally be invoked on WebRTC’s post-event recovery path (interruption ended / media services reset / returning to foreground while interrupted), carrying the most recent activation state you confirmed. Your implementation must be prepared to receive these extra calls and perform the corresponding AVAudioSession activation so that audio recovers after interruptions.
Warnings: - Must be set BEFORE creating any TcrSession, and can be set only once per process (swizzling is installed via dispatch_once). - The delegate is held weakly; your app must retain it for the whole session lifetime. Once it is deallocated, intercepted calls silently fail (return NO) and audio breaks. - Each implemented onSetXxx method MUST really perform the corresponding AVAudioSession operation and return its result. There is NO fallback to the original implementation — an empty implementation leaves audio dead, which is worse than not setting the delegate at all.
– onSetCategory:withOptions:error:
Forwarded from RTCAudioSession.setCategory:withOptions:error:. Must perform the real AVAudioSession call and return its result.
- (BOOL)onSetCategory:(NSString *_Nonnull)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError *_Nullable *_Nullable)outErrorDeclared In
TcrSession.h
– onSetMode:error:
Forwarded from RTCAudioSession.setMode:error:. Same contract as above.
- (BOOL)onSetMode:(NSString *_Nonnull)mode error:(NSError *_Nullable *_Nullable)outErrorDeclared In
TcrSession.h
– onSetActive:error:
Forwarded from RTCAudioSession.setActive:error:. Same contract as above.
- (BOOL)onSetActive:(BOOL)active error:(NSError *_Nullable *_Nullable)outErrorDeclared In
TcrSession.h