diff --git a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift index 3e5259e716..edef84fe11 100644 --- a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift +++ b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift @@ -81,7 +81,7 @@ public final class CallKitIntegration { } } - func dropCall(uuid: UUID) { + public func dropCall(uuid: UUID) { if #available(iOSApplicationExtension 10.0, iOS 10.0, *) { (sharedProviderDelegate as? CallKitProviderDelegate)?.dropCall(uuid: uuid) } diff --git a/submodules/TelegramCore/Sources/State/CallSessionManager.swift b/submodules/TelegramCore/Sources/State/CallSessionManager.swift index 1f7e2ebeff..234b29fc0c 100644 --- a/submodules/TelegramCore/Sources/State/CallSessionManager.swift +++ b/submodules/TelegramCore/Sources/State/CallSessionManager.swift @@ -537,9 +537,14 @@ private final class CallSessionManagerContext { guard let strongSelf = self else { return } - strongSelf.contexts.removeValue(forKey: internalId) - strongSelf.contextIdByStableId.removeValue(forKey: stableId) + context.state = .terminated(id: nil, accessHash: nil, reason: .ended(.missed), reportRating: false, sendDebugLogs: false) + strongSelf.contextUpdated(internalId: internalId) strongSelf.ringingStatesUpdated() + if context.isEmpty { + strongSelf.contexts.removeValue(forKey: internalId) + } + + strongSelf.contextIdByStableId.removeValue(forKey: stableId) } })) self.contextIdByStableId[stableId] = internalId diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index 7804de99ff..4beacfcc2b 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -247,6 +247,7 @@ private func extractAccountManagerState(records: AccountRecordsView? private let voipTokenPromise = Promise() @@ -1582,14 +1583,35 @@ private func extractAccountManagerState(records: AccountRecordsView take(1) |> deliverOnMainQueue).start(next: { activeAccounts in + var processed = false for (_, context, _) in activeAccounts.accounts { if context.account.id == accountId { context.account.stateManager.processIncomingCallUpdate(data: updateData, completion: { _ in }) + //callUpdate.callId + let disposable = MetaDisposable() + self.watchedCallsDisposables.add(disposable) + + disposable.set((context.account.callSessionManager.callState(internalId: CallSessionManager.getStableIncomingUUID(stableId: callUpdate.callId)) + |> deliverOnMainQueue).start(next: { state in + switch state.state { + case .terminated: + callKitIntegration.dropCall(uuid: CallSessionManager.getStableIncomingUUID(stableId: callUpdate.callId)) + default: + break + } + })) + + processed = true + break } } + + if !processed { + callKitIntegration.dropCall(uuid: CallSessionManager.getStableIncomingUUID(stableId: callUpdate.callId)) + } }) sharedApplicationContext.wakeupManager.allowBackgroundTimeExtension(timeout: 2.0) diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index 68860c76e2..e1e177c300 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -18,8 +18,19 @@ private func callConnectionDescription(_ connection: CallSessionConnection) -> O private func callConnectionDescriptionsWebrtc(_ connection: CallSessionConnection) -> [OngoingCallConnectionDescriptionWebrtc] { switch connection { - case .reflector: + case let .reflector(reflector): + #if DEBUG + var result: [OngoingCallConnectionDescriptionWebrtc] = [] + if !reflector.ip.isEmpty { + result.append(OngoingCallConnectionDescriptionWebrtc(connectionId: reflector.id, hasStun: false, hasTurn: true, ip: reflector.ip, port: reflector.port, username: "reflector", password: hexString(reflector.peerTag))) + } + if !reflector.ipv6.isEmpty { + result.append(OngoingCallConnectionDescriptionWebrtc(connectionId: reflector.id, hasStun: false, hasTurn: true, ip: reflector.ipv6, port: reflector.port, username: "reflector", password: hexString(reflector.peerTag))) + } + return result + #else return [] + #endif case let .webRtcReflector(reflector): var result: [OngoingCallConnectionDescriptionWebrtc] = [] if !reflector.ip.isEmpty { @@ -686,6 +697,11 @@ public final class OngoingCallContext { let _ = setupLogs OngoingCallThreadLocalContext.applyServerConfig(serializedData) + #if DEBUG + let version = "4.1.2" + let allowP2P = false + #endif + self.internalId = internalId self.account = account self.callSessionManager = callSessionManager diff --git a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm index 8f6e7c171e..290fbe744d 100644 --- a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm +++ b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm @@ -5,6 +5,7 @@ #import "Instance.h" #import "InstanceImpl.h" #import "v2/InstanceV2Impl.h" +#import "v2/InstanceV2ReferenceImpl.h" #import "v2_4_0_0/InstanceV2_4_0_0Impl.h" #include "StaticThreads.h" @@ -800,14 +801,29 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL; return 92; } ++ (void)ensureRegisteredImplementations { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + tgcalls::Register(); + tgcalls::Register(); + tgcalls::Register(); + tgcalls::Register(); + }); +} + + (NSArray * _Nonnull)versionsWithIncludeReference:(bool)includeReference { + [self ensureRegisteredImplementations]; + NSMutableArray *list = [[NSMutableArray alloc] init]; - [list addObject:@"2.7.7"]; - [list addObject:@"3.0.0"]; - if (includeReference) { - [list addObject:@"4.0.0"]; + + for (const auto &version : tgcalls::Meta::Versions()) { + [list addObject:[NSString stringWithUTF8String:version.c_str()]]; } - [list addObject:@"4.0.1"]; + + [list sortUsingComparator:^NSComparisonResult(NSString * _Nonnull lhs, NSString * _Nonnull rhs) { + return [lhs compare:rhs]; + }]; + return list; } @@ -915,15 +931,11 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL; tgcalls::EncryptionKey encryptionKey(encryptionKeyValue, isOutgoing); - __weak OngoingCallThreadLocalContextWebrtc *weakSelf = self; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - tgcalls::Register(); - tgcalls::Register(); - tgcalls::Register(); - }); + [OngoingCallThreadLocalContextWebrtc ensureRegisteredImplementations]; + __weak OngoingCallThreadLocalContextWebrtc *weakSelf = self; _tgVoip = tgcalls::Meta::Create([version UTF8String], (tgcalls::Descriptor){ + .version = [version UTF8String], .config = config, .persistentState = (tgcalls::PersistentState){ derivedStateValue }, .endpoints = endpoints, diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index b7460dd957..3ce2c38805 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit b7460dd9572173aed1e3838f5eb33b813a1e6b31 +Subproject commit 3ce2c38805ea5af7a05b8fe93a26becaf9e76bd3 diff --git a/third-party/webrtc/BUILD b/third-party/webrtc/BUILD index e4fb9b3fc4..61971e0edb 100644 --- a/third-party/webrtc/BUILD +++ b/third-party/webrtc/BUILD @@ -3256,6 +3256,7 @@ common_flags = [ "-DWEBRTC_USE_H264", "-DHAVE_SCTP", "-DWEBRTC_HAVE_USRSCTP", + "-DWEBRTC_HAVE_SCTP", "-Ithird-party/openh264", "-DWEBRTC_NS_FLOAT", "-DRTC_DISABLE_TRACE_EVENTS", @@ -3392,6 +3393,7 @@ cc_library( "-DPACKAGE_VERSION=''", "-DHAVE_SCTP", "-DWEBRTC_HAVE_USRSCTP", + "-DWEBRTC_HAVE_SCTP", "-DNON_WINDOWS_DEFINE", ] + arch_specific_cflags + optimization_flags, visibility = ["//visibility:public"], @@ -3472,6 +3474,7 @@ cc_library( "-DPACKAGE_STRING='\"\"'", "-DHAVE_SCTP", "-DWEBRTC_HAVE_USRSCTP", + "-DWEBRTC_HAVE_SCTP", ] + arch_specific_cflags + optimization_flags, deps = [ "//third-party/boringssl:crypto", @@ -3522,6 +3525,7 @@ objc_library( "-DPACKAGE_VERSION='\"\"'", "-DHAVE_SCTP", "-DWEBRTC_HAVE_USRSCTP", + "-DWEBRTC_HAVE_SCTP", "-DNO_MAIN_THREAD_WRAPPING", "-DRTC_DISABLE_TRACE_EVENTS", "-DRTC_DISABLE_METRICS",