From 585ae29868c1d2f079602beee699b3da9b2103b8 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 25 Jun 2025 12:43:34 +0200 Subject: [PATCH] refactor(uniffi): make the sdk widget config struct derive `uniffi`. This allows to not duplicate the struct in the uniffi crate. --- bindings/matrix-sdk-ffi/src/widget.rs | 172 +----------------- .../src/widget/settings/element_call.rs | 8 +- 2 files changed, 6 insertions(+), 174 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/widget.rs b/bindings/matrix-sdk-ffi/src/widget.rs index 5c57061af..48ec4ca66 100644 --- a/bindings/matrix-sdk-ffi/src/widget.rs +++ b/bindings/matrix-sdk-ffi/src/widget.rs @@ -110,174 +110,6 @@ pub async fn generate_webview_url( .map(|url| url.to_string())?) } -/// Defines if a call is encrypted and which encryption system should be used. -/// -/// This controls the url parameters: `perParticipantE2EE`, `password`. -#[derive(uniffi::Enum, Clone)] -pub enum EncryptionSystem { - /// Equivalent to the element call url parameter: `enableE2EE=false` - Unencrypted, - /// Equivalent to the element call url parameter: - /// `perParticipantE2EE=true` - PerParticipantKeys, - /// Equivalent to the element call url parameter: - /// `password={secret}` - SharedSecret { - /// The secret/password which is used in the url. - secret: String, - }, -} - -impl From for matrix_sdk::widget::EncryptionSystem { - fn from(value: EncryptionSystem) -> Self { - match value { - EncryptionSystem::Unencrypted => Self::Unencrypted, - EncryptionSystem::PerParticipantKeys => Self::PerParticipantKeys, - EncryptionSystem::SharedSecret { secret } => Self::SharedSecret { secret }, - } - } -} - -/// Defines the intent of showing the call. -/// -/// This controls whether to show or skip the lobby. -#[derive(uniffi::Enum, Clone)] -pub enum Intent { - /// The user wants to start a call. - StartCall, - /// The user wants to join an existing call. - JoinExisting, -} -impl From for matrix_sdk::widget::Intent { - fn from(value: Intent) -> Self { - match value { - Intent::StartCall => Self::StartCall, - Intent::JoinExisting => Self::JoinExisting, - } - } -} - -/// Properties to create a new virtual Element Call widget. -#[derive(uniffi::Record, Clone)] -pub struct VirtualElementCallWidgetOptions { - /// The url to the Element Call app including any `/room` path if required. - /// - /// E.g. , , - pub element_call_url: String, - - /// The widget id. - pub widget_id: String, - - /// The url that is used as the target for the PostMessages sent - /// by the widget (to the client). - /// - /// For a web app client this is the client url. In case of using other - /// platforms the client most likely is setup up to listen to - /// postmessages in the same webview the widget is hosted. In this case - /// the `parent_url` is set to the url of the webview with the widget. Be - /// aware that this means that the widget will receive its own postmessage - /// messages. The `matrix-widget-api` (js) ignores those so this works but - /// it might break custom implementations. - /// - /// Defaults to `element_call_url` for the non-iframe (dedicated webview) - /// usecase. - pub parent_url: Option, - - /// Whether the branding header of Element call should be hidden. - /// - /// Default: `true` - pub hide_header: Option, - - /// If set, the lobby will be skipped and the widget will join the - /// call on the `io.element.join` action. - /// - /// Default: `false` - pub preload: Option, - - /// The font scale which will be used inside element call. - /// - /// Default: `1` - pub font_scale: Option, - - /// Whether element call should prompt the user to open in the browser or - /// the app. - /// - /// Default: `false` - pub app_prompt: Option, - - /// Make it not possible to get to the calls list in the webview. - /// - /// Default: `true` - pub confine_to_room: Option, - - /// The font to use, to adapt to the system font. - pub font: Option, - - /// The encryption system to use. - /// - /// Use `EncryptionSystem::Unencrypted` to disable encryption. - pub encryption: EncryptionSystem, - - /// The intent of showing the call. - /// If the user wants to start a call or join an existing one. - /// Controls if the lobby is skipped or not. - pub intent: Option, - - /// Do not show the screenshare button. - pub hide_screensharing: bool, - - /// Can be used to pass a PostHog id to element call. - pub posthog_user_id: Option, - /// The host of the posthog api. - /// Supported since Element Call v0.9.0. Only used by the embedded package. - pub posthog_api_host: Option, - /// The key for the posthog api. - /// Supported since Element Call v0.9.0. Only used by the embedded package. - pub posthog_api_key: Option, - - /// The url to use for submitting rageshakes. - /// Supported since Element Call v0.9.0. Only used by the embedded package. - pub rageshake_submit_url: Option, - - /// Sentry [DSN](https://docs.sentry.io/concepts/key-terms/dsn-explainer/) - /// Supported since Element Call v0.9.0. Only used by the embedded package. - pub sentry_dsn: Option, - /// Sentry [environment](https://docs.sentry.io/concepts/key-terms/key-terms/) - /// Supported since Element Call v0.9.0. Only used by the embedded package. - pub sentry_environment: Option, - //// - `true`: The webview should show the list of media devices it detects using - //// `enumerateDevices`. - /// - `false`: the webview shows a a list of devices injected by the - /// client. (used on ios & android) - pub controlled_media_devices: bool, -} - -impl From for matrix_sdk::widget::VirtualElementCallWidgetOptions { - fn from(value: VirtualElementCallWidgetOptions) -> Self { - Self { - element_call_url: value.element_call_url, - widget_id: value.widget_id, - parent_url: value.parent_url, - hide_header: value.hide_header, - preload: value.preload, - font_scale: value.font_scale, - app_prompt: value.app_prompt, - confine_to_room: value.confine_to_room, - font: value.font, - posthog_user_id: value.posthog_user_id, - encryption: value.encryption.into(), - intent: value.intent.map(Into::into), - hide_screensharing: value.hide_screensharing, - posthog_api_host: value.posthog_api_host, - posthog_api_key: value.posthog_api_key, - rageshake_submit_url: value.rageshake_submit_url, - sentry_dsn: value.sentry_dsn, - sentry_environment: value.sentry_environment, - controlled_media_devices: value.controlled_media_devices, - } - } -} - /// `WidgetSettings` are usually created from a state event. /// (currently unimplemented) /// @@ -293,9 +125,9 @@ impl From for matrix_sdk::widget::VirtualElemen /// call widget. #[matrix_sdk_ffi_macros::export] pub fn new_virtual_element_call_widget( - props: VirtualElementCallWidgetOptions, + props: matrix_sdk::widget::VirtualElementCallWidgetOptions, ) -> Result { - Ok(matrix_sdk::widget::WidgetSettings::new_virtual_element_call_widget(props.into()) + Ok(matrix_sdk::widget::WidgetSettings::new_virtual_element_call_widget(props) .map(|w| w.into())?) } diff --git a/crates/matrix-sdk/src/widget/settings/element_call.rs b/crates/matrix-sdk/src/widget/settings/element_call.rs index cacba712f..54f3c7227 100644 --- a/crates/matrix-sdk/src/widget/settings/element_call.rs +++ b/crates/matrix-sdk/src/widget/settings/element_call.rs @@ -45,7 +45,7 @@ struct ElementCallParams { skip_lobby: Option, confine_to_room: bool, app_prompt: bool, - hide_header: bool, + header: HeaderStyle, preload: bool, /// Deprecated since Element Call v0.9.0. Included for backwards /// compatibility. Set to the same as `posthog_user_id`. @@ -76,7 +76,7 @@ struct ElementCallParams { /// Defines if a call is encrypted and which encryption system should be used. /// /// This controls the url parameters: `perParticipantE2EE`, `password`. -#[derive(Debug, PartialEq, Default)] +#[derive(Debug, PartialEq, Default, uniffi::Enum, Clone)] pub enum EncryptionSystem { /// Equivalent to the element call url parameter: `perParticipantE2EE=false` /// and no password. @@ -96,7 +96,7 @@ pub enum EncryptionSystem { /// Defines the intent of showing the call. /// /// This controls whether to show or skip the lobby. -#[derive(Debug, PartialEq, Serialize, Default)] +#[derive(Debug, PartialEq, Serialize, Default, uniffi::Enum, Clone)] #[serde(rename_all = "snake_case")] pub enum Intent { #[default] @@ -107,7 +107,7 @@ pub enum Intent { } /// Properties to create a new virtual Element Call widget. -#[derive(Debug, Default)] +#[derive(Debug, Default, uniffi::Record, Clone)] pub struct VirtualElementCallWidgetOptions { /// The url to the app. ///