Skip to content
Snippets Groups Projects
Unverified Commit 60024c78 authored by Mauro's avatar Mauro Committed by GitHub
Browse files

Embed element call (#3939)


* it works but only with the baseURL for now

* works but strings are not referenced properly

and we are using a dummy config.json which maybe is not required at all?

* test with EmbeddedElementCall repo

* updated the version

* ignore our own package

* updated version

removed using EC through the well known URL

* fix for remote URL overriding

* updated version

* fix for microphone and camera using local URL

* better solution

* Use version 0.9.0-release-test.3

* fix project

* removed workaround for emebedded EC url generation

* updated EC

* pr suggestions

* fix

* removed unnecessary configuration flag

---------

Co-authored-by: default avatarHugh Nimmo-Smith <hughns@element.io>
parent 791ce678
Branches
Tags nightly/25.03.6.873 release/25.03.6
No related merge requests found
...@@ -9,7 +9,7 @@ then ...@@ -9,7 +9,7 @@ then
exit 1 exit 1
fi fi
swift-package-list ElementX.xcodeproj --requires-license --ignore-package compound-ios --ignore-package compound-design-tokens --ignore-package matrix-rich-text-editor-swift --output-type settings-bundle --output-path ElementX/SupportingFiles swift-package-list ElementX.xcodeproj --requires-license --ignore-package compound-ios --ignore-package compound-design-tokens --ignore-package matrix-rich-text-editor-swift --ignore-package element-call-swift --output-type settings-bundle --output-path ElementX/SupportingFiles
if ! git diff --quiet -- ./ElementX/SupportingFiles/Settings.bundle || [ -n "$(git ls-files --others --exclude-standard -- ./ElementX/SupportingFiles/Settings.bundle)" ]; then if ! git diff --quiet -- ./ElementX/SupportingFiles/Settings.bundle || [ -n "$(git ls-files --others --exclude-standard -- ./ElementX/SupportingFiles/Settings.bundle)" ]; then
echo "pre-commit: Commit aborted due to unstaged changes to the package Acknowledgements." echo "pre-commit: Commit aborted due to unstaged changes to the package Acknowledgements."
exit 1 exit 1
......
This diff is collapsed.
{ {
"originHash" : "f9011692b20e61e6f0df94b6e0946a4c8f4d58429a88998f249712bb1fee47f1", "originHash" : "cb4b4c28930e04929217c9570b7f82a1dc8e3dc51e3f956f11584dbae9bac079",
"pins" : [ "pins" : [
{ {
"identity" : "compound-design-tokens", "identity" : "compound-design-tokens",
...@@ -54,6 +54,15 @@ ...@@ -54,6 +54,15 @@
"version" : "1.7.18" "version" : "1.7.18"
} }
}, },
{
"identity" : "element-call-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/element-call-swift",
"state" : {
"revision" : "101bdac7a5f9c53f702065bac7772e9dedb26c62",
"version" : "0.9.0-rc.3"
}
},
{ {
"identity" : "emojibase-bindings", "identity" : "emojibase-bindings",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
// Please see LICENSE files in the repository root for full details. // Please see LICENSE files in the repository root for full details.
// //
#if canImport(EmbeddedElementCall)
import EmbeddedElementCall
#endif
import Foundation import Foundation
import SwiftUI import SwiftUI
...@@ -267,7 +271,8 @@ final class AppSettings { ...@@ -267,7 +271,8 @@ final class AppSettings {
// MARK: - Element Call // MARK: - Element Call
let elementCallBaseURL: URL = "https://call.element.io/room" // swiftlint:disable:next force_unwrapping
let elementCallBaseURL: URL = EmbeddedElementCall.appURL!
// These are publicly availble on https://call.element.io so we don't neeed to treat them as secrets // These are publicly availble on https://call.element.io so we don't neeed to treat them as secrets
let elementCallPosthogAPIHost = "https://posthog-element-call.element.io" let elementCallPosthogAPIHost = "https://posthog-element-call.element.io"
......
...@@ -148,8 +148,6 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol ...@@ -148,8 +148,6 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
let baseURL = if let elementCallBaseURLOverride { let baseURL = if let elementCallBaseURLOverride {
elementCallBaseURLOverride elementCallBaseURLOverride
} else if case .success(let wellKnown) = await clientProxy.getElementWellKnown(), let wellKnownCall = wellKnown?.call {
wellKnownCall.widgetURL
} else { } else {
elementCallBaseURL elementCallBaseURL
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import AVKit import AVKit
import Combine import Combine
import EmbeddedElementCall
import SFSafeSymbols import SFSafeSymbols
import SwiftUI import SwiftUI
import WebKit import WebKit
...@@ -98,6 +99,8 @@ private struct CallView: UIViewRepresentable { ...@@ -98,6 +99,8 @@ private struct CallView: UIViewRepresentable {
let userContentController = WKUserContentController() let userContentController = WKUserContentController()
userContentController.add(WKScriptMessageHandlerWrapper(self), name: viewModelContext.viewState.messageHandler) userContentController.add(WKScriptMessageHandlerWrapper(self), name: viewModelContext.viewState.messageHandler)
// Required to allow a webview that uses file URL to load its own assets
configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
configuration.userContentController = userContentController configuration.userContentController = userContentController
configuration.allowsInlineMediaPlayback = true configuration.allowsInlineMediaPlayback = true
configuration.allowsPictureInPictureMediaPlayback = true configuration.allowsPictureInPictureMediaPlayback = true
...@@ -133,8 +136,13 @@ private struct CallView: UIViewRepresentable { ...@@ -133,8 +136,13 @@ private struct CallView: UIViewRepresentable {
func load(_ url: URL) { func load(_ url: URL) {
self.url = url self.url = url
let request = URLRequest(url: url) // The only file URL we allow is the one coming from our own local ElementCall bundle, so it's okay to allow read permission only to our local EC bundle
webView.load(request) if url.isFileURL {
webView.loadFileURL(url, allowingReadAccessTo: EmbeddedElementCall.bundle.bundleURL)
} else {
let request = URLRequest(url: url)
webView.load(request)
}
} }
func evaluateJavaScript(_ script: String) async throws -> Any? { func evaluateJavaScript(_ script: String) async throws -> Any? {
...@@ -159,8 +167,8 @@ private struct CallView: UIViewRepresentable { ...@@ -159,8 +167,8 @@ private struct CallView: UIViewRepresentable {
// MARK: - WKUIDelegate // MARK: - WKUIDelegate
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 // Allow if the origin is local, otherwise don't allow permissions for domains different than what the call was started on
guard origin.host == url.host else { guard origin.protocol == "file" || origin.host == url.host else {
return .deny return .deny
} }
...@@ -174,9 +182,16 @@ private struct CallView: UIViewRepresentable { ...@@ -174,9 +182,16 @@ private struct CallView: 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. if let navigationURL = navigationAction.request.url {
if navigationAction.request.url?.host == url.host { // Do not allow navigation to a different URL scheme.
return .allow if navigationURL.scheme != url.scheme {
return .cancel
}
// Allow any content from the main URL.
if navigationURL.host == url.host {
return .allow
}
} }
// Additionally allow any embedded content such as captchas. // Additionally allow any embedded content such as captchas.
......
...@@ -73,7 +73,7 @@ struct DeveloperOptionsScreen: View { ...@@ -73,7 +73,7 @@ struct DeveloperOptionsScreen: View {
} }
Section { Section {
TextField(context.viewState.elementCallBaseURL.absoluteString, text: $elementCallURLOverrideString) TextField("Leave empty to use EC locally", text: $elementCallURLOverrideString)
.autocorrectionDisabled(true) .autocorrectionDisabled(true)
.autocapitalization(.none) .autocapitalization(.none)
.foregroundColor(URL(string: elementCallURLOverrideString) == nil ? .red : .primary) .foregroundColor(URL(string: elementCallURLOverrideString) == nil ? .red : .primary)
...@@ -86,11 +86,7 @@ struct DeveloperOptionsScreen: View { ...@@ -86,11 +86,7 @@ struct DeveloperOptionsScreen: View {
} }
} }
} header: { } header: {
Text("Element Call") Text("Element Call remote URL override")
} footer: {
if context.elementCallBaseURLOverride == nil {
Text("The call URL may be overridden by your homeserver.")
}
} }
Section { Section {
......
...@@ -9,20 +9,9 @@ import Foundation ...@@ -9,20 +9,9 @@ import Foundation
import MatrixRustSDK import MatrixRustSDK
struct ElementWellKnown { struct ElementWellKnown {
struct Call {
let widgetURL: URL
init?(_ wellKnown: MatrixRustSDK.ElementCallWellKnown) {
guard let widgetURL = URL(string: wellKnown.widgetUrl) else { return nil }
self.widgetURL = widgetURL
}
}
let call: Call?
let registrationHelperURL: URL? let registrationHelperURL: URL?
init?(_ wellKnown: MatrixRustSDK.ElementWellKnown) { init?(_ wellKnown: MatrixRustSDK.ElementWellKnown) {
call = wellKnown.call.flatMap(Call.init)
registrationHelperURL = wellKnown.registrationHelperUrl.flatMap(URL.init) registrationHelperURL = wellKnown.registrationHelperUrl.flatMap(URL.init)
} }
} }
...@@ -214,6 +214,7 @@ targets: ...@@ -214,6 +214,7 @@ targets:
- package: Collections - package: Collections
- package: DeviceKit - package: DeviceKit
- package: DTCoreText - package: DTCoreText
- package: EmbeddedElementCall
- package: KeychainAccess - package: KeychainAccess
- package: Kingfisher - package: Kingfisher
- package: KZFileWatchers - package: KZFileWatchers
......
...@@ -81,6 +81,9 @@ packages: ...@@ -81,6 +81,9 @@ packages:
url: https://github.com/element-hq/matrix-rich-text-editor-swift url: https://github.com/element-hq/matrix-rich-text-editor-swift
exactVersion: 2.37.12 exactVersion: 2.37.12
# path: ../matrix-rich-text-editor/platforms/ios/lib/WysiwygComposer # path: ../matrix-rich-text-editor/platforms/ios/lib/WysiwygComposer
EmbeddedElementCall:
url: https://github.com/element-hq/element-call-swift
exactVersion: 0.9.0-rc.3
# External dependencies # External dependencies
Algorithms: Algorithms:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment