mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Video call UI improvements
This commit is contained in:
@@ -8,6 +8,7 @@ public enum ManagedAudioSessionType: Equatable {
|
||||
case playWithPossiblePortOverride
|
||||
case record(speaker: Bool)
|
||||
case voiceCall
|
||||
case videoCall
|
||||
|
||||
var isPlay: Bool {
|
||||
switch self {
|
||||
@@ -23,7 +24,7 @@ private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones:
|
||||
switch type {
|
||||
case .play:
|
||||
return .playback
|
||||
case .record, .voiceCall:
|
||||
case .record, .voiceCall, .videoCall:
|
||||
return .playAndRecord
|
||||
case .playWithPossiblePortOverride:
|
||||
if headphones {
|
||||
@@ -244,6 +245,7 @@ public final class ManagedAudioSession {
|
||||
|
||||
if let availableInputs = audioSession.availableInputs {
|
||||
var hasHeadphones = false
|
||||
var hasBluetoothHeadphones = false
|
||||
|
||||
var headphonesAreActive = false
|
||||
loop: for currentOutput in audioSession.currentRoute.outputs {
|
||||
@@ -251,6 +253,7 @@ public final class ManagedAudioSession {
|
||||
case .headphones, .bluetoothA2DP, .bluetoothHFP:
|
||||
headphonesAreActive = true
|
||||
hasHeadphones = true
|
||||
hasBluetoothHeadphones = [.bluetoothA2DP, .bluetoothHFP].contains(currentOutput.portType)
|
||||
activeOutput = .headphones
|
||||
break loop
|
||||
default:
|
||||
@@ -296,7 +299,7 @@ public final class ManagedAudioSession {
|
||||
availableOutputs.insert(.speaker, at: 0)
|
||||
}
|
||||
|
||||
if hasHeadphones {
|
||||
if hasHeadphones && !hasBluetoothHeadphones {
|
||||
availableOutputs.insert(.headphones, at: 0)
|
||||
}
|
||||
availableOutputs.insert(.builtin, at: 0)
|
||||
@@ -672,15 +675,24 @@ public final class ManagedAudioSession {
|
||||
options.insert(.allowBluetooth)
|
||||
}
|
||||
}
|
||||
case .record, .voiceCall:
|
||||
case .record, .voiceCall, .videoCall:
|
||||
options.insert(.allowBluetooth)
|
||||
}
|
||||
print("ManagedAudioSession setting active true")
|
||||
let mode: AVAudioSession.Mode
|
||||
switch type {
|
||||
case .voiceCall:
|
||||
mode = .voiceChat
|
||||
case .videoCall:
|
||||
mode = .videoChat
|
||||
default:
|
||||
mode = .default
|
||||
}
|
||||
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
|
||||
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: type == .voiceCall ? .voiceChat : .default, policy: .default, options: options)
|
||||
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: mode, policy: .default, options: options)
|
||||
} else {
|
||||
AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:error:"), with: nativeCategory)
|
||||
try AVAudioSession.sharedInstance().setMode(type == .voiceCall ? .voiceChat : .default)
|
||||
try AVAudioSession.sharedInstance().setMode(mode)
|
||||
}
|
||||
} catch let error {
|
||||
print("ManagedAudioSession setup error \(error)")
|
||||
|
||||
Reference in New Issue
Block a user