mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
refactor(uniffi): make the sdk widget config struct derive uniffi.
This allows to not duplicate the struct in the uniffi crate.
This commit is contained in:
@@ -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<EncryptionSystem> 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<Intent> 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. <https://call.element.io>, <https://call.element.dev>, <https://call.element.dev/room>
|
||||
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<String>,
|
||||
|
||||
/// Whether the branding header of Element call should be hidden.
|
||||
///
|
||||
/// Default: `true`
|
||||
pub hide_header: Option<bool>,
|
||||
|
||||
/// 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<bool>,
|
||||
|
||||
/// The font scale which will be used inside element call.
|
||||
///
|
||||
/// Default: `1`
|
||||
pub font_scale: Option<f64>,
|
||||
|
||||
/// Whether element call should prompt the user to open in the browser or
|
||||
/// the app.
|
||||
///
|
||||
/// Default: `false`
|
||||
pub app_prompt: Option<bool>,
|
||||
|
||||
/// Make it not possible to get to the calls list in the webview.
|
||||
///
|
||||
/// Default: `true`
|
||||
pub confine_to_room: Option<bool>,
|
||||
|
||||
/// The font to use, to adapt to the system font.
|
||||
pub font: Option<String>,
|
||||
|
||||
/// 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<Intent>,
|
||||
|
||||
/// 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<String>,
|
||||
/// The host of the posthog api.
|
||||
/// Supported since Element Call v0.9.0. Only used by the embedded package.
|
||||
pub posthog_api_host: Option<String>,
|
||||
/// The key for the posthog api.
|
||||
/// Supported since Element Call v0.9.0. Only used by the embedded package.
|
||||
pub posthog_api_key: Option<String>,
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
/// 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<String>,
|
||||
//// - `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<VirtualElementCallWidgetOptions> 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<VirtualElementCallWidgetOptions> 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<WidgetSettings, ParseError> {
|
||||
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())?)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ struct ElementCallParams {
|
||||
skip_lobby: Option<bool>,
|
||||
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.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user