Fix voice chat issues

This commit is contained in:
Ali 2021-03-11 01:22:44 +04:00
parent b9f5db6a5a
commit d109d9aed9
4 changed files with 40 additions and 19 deletions

View File

@ -422,7 +422,7 @@ public final class ManagedAudioSession {
if let strongSelf = self { if let strongSelf = self {
for holder in strongSelf.holders { for holder in strongSelf.holders {
if holder.id == id && holder.active { if holder.id == id && holder.active {
strongSelf.setup(type: audioSessionType, outputMode: holder.outputMode, activateNow: false) strongSelf.setup(type: audioSessionType, outputMode: holder.outputMode, activateNow: true)
break break
} }
} }
@ -649,7 +649,17 @@ public final class ManagedAudioSession {
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none) try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
try AVAudioSession.sharedInstance().setPreferredInput(nil) try AVAudioSession.sharedInstance().setPreferredInput(nil)
} catch let error { } catch let error {
print("ManagedAudioSession applyNone error \(error)") print("ManagedAudioSession applyNone error \(error), waiting")
Thread.sleep(forTimeInterval: 2.0)
do {
try AVAudioSession.sharedInstance().setActive(false, options: [.notifyOthersOnDeactivation])
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
try AVAudioSession.sharedInstance().setPreferredInput(nil)
} catch let error {
print("ManagedAudioSession applyNone repeated error \(error), giving up")
}
} }
if wasActive { if wasActive {
@ -677,7 +687,7 @@ public final class ManagedAudioSession {
do { do {
let nativeCategory = nativeCategoryForType(type, headphones: self.isHeadsetPluggedInValue, outputMode: outputMode) let nativeCategory = nativeCategoryForType(type, headphones: self.isHeadsetPluggedInValue, outputMode: outputMode)
print("ManagedAudioSession setting category for \(type) (native: \(nativeCategory))") print("ManagedAudioSession setting category for \(type) (native: \(nativeCategory)) activateNow: \(activateNow)")
var options: AVAudioSession.CategoryOptions = [] var options: AVAudioSession.CategoryOptions = []
switch type { switch type {
case .play, .ambient: case .play, .ambient:
@ -841,7 +851,7 @@ public final class ManagedAudioSession {
} }
private func updateOutputMode(_ outputMode: AudioSessionOutputMode) { private func updateOutputMode(_ outputMode: AudioSessionOutputMode) {
if let (type, currentOutputMode) = self.currentTypeAndOutputMode, currentOutputMode != outputMode { if let (type, _) = self.currentTypeAndOutputMode {
self.setup(type: type, outputMode: outputMode, activateNow: true) self.setup(type: type, outputMode: outputMode, activateNow: true)
} }
} }

View File

@ -146,6 +146,8 @@ public final class AccountGroupCallContextCacheImpl: AccountGroupCallContextCach
private let queue: Queue private let queue: Queue
private var contexts: [Int64: Record] = [:] private var contexts: [Int64: Record] = [:]
private let leaveDisposables = DisposableSet()
init(queue: Queue) { init(queue: Queue) {
self.queue = queue self.queue = queue
@ -181,6 +183,11 @@ public final class AccountGroupCallContextCacheImpl: AccountGroupCallContextCach
} }
}) })
} }
public func leaveInBackground(account: Account, id: Int64, accessHash: Int64, source: UInt32) {
let disposable = leaveGroupCall(account: account, callId: id, accessHash: accessHash, source: source).start()
self.leaveDisposables.add(disposable)
}
} }
let queue: Queue = .mainQueue() let queue: Queue = .mainQueue()
@ -923,7 +930,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
default: default:
break break
} }
audioSessionControl.setup(synchronous: true) audioSessionControl.setup(synchronous: false)
} }
self.audioSessionShouldBeActive.set(true) self.audioSessionShouldBeActive.set(true)
@ -1412,7 +1419,13 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|> switchToLatest |> switchToLatest
} }
|> deliverOnMainQueue).start(next: { [weak self] event in |> deliverOnMainQueue).start(next: { [weak self] event in
self?.memberEventsPipe.putNext(event) guard let strongSelf = self else {
return
}
if event.peer.id == strongSelf.stateValue.myPeerId {
return
}
strongSelf.memberEventsPipe.putNext(event)
})) }))
if let isCurrentlyConnecting = self.isCurrentlyConnecting, isCurrentlyConnecting { if let isCurrentlyConnecting = self.isCurrentlyConnecting, isCurrentlyConnecting {
@ -1601,18 +1614,16 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
strongSelf.markAsCanBeRemoved() strongSelf.markAsCanBeRemoved()
})) }))
} else { } else {
self.leaveDisposable.set((leaveGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash, source: localSsrc) if let contexts = self.accountContext.cachedGroupCallContexts as? AccountGroupCallContextCacheImpl {
|> deliverOnMainQueue).start(error: { [weak self] _ in let account = self.account
guard let strongSelf = self else { let id = callInfo.id
return let accessHash = callInfo.accessHash
let source = localSsrc
contexts.impl.with { impl in
impl.leaveInBackground(account: account, id: id, accessHash: accessHash, source: source)
} }
strongSelf.markAsCanBeRemoved() }
}, completed: { [weak self] in self.markAsCanBeRemoved()
guard let strongSelf = self else {
return
}
strongSelf.markAsCanBeRemoved()
}))
} }
} else { } else {
self.markAsCanBeRemoved() self.markAsCanBeRemoved()

View File

@ -149,7 +149,7 @@ extension TelegramUser {
guard let lhs = lhs else { guard let lhs = lhs else {
return rhs return rhs
} }
if case .personal? = rhs.accessHash { if let rhsAccessHash = rhs.accessHash, case .personal = rhsAccessHash {
return rhs return rhs
} else { } else {
var userFlags: UserInfoFlags = [] var userFlags: UserInfoFlags = []

@ -1 +1 @@
Subproject commit d19c74b1474e4aab01d797373f1d62e4da5f87a5 Subproject commit 943d24ab5c86d2e4d739e82234b4d14210433ca0