Make Element Call widget URL configurable (#2971)

This commit is contained in:
Stefan Ceriu
2024-07-02 11:35:05 +03:00
committed by GitHub
parent 78b0c7068d
commit b2c9878df6
15 changed files with 342 additions and 114 deletions
@@ -19,9 +19,11 @@ import SwiftUI
struct CallScreenCoordinatorParameters {
let elementCallService: ElementCallServiceProtocol
let clientProxy: ClientProxyProtocol
let roomProxy: RoomProxyProtocol
let callBaseURL: URL
let clientID: String
let elementCallBaseURL: URL
let elementCallBaseURLOverride: URL?
}
enum CallScreenCoordinatorAction {
@@ -39,9 +41,11 @@ final class CallScreenCoordinator: CoordinatorProtocol {
init(parameters: CallScreenCoordinatorParameters) {
viewModel = CallScreenViewModel(elementCallService: parameters.elementCallService,
clientProxy: parameters.clientProxy,
roomProxy: parameters.roomProxy,
callBaseURL: parameters.callBaseURL,
clientID: parameters.clientID)
clientID: parameters.clientID,
elementCallBaseURL: parameters.elementCallBaseURL,
elementCallBaseURLOverride: parameters.elementCallBaseURLOverride)
}
func start() {
@@ -38,9 +38,11 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
/// - callBaseURL: Which Element Call instance should be used
/// - clientID: Something to identify the current client on the Element Call side
init(elementCallService: ElementCallServiceProtocol,
clientProxy: ClientProxyProtocol,
roomProxy: RoomProxyProtocol,
callBaseURL: URL,
clientID: String) {
clientID: String,
elementCallBaseURL: URL,
elementCallBaseURLOverride: URL?) {
self.elementCallService = elementCallService
self.roomProxy = roomProxy
@@ -90,7 +92,15 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
.store(in: &cancellables)
Task {
switch await widgetDriver.start(baseURL: callBaseURL, clientID: clientID) {
let baseURL = if let elementCallBaseURLOverride {
elementCallBaseURLOverride
} else if case .success(let wellKnown) = await clientProxy.getElementWellKnown(), let wellKnownCall = wellKnown?.call {
wellKnownCall.widgetURL
} else {
elementCallBaseURL
}
switch await widgetDriver.start(baseURL: baseURL, clientID: clientID) {
case .success(let url):
state.url = url
case .failure(let error):
@@ -172,7 +172,11 @@ private struct WebView: UIViewRepresentable {
struct CallScreen_Previews: PreviewProvider {
static let viewModel = {
let clientProxy = ClientProxyMock()
clientProxy.getElementWellKnownReturnValue = .success(nil)
let roomProxy = RoomProxyMock()
roomProxy.sendCallNotificationIfNeeededReturnValue = .success(())
let widgetDriver = ElementCallWidgetDriverMock()
widgetDriver.underlyingMessagePublisher = .init()
@@ -182,9 +186,11 @@ struct CallScreen_Previews: PreviewProvider {
roomProxy.elementCallWidgetDriverReturnValue = widgetDriver
return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()),
clientProxy: clientProxy,
roomProxy: roomProxy,
callBaseURL: "https://call.element.io",
clientID: "io.element.elementx")
clientID: "io.element.elementx",
elementCallBaseURL: "https://call.element.io",
elementCallBaseURLOverride: nil)
}()
static var previews: some View {
@@ -32,7 +32,8 @@ final class DeveloperOptionsScreenCoordinator: CoordinatorProtocol {
}
init() {
viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings)
viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings,
elementCallBaseURL: ServiceLocator.shared.settings.elementCallBaseURL)
viewModel.actions
.sink { [weak self] action in
@@ -21,6 +21,7 @@ enum DeveloperOptionsScreenViewModelAction {
}
struct DeveloperOptionsScreenViewState: BindableState {
let elementCallBaseURL: URL
var bindings: DeveloperOptionsScreenViewStateBindings
}
@@ -46,7 +47,7 @@ enum DeveloperOptionsScreenViewAction {
protocol DeveloperOptionsProtocol: AnyObject {
var logLevel: TracingConfiguration.LogLevel { get set }
var hideUnreadMessagesBadge: Bool { get set }
var elementCallBaseURL: URL { get set }
var elementCallBaseURLOverride: URL? { get set }
var fuzzyRoomListSearchEnabled: Bool { get set }
}
@@ -26,9 +26,9 @@ class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, Deve
actionsSubject.eraseToAnyPublisher()
}
init(developerOptions: DeveloperOptionsProtocol) {
init(developerOptions: DeveloperOptionsProtocol, elementCallBaseURL: URL) {
let bindings = DeveloperOptionsScreenViewStateBindings(developerOptions: developerOptions)
let state = DeveloperOptionsScreenViewState(bindings: bindings)
let state = DeveloperOptionsScreenViewState(elementCallBaseURL: elementCallBaseURL, bindings: bindings)
super.init(initialViewState: state)
}
@@ -38,14 +38,11 @@ struct DeveloperOptionsScreen: View {
}
Section("Element Call") {
TextField(context.elementCallBaseURL.absoluteString, text: $elementCallBaseURLString)
TextField(context.viewState.elementCallBaseURL.absoluteString, text: $elementCallBaseURLString)
.submitLabel(.done)
.onSubmit {
guard let url = URL(string: elementCallBaseURLString) else {
return
}
context.elementCallBaseURL = url
guard let url = URL(string: elementCallBaseURLString) else { return }
context.elementCallBaseURLOverride = url
}
.autocorrectionDisabled(true)
.autocapitalization(.none)
@@ -148,7 +145,8 @@ private struct LogLevelConfigurationView: View {
// MARK: - Previews
struct DeveloperOptionsScreen_Previews: PreviewProvider {
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings)
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings,
elementCallBaseURL: ServiceLocator.shared.settings.elementCallBaseURL)
static var previews: some View {
NavigationStack {
DeveloperOptionsScreen(context: viewModel.context)