mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Fix default to speaker
This commit is contained in:
parent
46e71cd7c7
commit
950c3d9f1e
@ -19,6 +19,8 @@ public final class SharedCallAudioContext {
|
|||||||
let audioDevice: OngoingCallContext.AudioDevice?
|
let audioDevice: OngoingCallContext.AudioDevice?
|
||||||
let callKitIntegration: CallKitIntegration?
|
let callKitIntegration: CallKitIntegration?
|
||||||
|
|
||||||
|
private let defaultToSpeaker: Bool
|
||||||
|
|
||||||
private var audioSessionDisposable: Disposable?
|
private var audioSessionDisposable: Disposable?
|
||||||
private var audioSessionShouldBeActiveDisposable: Disposable?
|
private var audioSessionShouldBeActiveDisposable: Disposable?
|
||||||
private var isAudioSessionActiveDisposable: Disposable?
|
private var isAudioSessionActiveDisposable: Disposable?
|
||||||
@ -40,10 +42,17 @@ public final class SharedCallAudioContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private let audioSessionShouldBeActive = Promise<Bool>(true)
|
private let audioSessionShouldBeActive = Promise<Bool>(true)
|
||||||
|
private var initialSetupTimer: Foundation.Timer?
|
||||||
|
|
||||||
init(audioSession: ManagedAudioSession, callKitIntegration: CallKitIntegration?) {
|
init(audioSession: ManagedAudioSession, callKitIntegration: CallKitIntegration?, defaultToSpeaker: Bool = false) {
|
||||||
self.callKitIntegration = callKitIntegration
|
self.callKitIntegration = callKitIntegration
|
||||||
self.audioDevice = OngoingCallContext.AudioDevice.create(enableSystemMute: false)
|
self.audioDevice = OngoingCallContext.AudioDevice.create(enableSystemMute: false)
|
||||||
|
self.defaultToSpeaker = defaultToSpeaker
|
||||||
|
|
||||||
|
if defaultToSpeaker {
|
||||||
|
self.didSetCurrentAudioOutputValue = true
|
||||||
|
self.currentAudioOutputValue = .speaker
|
||||||
|
}
|
||||||
|
|
||||||
var didReceiveAudioOutputs = false
|
var didReceiveAudioOutputs = false
|
||||||
self.audioSessionDisposable = audioSession.push(audioSessionType: .voiceCall, manualActivate: { [weak self] control in
|
self.audioSessionDisposable = audioSession.push(audioSessionType: .voiceCall, manualActivate: { [weak self] control in
|
||||||
@ -72,6 +81,27 @@ public final class SharedCallAudioContext {
|
|||||||
audioSessionActive = .single(true)
|
audioSessionActive = .single(true)
|
||||||
}
|
}
|
||||||
self.isAudioSessionActivePromise.set(audioSessionActive)
|
self.isAudioSessionActivePromise.set(audioSessionActive)
|
||||||
|
|
||||||
|
self.initialSetupTimer?.invalidate()
|
||||||
|
self.initialSetupTimer = Foundation.Timer(timeInterval: 0.5, repeats: false, block: { [weak self] _ in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.defaultToSpeaker, let audioSessionControl = self.audioSessionControl {
|
||||||
|
self.currentAudioOutputValue = .speaker
|
||||||
|
self.didSetCurrentAudioOutputValue = true
|
||||||
|
|
||||||
|
if let callKitIntegration = self.callKitIntegration {
|
||||||
|
if self.didSetCurrentAudioOutputValue {
|
||||||
|
callKitIntegration.applyVoiceChatOutputMode(outputMode: .custom(self.currentAudioOutputValue))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
audioSessionControl.setOutputMode(.custom(self.currentAudioOutputValue))
|
||||||
|
audioSessionControl.setup(synchronous: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: { [weak self] _ in
|
}, deactivate: { [weak self] _ in
|
||||||
@ -160,9 +190,13 @@ public final class SharedCallAudioContext {
|
|||||||
self.audioSessionShouldBeActiveDisposable?.dispose()
|
self.audioSessionShouldBeActiveDisposable?.dispose()
|
||||||
self.isAudioSessionActiveDisposable?.dispose()
|
self.isAudioSessionActiveDisposable?.dispose()
|
||||||
self.audioOutputStateDisposable?.dispose()
|
self.audioOutputStateDisposable?.dispose()
|
||||||
|
self.initialSetupTimer?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCurrentAudioOutput(_ output: AudioSessionOutput) {
|
func setCurrentAudioOutput(_ output: AudioSessionOutput) {
|
||||||
|
self.initialSetupTimer?.invalidate()
|
||||||
|
self.initialSetupTimer = nil
|
||||||
|
|
||||||
guard self.currentAudioOutputValue != output else {
|
guard self.currentAudioOutputValue != output else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -427,7 +461,7 @@ public final class PresentationCallImpl: PresentationCall {
|
|||||||
if let data = context.currentAppConfiguration.with({ $0 }).data, let _ = data["ios_killswitch_disable_call_device"] {
|
if let data = context.currentAppConfiguration.with({ $0 }).data, let _ = data["ios_killswitch_disable_call_device"] {
|
||||||
self.sharedAudioContext = nil
|
self.sharedAudioContext = nil
|
||||||
} else {
|
} else {
|
||||||
self.sharedAudioContext = SharedCallAudioContext(audioSession: audioSession, callKitIntegration: callKitIntegration)
|
self.sharedAudioContext = SharedCallAudioContext(audioSession: audioSession, callKitIntegration: callKitIntegration, defaultToSpeaker: startWithVideo || initialState?.type == .video)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let _ = self.sharedAudioContext {
|
if let _ = self.sharedAudioContext {
|
||||||
|
@ -1134,7 +1134,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if useSharedAudio {
|
if useSharedAudio {
|
||||||
let sharedAudioContextValue = SharedCallAudioContext(audioSession: audioSession, callKitIntegration: callKitIntegration)
|
let sharedAudioContextValue = SharedCallAudioContext(audioSession: audioSession, callKitIntegration: callKitIntegration, defaultToSpeaker: true)
|
||||||
sharedAudioContext = sharedAudioContextValue
|
sharedAudioContext = sharedAudioContextValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user