Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup how we setup the CallKit provider and have it be used for outgoing calls as well #2967

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
8DCD9CC5361FF22A5B2C20F1 /* AppLockSetupSettingsScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9FCE4D1E3A81AC1CC5CB91 /* AppLockSetupSettingsScreenCoordinator.swift */; };
8DDC6F28C797D8685F2F8E32 /* AnalyticsConsentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57B6B383F1FD04CC0E7B60C6 /* AnalyticsConsentState.swift */; };
8E650379587C31D7912ED67B /* UNNotification+Creator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0AEA686E425F86F6BA0404 /* UNNotification+Creator.swift */; };
8E7A902CA16E24928F83646C /* ElementCallServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = E321E840DCC63790049984F4 /* ElementCallServiceMock.swift */; };
8ED8AF57A06F5EE9978ED23F /* AuthenticationStartScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FB89DC7F9A4A91020037001 /* AuthenticationStartScreenViewModelTests.swift */; };
8EF63DDDC1B54F122070B04D /* ReadMarkerRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6311F21F911E23BE4DF51B4 /* ReadMarkerRoomTimelineView.swift */; };
8F2FAA98457750D9D664136F /* Mapbox in Frameworks */ = {isa = PBXBuildFile; productRef = C1BF15833233CD3BDB7E2B1D /* Mapbox */; };
Expand Down Expand Up @@ -2052,6 +2053,7 @@
E2DCA495ED42D2463DDAA94D /* TimelineBubbleLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineBubbleLayout.swift; sourceTree = "<group>"; };
E2F96CCBEAAA7F2185BFA354 /* ClientProxyMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientProxyMock.swift; sourceTree = "<group>"; };
E3059CFA00C67D8787273B20 /* ServerSelectionScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionScreenViewModel.swift; sourceTree = "<group>"; };
E321E840DCC63790049984F4 /* ElementCallServiceMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementCallServiceMock.swift; sourceTree = "<group>"; };
E36CB905A2B9EC2C92A2DA7C /* KeychainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainController.swift; sourceTree = "<group>"; };
E3B97591B2D3D4D67553506D /* AnalyticsClientProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsClientProtocol.swift; sourceTree = "<group>"; };
E4103AB4340F2974D690A12A /* CallScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2691,6 +2693,7 @@
3BAC027034248429A438886B /* AppMediatorMock.swift */,
E2F96CCBEAAA7F2185BFA354 /* ClientProxyMock.swift */,
4E600B315B920B9687F8EE1B /* ComposerDraftServiceMock.swift */,
E321E840DCC63790049984F4 /* ElementCallServiceMock.swift */,
382B50F7E379B3DBBD174364 /* NotificationSettingsProxyMock.swift */,
B2AD8A56CD37E23071A2F4BF /* PHGPostHogMock.swift */,
D38391154120264910D19528 /* PollMock.swift */,
Expand Down Expand Up @@ -6041,6 +6044,7 @@
AE1160076F663BF14E0E893A /* EffectsView.swift in Sources */,
FE4593FC2A02AAF92E089565 /* ElementAnimations.swift in Sources */,
5732395A4F71F51F9C754C5A /* ElementCallService.swift in Sources */,
8E7A902CA16E24928F83646C /* ElementCallServiceMock.swift in Sources */,
48416BBEB8DDF3E4DED0EDB6 /* ElementCallServiceProtocol.swift in Sources */,
07CC13C5729C24255348CBBD /* ElementCallWidgetDriver.swift in Sources */,
370AF5BFCD4384DD455479B6 /* ElementCallWidgetDriverProtocol.swift in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
.receive(on: DispatchQueue.main)
.sink { [weak self] action in
switch action {
case .answerCall(let roomID):
case .startCall(let roomID):
self?.handleAppRoute(.call(roomID: roomID))
case .declineCall:
break
case .endCall:
break // Handled internally in the UserSessionFlowCoordinator
}
}
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}
}
.store(in: &cancellables)

elementCallService.actions
.receive(on: DispatchQueue.main)
.sink { [weak self] action in
switch action {
case .startCall:
break
case .endCall:
self?.dismissCallScreenIfNeeded()
}
}
.store(in: &cancellables)
}

func start() {
Expand Down Expand Up @@ -569,6 +581,14 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
presentCallScreen(roomProxy: roomProxy)
}

private func dismissCallScreenIfNeeded() {
guard navigationSplitCoordinator.sheetCoordinator is CallScreenCoordinator else {
return
}

navigationSplitCoordinator.setSheetCoordinator(nil)
}

// MARK: Secure backup confirmation

private func presentSecureBackupLogoutConfirmationScreen() {
Expand Down
28 changes: 28 additions & 0 deletions ElementX/Sources/Mocks/ElementCallServiceMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine
import Foundation

struct ElementCallServiceMockConfiguration { }

extension ElementCallServiceMock {
convenience init(_ configuration: ElementCallServiceMockConfiguration) {
self.init()

underlyingActions = PassthroughSubject().eraseToAnyPublisher()
}
}
32 changes: 16 additions & 16 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4697,44 +4697,44 @@ class ElementCallServiceMock: ElementCallServiceProtocol {

//MARK: - setupCallSession

var setupCallSessionTitleUnderlyingCallsCount = 0
var setupCallSessionTitleCallsCount: Int {
var setupCallSessionRoomIDRoomDisplayNameUnderlyingCallsCount = 0
var setupCallSessionRoomIDRoomDisplayNameCallsCount: Int {
get {
if Thread.isMainThread {
return setupCallSessionTitleUnderlyingCallsCount
return setupCallSessionRoomIDRoomDisplayNameUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = setupCallSessionTitleUnderlyingCallsCount
returnValue = setupCallSessionRoomIDRoomDisplayNameUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
setupCallSessionTitleUnderlyingCallsCount = newValue
setupCallSessionRoomIDRoomDisplayNameUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
setupCallSessionTitleUnderlyingCallsCount = newValue
setupCallSessionRoomIDRoomDisplayNameUnderlyingCallsCount = newValue
}
}
}
}
var setupCallSessionTitleCalled: Bool {
return setupCallSessionTitleCallsCount > 0
var setupCallSessionRoomIDRoomDisplayNameCalled: Bool {
return setupCallSessionRoomIDRoomDisplayNameCallsCount > 0
}
var setupCallSessionTitleReceivedTitle: String?
var setupCallSessionTitleReceivedInvocations: [String] = []
var setupCallSessionTitleClosure: ((String) async -> Void)?
var setupCallSessionRoomIDRoomDisplayNameReceivedArguments: (roomID: String, roomDisplayName: String)?
var setupCallSessionRoomIDRoomDisplayNameReceivedInvocations: [(roomID: String, roomDisplayName: String)] = []
var setupCallSessionRoomIDRoomDisplayNameClosure: ((String, String) async -> Void)?

func setupCallSession(title: String) async {
setupCallSessionTitleCallsCount += 1
setupCallSessionTitleReceivedTitle = title
func setupCallSession(roomID: String, roomDisplayName: String) async {
setupCallSessionRoomIDRoomDisplayNameCallsCount += 1
setupCallSessionRoomIDRoomDisplayNameReceivedArguments = (roomID: roomID, roomDisplayName: roomDisplayName)
DispatchQueue.main.async {
self.setupCallSessionTitleReceivedInvocations.append(title)
self.setupCallSessionRoomIDRoomDisplayNameReceivedInvocations.append((roomID: roomID, roomDisplayName: roomDisplayName))
}
await setupCallSessionTitleClosure?(title)
await setupCallSessionRoomIDRoomDisplayNameClosure?(roomID, roomDisplayName)
}
//MARK: - tearDownCallSession

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
return
}

await elementCallService.setupCallSession(title: roomProxy.roomTitle)
await elementCallService.setupCallSession(roomID: roomProxy.id, roomDisplayName: roomProxy.roomTitle)

let _ = await roomProxy.sendCallNotificationIfNeeeded()
}
Expand All @@ -128,15 +128,15 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol

private func hangUp() async {
let hangUpMessage = """
"api":"toWidget",
{"api":"fromWidget",
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved
"widgetId":"\(widgetDriver.widgetID)",
"requestId":"widgetapi-\(UUID())",
"action":"im.vector.hangup",
"data":{}
"data":{}}
"""

let result = await widgetDriver.sendMessage(hangUpMessage)
MXLog.error("Result yo: \(result)")
MXLog.info("Sent hangUp message with result: \(result)")
}

private static let eventHandlerName = "elementx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct CallScreen_Previews: PreviewProvider {

roomProxy.elementCallWidgetDriverReturnValue = widgetDriver

return CallScreenViewModel(elementCallService: ElementCallServiceMock(),
return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()),
roomProxy: roomProxy,
callBaseURL: "https://call.element.io",
clientID: "io.element.elementx")
Expand Down
Loading
Loading