Update CallSessionManager

This commit is contained in:
Ali 2023-03-24 13:56:54 +04:00
parent 5f5d6acab8
commit 7a3aea37a6

View File

@ -369,6 +369,7 @@ private final class CallSessionManagerContext {
private let ringingSubscribers = Bag<([CallSessionRingingState]) -> Void>()
private var contexts: [CallSessionInternalId: CallSessionContext] = [:]
private var futureContextSubscribers: [CallSessionInternalId: Bag<(CallSession) -> Void>] = [:]
private var contextIdByStableId: [CallSessionStableId: CallSessionInternalId] = [:]
private var enqueuedSignalingData: [Int64: [Data]] = [:]
@ -443,7 +444,10 @@ private final class CallSessionManagerContext {
return Signal { [weak self] subscriber in
let disposable = MetaDisposable()
queue.async {
if let strongSelf = self, let context = strongSelf.contexts[internalId] {
guard let strongSelf = self else {
return
}
if let context = strongSelf.contexts[internalId] {
let index = context.subscribers.add { next in
subscriber.putNext(next)
}
@ -459,8 +463,22 @@ private final class CallSessionManagerContext {
}
})
} else {
subscriber.putNext(CallSession(id: internalId, stableId: nil, isOutgoing: false, type: .audio, state: .terminated(id: nil, reason: .error(.generic), options: []), isVideoPossible: true))
subscriber.putCompletion()
if strongSelf.futureContextSubscribers[internalId] == nil {
strongSelf.futureContextSubscribers[internalId] = Bag()
}
let index = strongSelf.futureContextSubscribers[internalId]?.add({ session in
subscriber.putNext(session)
})
if let index = index {
disposable.set(ActionDisposable {
queue.async {
guard let strongSelf = self else {
return
}
strongSelf.futureContextSubscribers[internalId]?.remove(index)
}
})
}
}
}
return disposable
@ -517,6 +535,11 @@ private final class CallSessionManagerContext {
for subscriber in context.subscribers.copyItems() {
subscriber(session)
}
if let futureSubscribers = self.futureContextSubscribers[internalId] {
for subscriber in futureSubscribers.copyItems() {
subscriber(session)
}
}
}
}