diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index e272de99de..02191be3d6 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -29,7 +29,7 @@ 17EC850C29133CDB00319C82 /* CancelledGroupRing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EC850B29133CDB00319C82 /* CancelledGroupRing.swift */; }; 23B9887F4A95010141FCF725 /* Pods_SignalUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E36B9FCE67E9FFDA471A085 /* Pods_SignalUI.framework */; }; 3236FCC42592B67B006D33B9 /* NameCollisionReviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3236FCC32592B67B006D33B9 /* NameCollisionReviewCell.swift */; }; - 32525F9527C74B1A0099E801 /* LightweightCallManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32525F9427C74B1A0099E801 /* LightweightCallManager.swift */; }; + 32525F9527C74B1A0099E801 /* LightweightGroupCallManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32525F9427C74B1A0099E801 /* LightweightGroupCallManager.swift */; }; 326DF2612739F4D90017B789 /* FeaturedBadgeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326DF2602739F4D90017B789 /* FeaturedBadgeViewController.swift */; }; 327CF66825ACE7DD00DA0A6F /* GetStartedBannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327CF66725ACE7DC00DA0A6F /* GetStartedBannerViewController.swift */; }; 328EF3DC25782A6A00D5C31D /* GroupCallSwipeToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328EF3DB25782A6A00D5C31D /* GroupCallSwipeToastView.swift */; }; @@ -2575,7 +2575,7 @@ 264242150E87D10A357DB07B /* Pods_SignalMessaging.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SignalMessaging.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 30A821E68938D081D1190643 /* Pods-SignalServiceKit.profiling.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalServiceKit.profiling.xcconfig"; path = "Pods/Target Support Files/Pods-SignalServiceKit/Pods-SignalServiceKit.profiling.xcconfig"; sourceTree = ""; }; 3236FCC32592B67B006D33B9 /* NameCollisionReviewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameCollisionReviewCell.swift; sourceTree = ""; }; - 32525F9427C74B1A0099E801 /* LightweightCallManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightweightCallManager.swift; sourceTree = ""; }; + 32525F9427C74B1A0099E801 /* LightweightGroupCallManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightweightGroupCallManager.swift; sourceTree = ""; }; 326DF2602739F4D90017B789 /* FeaturedBadgeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturedBadgeViewController.swift; sourceTree = ""; }; 327CF66725ACE7DC00DA0A6F /* GetStartedBannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetStartedBannerViewController.swift; sourceTree = ""; }; 328EF3DB25782A6A00D5C31D /* GroupCallSwipeToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupCallSwipeToastView.swift; sourceTree = ""; }; @@ -5218,7 +5218,7 @@ 32525F9327C74AC50099E801 /* calls */ = { isa = PBXGroup; children = ( - 32525F9427C74B1A0099E801 /* LightweightCallManager.swift */, + 32525F9427C74B1A0099E801 /* LightweightGroupCallManager.swift */, ); path = calls; sourceTree = ""; @@ -11543,7 +11543,7 @@ 340B870E23DF3E3A00BE0AFC /* GroupV2UpdatesImpl.swift in Sources */, 88F67A0C24E5126D00435A71 /* HapticFeedback.swift in Sources */, 4C9D347F23689E06006A4307 /* IncomingContactSyncJobQueue.swift in Sources */, - 32525F9527C74B1A0099E801 /* LightweightCallManager.swift in Sources */, + 32525F9527C74B1A0099E801 /* LightweightGroupCallManager.swift in Sources */, 4C35B08A23F8A9D2003EB937 /* MessageRequestPendingReceipts.swift in Sources */, 34BB78B5272C510900DA0D04 /* MobileCoinHelperMinimal.swift in Sources */, 764981432A230F2C00EC1287 /* MockSMEnvironment.swift in Sources */, diff --git a/Signal/src/Calls/CallService.swift b/Signal/src/Calls/CallService.swift index d46adb2603..d68cd4830b 100644 --- a/Signal/src/Calls/CallService.swift +++ b/Signal/src/Calls/CallService.swift @@ -18,7 +18,12 @@ protocol CallServiceObserver: AnyObject { func didUpdateCall(from oldValue: SignalCall?, to newValue: SignalCall?) } -public final class CallService: LightweightCallManager { +/// Manages events related to both 1:1 and group calls, while the main app is +/// running. +/// +/// Responsible for the 1:1 or group call this device is currently active in, if +/// any, as well as any other updates to other calls that we learn about. +public final class CallService: LightweightGroupCallManager { public typealias CallManagerType = CallManager private var _callManager: CallManagerType! = nil @@ -48,6 +53,8 @@ public final class CallService: LightweightCallManager { /// but othere call state may race (observer state, sleep state, etc.) private var _currentCallLock = UnfairLock() private var _currentCall: SignalCall? + + /// Represents the call currently occuring on this device. @objc public private(set) var currentCall: SignalCall? { get { @@ -498,7 +505,7 @@ public final class CallService: LightweightCallManager { // Kick off a peek now that we've disconnected to get an updated participant state. if let thread = call.thread as? TSGroupThread { - peekCallAndUpdateThread(thread) + peekGroupCallAndUpdateThread(thread) } else { owsFailDebug("Invalid thread type") } @@ -555,7 +562,7 @@ public final class CallService: LightweightCallManager { } } - // MARK: - LightweightCallManager + // MARK: - func buildAndConnectGroupCallIfPossible(thread: TSGroupThread, videoMuted: Bool) -> SignalCall? { AssertIsOnMainThread() @@ -845,17 +852,19 @@ public final class CallService: LightweightCallManager { // MARK: - - override public func peekCallAndUpdateThread(_ thread: TSGroupThread, - expectedEraId: String? = nil, - triggerEventTimestamp: UInt64 = NSDate.ows_millisecondTimeStamp(), - completion: (() -> Void)? = nil) { + override public func peekGroupCallAndUpdateThread( + _ thread: TSGroupThread, + expectedEraId: String? = nil, + triggerEventTimestamp: UInt64 = NSDate.ows_millisecondTimeStamp(), + completion: (() -> Void)? = nil + ) { // If the currentCall is for the provided thread, we don't need to perform an explicit // peek. Connected calls will receive automatic updates from RingRTC guard currentCall?.thread != thread else { Logger.info("Ignoring peek request for the current call") return } - super.peekCallAndUpdateThread(thread, expectedEraId: expectedEraId, triggerEventTimestamp: triggerEventTimestamp, completion: completion) + super.peekGroupCallAndUpdateThread(thread, expectedEraId: expectedEraId, triggerEventTimestamp: triggerEventTimestamp, completion: completion) } override public func postUserNotificationIfNecessary(groupCallMessage: OWSGroupCallMessage, transaction: SDSAnyWriteTransaction) { diff --git a/Signal/src/Calls/SignalCall.swift b/Signal/src/Calls/SignalCall.swift index 86b0954b46..4fb10bae72 100644 --- a/Signal/src/Calls/SignalCall.swift +++ b/Signal/src/Calls/SignalCall.swift @@ -8,7 +8,8 @@ import SignalRingRTC import SignalServiceKit import SignalUI -// All Observer methods will be invoked from the main thread. +/// Represents an observer who will receive updates about a call happening on +/// this device. See ``SignalCall``. public protocol CallObserver: AnyObject { func individualCallStateDidChange(_ call: SignalCall, state: CallState) func individualCallLocalVideoMuteDidChange(_ call: SignalCall, isVideoMuted: Bool) @@ -47,6 +48,7 @@ public extension CallObserver { func callMessageSendFailedUntrustedIdentity(_ call: SignalCall) {} } +/// Represents a call happening on this device. @objc public class SignalCall: NSObject, CallManagerCallReference { public let mode: Mode diff --git a/Signal/src/Calls/Signaling/WebRTCCallMessageHandler.swift b/Signal/src/Calls/Signaling/WebRTCCallMessageHandler.swift index 01120cc427..45d6ab3b83 100644 --- a/Signal/src/Calls/Signaling/WebRTCCallMessageHandler.swift +++ b/Signal/src/Calls/Signaling/WebRTCCallMessageHandler.swift @@ -167,7 +167,7 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler { completion: @escaping () -> Void ) { Logger.info("Received group call update message for thread: \(groupThread.uniqueId) eraId: \(String(describing: updateMessage.eraID))") - callService.peekCallAndUpdateThread( + callService.peekGroupCallAndUpdateThread( groupThread, expectedEraId: updateMessage.eraID, triggerEventTimestamp: serverReceivedTimestamp, diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController+Calls.swift b/Signal/src/ViewControllers/ConversationView/ConversationViewController+Calls.swift index 7e1da2c6f4..bea2ca153a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController+Calls.swift +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController+Calls.swift @@ -95,7 +95,7 @@ public extension ConversationViewController { func refreshCallState() { if let groupThread = thread as? TSGroupThread { - callService.peekCallAndUpdateThread(groupThread) + callService.peekGroupCallAndUpdateThread(groupThread) } } diff --git a/Signal/src/environment/AppEnvironment.swift b/Signal/src/environment/AppEnvironment.swift index b7e24ec9fe..e4f9449f35 100644 --- a/Signal/src/environment/AppEnvironment.swift +++ b/Signal/src/environment/AppEnvironment.swift @@ -115,6 +115,6 @@ public class AppEnvironment: NSObject { } // Hang certain singletons on SMEnvironment too. - SMEnvironment.shared.lightweightCallManagerRef = callServiceRef + SMEnvironment.shared.lightweightGroupCallManagerRef = callServiceRef } } diff --git a/SignalMessaging/calls/LightweightCallManager.swift b/SignalMessaging/calls/LightweightGroupCallManager.swift similarity index 95% rename from SignalMessaging/calls/LightweightCallManager.swift rename to SignalMessaging/calls/LightweightGroupCallManager.swift index 61d0c63661..19c317e2e4 100644 --- a/SignalMessaging/calls/LightweightCallManager.swift +++ b/SignalMessaging/calls/LightweightGroupCallManager.swift @@ -7,8 +7,15 @@ import LibSignalClient import SignalServiceKit import SignalRingRTC -open class LightweightCallManager: NSObject, Dependencies { - +/// Responsible for updating group call state when we learn it may have changed. +/// +/// Lightweight in that it does not maintain or manage state for active calls, +/// and can be used both in the main app and in extensions. +/// +/// - Note +/// This class is subclassed by ``CallService`` in the main app, to additionally +/// manage calls this device is actively participating in. +open class LightweightGroupCallManager: NSObject, Dependencies { public let sfuClient: SFUClient public let httpClient: HTTPClient private var sfuUrl: String { DebugFlags.callingUseTestSFU.get() ? TSConstants.sfuTestURL : TSConstants.sfuURL } @@ -21,7 +28,7 @@ open class LightweightCallManager: NSObject, Dependencies { httpClient.delegate = self } - open dynamic func peekCallAndUpdateThread( + open dynamic func peekGroupCallAndUpdateThread( _ thread: TSGroupThread, expectedEraId: String? = nil, triggerEventTimestamp: UInt64 = NSDate.ows_millisecondTimeStamp(), @@ -171,7 +178,7 @@ open class LightweightCallManager: NSObject, Dependencies { } } -extension LightweightCallManager { +extension LightweightGroupCallManager { /// Fetches a data blob that serves as proof of membership in the group /// Used by RingRTC to verify access to group call information @@ -217,7 +224,7 @@ extension LightweightCallManager { // MARK: - -extension LightweightCallManager: HTTPDelegate { +extension LightweightGroupCallManager: HTTPDelegate { /** * A HTTP request should be sent to the given url. * Invoked on the main thread, asychronously. diff --git a/SignalMessaging/environment/SMEnvironment.swift b/SignalMessaging/environment/SMEnvironment.swift index a0310e7b9d..1d3e98d15e 100644 --- a/SignalMessaging/environment/SMEnvironment.swift +++ b/SignalMessaging/environment/SMEnvironment.swift @@ -34,7 +34,7 @@ public class SMEnvironment { public let smJobQueuesRef: SignalMessagingJobQueues // This property is configured after SMEnvironment is created. - public var lightweightCallManagerRef: LightweightCallManager? + public var lightweightGroupCallManagerRef: LightweightGroupCallManager? public init( preferences: Preferences, diff --git a/SignalMessaging/utils/Dependencies+SignalMessaging.swift b/SignalMessaging/utils/Dependencies+SignalMessaging.swift index 9f668ac821..79250fd140 100644 --- a/SignalMessaging/utils/Dependencies+SignalMessaging.swift +++ b/SignalMessaging/utils/Dependencies+SignalMessaging.swift @@ -42,12 +42,12 @@ public extension NSObject { SMEnvironment.shared.avatarBuilderRef } - var lightweightCallManager: LightweightCallManager? { - SMEnvironment.shared.lightweightCallManagerRef + var lightweightGroupCallManager: LightweightGroupCallManager? { + SMEnvironment.shared.lightweightGroupCallManagerRef } - static var lightweightCallManager: LightweightCallManager? { - SMEnvironment.shared.lightweightCallManagerRef + static var lightweightGroupCallManager: LightweightGroupCallManager? { + SMEnvironment.shared.lightweightGroupCallManagerRef } var smJobQueues: SignalMessagingJobQueues { diff --git a/SignalNSE/NSECallMessageHandler.swift b/SignalNSE/NSECallMessageHandler.swift index e6f60184c8..3cbd3e99ee 100644 --- a/SignalNSE/NSECallMessageHandler.swift +++ b/SignalNSE/NSECallMessageHandler.swift @@ -184,7 +184,7 @@ public class NSECallMessageHandler: NSObject, OWSCallMessageHandler { completion: @escaping () -> Void ) { NSELogger.uncorrelated.info("Received group call update for thread \(groupThread.uniqueId)") - lightweightCallManager?.peekCallAndUpdateThread( + lightweightGroupCallManager?.peekGroupCallAndUpdateThread( groupThread, expectedEraId: updateMessage.eraID, triggerEventTimestamp: serverReceivedTimestamp, diff --git a/SignalNSE/NSEEnvironment.swift b/SignalNSE/NSEEnvironment.swift index bc1d7f47d0..a337832079 100644 --- a/SignalNSE/NSEEnvironment.swift +++ b/SignalNSE/NSEEnvironment.swift @@ -142,7 +142,7 @@ class NSEEnvironment: Dependencies { notificationPresenter: NotificationPresenter() ) - SMEnvironment.shared.lightweightCallManagerRef = LightweightCallManager() + SMEnvironment.shared.lightweightGroupCallManagerRef = LightweightGroupCallManager() databaseContinuation.prepareDatabase().done(on: DispatchQueue.main) { finalSetupContinuation in switch finalSetupContinuation.finish(willResumeInProgressRegistration: false) { diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 4245e0c5d9..379c1ab3c6 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -66,7 +66,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // Configure the rest of the globals before preparing the database. SUIEnvironment.shared.setup() - SMEnvironment.shared.lightweightCallManagerRef = LightweightCallManager() + SMEnvironment.shared.lightweightGroupCallManagerRef = LightweightGroupCallManager() databaseContinuation.prepareDatabase().done(on: DispatchQueue.main) { finalContinuation in switch finalContinuation.finish(willResumeInProgressRegistration: false) {