Pass in custom call URL query parameters

This commit is contained in:
Stefan Ceriu
2023-09-25 09:18:26 +03:00
parent 44c6da7ce6
commit 01d7134075
@@ -17,14 +17,19 @@
import SwiftUI import SwiftUI
import WebKit import WebKit
struct GenericLinkCoordinatorParameters { struct GenericCallLinkCoordinatorParameters {
let url: URL let url: URL
} }
class GenericCallLinkCoordinator: CoordinatorProtocol { private enum GenericCallLinkQueryParameters {
private let parameters: GenericLinkCoordinatorParameters static let appPrompt = "appPrompt"
static let confineToRoom = "confineToRoom"
}
init(parameters: GenericLinkCoordinatorParameters) { class GenericCallLinkCoordinator: CoordinatorProtocol {
private let parameters: GenericCallLinkCoordinatorParameters
init(parameters: GenericCallLinkCoordinatorParameters) {
self.parameters = parameters self.parameters = parameters
} }
@@ -45,7 +50,7 @@ private struct WebView: UIViewRepresentable {
} }
func makeCoordinator() -> Coordinator { func makeCoordinator() -> Coordinator {
Coordinator(initialURL: url) Coordinator(url: url)
} }
func updateUIView(_ webView: WKWebView, context: Context) { func updateUIView(_ webView: WKWebView, context: Context) {
@@ -54,11 +59,28 @@ private struct WebView: UIViewRepresentable {
@MainActor @MainActor
class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate { class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate {
private let initialURL: URL private let url: URL
private(set) var webView: WKWebView! private(set) var webView: WKWebView!
init(initialURL: URL) { init(url: URL) {
self.initialURL = initialURL if var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true) {
urlComponents.queryItems?.removeAll { $0.name == GenericCallLinkQueryParameters.appPrompt }
urlComponents.queryItems?.removeAll { $0.name == GenericCallLinkQueryParameters.confineToRoom }
urlComponents.queryItems?.append(.init(name: GenericCallLinkQueryParameters.appPrompt, value: "false"))
urlComponents.queryItems?.append(.init(name: GenericCallLinkQueryParameters.confineToRoom, value: "true"))
if let adjustedURL = urlComponents.url {
self.url = adjustedURL
} else {
MXLog.error("Failed adjusting URL with components: \(urlComponents)")
self.url = url
}
} else {
MXLog.error("Failed constructing URL components for url: \(url)")
self.url = url
}
super.init() super.init()
let configuration = WKWebViewConfiguration() let configuration = WKWebViewConfiguration()
@@ -74,7 +96,7 @@ private struct WebView: UIViewRepresentable {
func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision { func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision {
// Don't allow permissions for domains different than what the call was started on // Don't allow permissions for domains different than what the call was started on
guard origin.host == initialURL.host else { guard origin.host == url.host else {
return .deny return .deny
} }
@@ -85,7 +107,7 @@ private struct WebView: UIViewRepresentable {
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
// Allow any content from the main URL. // Allow any content from the main URL.
if navigationAction.request.url?.host == initialURL.host { if navigationAction.request.url?.host == url.host {
return .allow return .allow
} }