mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-18 03:20:09 +00:00
call fixes
This commit is contained in:
parent
c36925e399
commit
be4a6c4c69
@ -9,6 +9,9 @@ import Foundation
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
let kCallMinLayer:Int32 = 65;
|
||||||
|
let kCallMaxLayer:Int32 = 75;
|
||||||
|
|
||||||
public enum CallSessionError: Equatable {
|
public enum CallSessionError: Equatable {
|
||||||
case generic
|
case generic
|
||||||
case privacyRestricted
|
case privacyRestricted
|
||||||
@ -201,6 +204,7 @@ private final class CallSessionContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class CallSessionManagerContext {
|
private final class CallSessionManagerContext {
|
||||||
|
|
||||||
private let queue: Queue
|
private let queue: Queue
|
||||||
private let postbox: Postbox
|
private let postbox: Postbox
|
||||||
private let network: Network
|
private let network: Network
|
||||||
@ -408,9 +412,10 @@ private final class CallSessionManagerContext {
|
|||||||
case let .waiting(config):
|
case let .waiting(config):
|
||||||
context.state = .awaitingConfirmation(id: id, accessHash: accessHash, gAHash: gAHash, b: b, config: config)
|
context.state = .awaitingConfirmation(id: id, accessHash: accessHash, gAHash: gAHash, b: b, config: config)
|
||||||
strongSelf.contextUpdated(internalId: internalId)
|
strongSelf.contextUpdated(internalId: internalId)
|
||||||
case let .call(config, gA, timestamp, connections):
|
case let .call(config, gA, timestamp, connections, maxLayer):
|
||||||
if let (key, keyId, keyVisualHash) = strongSelf.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gA) {
|
if let (key, keyId, keyVisualHash) = strongSelf.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gA) {
|
||||||
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections, maxLayer: 77)
|
|
||||||
|
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections, maxLayer: maxLayer)
|
||||||
strongSelf.contextUpdated(internalId: internalId)
|
strongSelf.contextUpdated(internalId: internalId)
|
||||||
} else {
|
} else {
|
||||||
strongSelf.drop(internalId: internalId, reason: .disconnect)
|
strongSelf.drop(internalId: internalId, reason: .disconnect)
|
||||||
@ -527,7 +532,7 @@ private final class CallSessionManagerContext {
|
|||||||
//assertionFailure()
|
//assertionFailure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, _, connection, alternativeConnections, startDate):
|
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||||
if let internalId = self.contextIdByStableId[id] {
|
if let internalId = self.contextIdByStableId[id] {
|
||||||
if let context = self.contexts[internalId] {
|
if let context = self.contexts[internalId] {
|
||||||
switch context.state {
|
switch context.state {
|
||||||
@ -536,8 +541,12 @@ private final class CallSessionManagerContext {
|
|||||||
case let .awaitingConfirmation(_, accessHash, gAHash, b, config):
|
case let .awaitingConfirmation(_, accessHash, gAHash, b, config):
|
||||||
if let (key, calculatedKeyId, keyVisualHash) = self.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gAOrB.makeData()) {
|
if let (key, calculatedKeyId, keyVisualHash) = self.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gAOrB.makeData()) {
|
||||||
if keyFingerprint == calculatedKeyId {
|
if keyFingerprint == calculatedKeyId {
|
||||||
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: calculatedKeyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections), maxLayer: 77)
|
switch callProtocol {
|
||||||
|
case let .phoneCallProtocol(_, _, maxLayer):
|
||||||
|
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: calculatedKeyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections), maxLayer: maxLayer)
|
||||||
self.contextUpdated(internalId: internalId)
|
self.contextUpdated(internalId: internalId)
|
||||||
|
break
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.drop(internalId: internalId, reason: .disconnect)
|
self.drop(internalId: internalId, reason: .disconnect)
|
||||||
}
|
}
|
||||||
@ -545,8 +554,12 @@ private final class CallSessionManagerContext {
|
|||||||
self.drop(internalId: internalId, reason: .disconnect)
|
self.drop(internalId: internalId, reason: .disconnect)
|
||||||
}
|
}
|
||||||
case let .confirming(id, accessHash, key, keyId, keyVisualHash, _):
|
case let .confirming(id, accessHash, key, keyId, keyVisualHash, _):
|
||||||
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections), maxLayer: 77)
|
switch callProtocol {
|
||||||
|
case let .phoneCallProtocol(_, _, maxLayer):
|
||||||
|
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections), maxLayer: maxLayer)
|
||||||
self.contextUpdated(internalId: internalId)
|
self.contextUpdated(internalId: internalId)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
@ -736,7 +749,7 @@ public final class CallSessionManager {
|
|||||||
|
|
||||||
private enum AcceptedCall {
|
private enum AcceptedCall {
|
||||||
case waiting(config: SecretChatEncryptionConfig)
|
case waiting(config: SecretChatEncryptionConfig)
|
||||||
case call(config: SecretChatEncryptionConfig, gA: Data, timestamp: Int32, connections: CallSessionConnectionSet)
|
case call(config: SecretChatEncryptionConfig, gA: Data, timestamp: Int32, connections: CallSessionConnectionSet, maxLayer: Int32)
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum AcceptCallResult {
|
private enum AcceptCallResult {
|
||||||
@ -755,7 +768,7 @@ private func acceptCallSession(postbox: Postbox, network: Network, stableId: Cal
|
|||||||
|
|
||||||
let gb = MTExp(g, bData, p)!
|
let gb = MTExp(g, bData, p)!
|
||||||
|
|
||||||
return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(id: stableId, accessHash: accessHash), gB: Buffer(data: gb), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: 65, maxLayer: 66)))
|
return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(id: stableId, accessHash: accessHash), gB: Buffer(data: gb), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: kCallMinLayer, maxLayer: kCallMaxLayer)))
|
||||||
|> map { Optional($0) }
|
|> map { Optional($0) }
|
||||||
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
|
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
@ -778,9 +791,12 @@ private func acceptCallSession(postbox: Postbox, network: Network, stableId: Cal
|
|||||||
return .failed
|
return .failed
|
||||||
case .phoneCallWaiting:
|
case .phoneCallWaiting:
|
||||||
return .success(.waiting(config: config))
|
return .success(.waiting(config: config))
|
||||||
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, `protocol`, connection, alternativeConnections, startDate):
|
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||||
if id == stableId {
|
if id == stableId {
|
||||||
return .success(.call(config: config, gA: gAOrB.makeData(), timestamp: startDate, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections)))
|
switch callProtocol{
|
||||||
|
case let .phoneCallProtocol(_, _, maxLayer):
|
||||||
|
return .success(.call(config: config, gA: gAOrB.makeData(), timestamp: startDate, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections), maxLayer: maxLayer))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return .failed
|
return .failed
|
||||||
}
|
}
|
||||||
@ -812,7 +828,7 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer
|
|||||||
|
|
||||||
let gAHash = MTSha256(ga)!
|
let gAHash = MTSha256(ga)!
|
||||||
|
|
||||||
return network.request(Api.functions.phone.requestCall(userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: 65, maxLayer: 66)))
|
return network.request(Api.functions.phone.requestCall(userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: kCallMinLayer, maxLayer: kCallMaxLayer)))
|
||||||
|> map { result -> RequestCallSessionResult in
|
|> map { result -> RequestCallSessionResult in
|
||||||
switch result {
|
switch result {
|
||||||
case let .phoneCall(phoneCall, _):
|
case let .phoneCall(phoneCall, _):
|
||||||
@ -848,7 +864,7 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func confirmCallSession(network: Network, stableId: CallSessionStableId, accessHash: Int64, gA: Data, keyFingerprint: Int64) -> Signal<Api.PhoneCall?, NoError> {
|
private func confirmCallSession(network: Network, stableId: CallSessionStableId, accessHash: Int64, gA: Data, keyFingerprint: Int64) -> Signal<Api.PhoneCall?, NoError> {
|
||||||
return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(id: stableId, accessHash: accessHash), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: 65, maxLayer: 66)))
|
return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(id: stableId, accessHash: accessHash), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: kCallMinLayer, maxLayer: kCallMaxLayer)))
|
||||||
|> map { Optional($0) }
|
|> map { Optional($0) }
|
||||||
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
|
|> `catch` { _ -> Signal<Api.phone.PhoneCall?, NoError> in
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user