@@ -26,7 +26,29 @@ internal import LiveKitWebRTC
2626@_implementationOnly import LiveKitWebRTC
2727#endif
2828
29+ /// An ``AudioEngineObserver`` that configures the `AVAudioSession` based on the state of the audio engine.
2930public class AudioSessionEngineObserver : AudioEngineObserver , Loggable , @unchecked Sendable {
31+ /// Controls automatic configuration of the `AVAudioSession` based on audio engine state.
32+ ///
33+ /// - When `true`: The `AVAudioSession` is automatically configured based on the audio engine state
34+ /// - When `false`: Manual configuration of the `AVAudioSession` is required
35+ ///
36+ /// > Note: It is recommended to set this value before connecting to a room.
37+ ///
38+ /// Default value: `true`
39+ public var isAutomaticConfigurationEnabled : Bool {
40+ get { _state. isAutomaticConfigurationEnabled }
41+ set { _state. mutate { $0. isAutomaticConfigurationEnabled = newValue } }
42+ }
43+
44+ /// Controls the speaker output preference for audio routing.
45+ ///
46+ /// - When `true`: The speaker output is preferred over the receiver output
47+ /// - When `false`: The receiver output is preferred over the speaker output
48+ ///
49+ /// > Note: This value is only used when `isAutomaticConfigurationEnabled` is `true`.
50+ ///
51+ /// Default value: `true`
3052 public var isSpeakerOutputPreferred : Bool {
3153 get { _state. isSpeakerOutputPreferred }
3254 set { _state. mutate { $0. isSpeakerOutputPreferred = newValue } }
@@ -35,6 +57,7 @@ public class AudioSessionEngineObserver: AudioEngineObserver, Loggable, @uncheck
3557 struct State : Sendable {
3658 var next : ( any AudioEngineObserver ) ?
3759
60+ var isAutomaticConfigurationEnabled : Bool = true
3861 var isPlayoutEnabled : Bool = false
3962 var isRecordingEnabled : Bool = false
4063 var isSpeakerOutputPreferred : Bool = true
@@ -49,7 +72,7 @@ public class AudioSessionEngineObserver: AudioEngineObserver, Loggable, @uncheck
4972
5073 public init ( ) {
5174 _state. onDidMutate = { new_, old_ in
52- if new_. isPlayoutEnabled != old_. isPlayoutEnabled ||
75+ if new_. isAutomaticConfigurationEnabled , new_ . isPlayoutEnabled != old_. isPlayoutEnabled ||
5376 new_. isRecordingEnabled != old_. isRecordingEnabled ||
5477 new_. isSpeakerOutputPreferred != old_. isSpeakerOutputPreferred
5578 {
0 commit comments