Skip to main content

ruma_events/call/member/
focus.rs

1//! Types for MatrixRTC Focus/SFU configurations.
2
3use ruma_macros::StringEnum;
4use serde::{Deserialize, Serialize};
5
6use crate::PrivOwnedStr;
7
8/// Description of the SFU/Focus a membership can be connected to.
9///
10/// A focus can be any server powering the MatrixRTC session (SFU,
11/// MCU). It serves as a node to redistribute RTC streams.
12#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
13#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
14#[serde(tag = "type", rename_all = "snake_case")]
15pub enum Focus {
16    /// LiveKit is one possible type of SFU/Focus that can be used for a MatrixRTC session.
17    Livekit(LivekitFocus),
18}
19
20/// The struct to describe LiveKit as a `preferred_foci`.
21#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
22#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
23pub struct LivekitFocus {
24    /// The alias where the LiveKit sessions can be reached.
25    #[serde(rename = "livekit_alias")]
26    #[deprecated = "Newer versions of Element Call won't fill this field anymore."]
27    pub alias: Option<String>,
28
29    /// The URL of the JWT service for the LiveKit instance.
30    #[serde(rename = "livekit_service_url")]
31    pub service_url: String,
32}
33
34impl LivekitFocus {
35    /// Initialize a [`LivekitFocus`].
36    ///
37    /// # Arguments
38    ///
39    /// * `alias` - The alias with which the LiveKit sessions can be reached.
40    /// * `service_url` - The url of the JWT server for the LiveKit instance.
41    #[allow(deprecated)]
42    pub fn new(alias: Option<String>, service_url: String) -> Self {
43        Self { alias, service_url }
44    }
45}
46
47/// Data to define the actively used Focus.
48///
49/// A focus can be any server powering the MatrixRTC session (SFU,
50/// MCU). It serves as a node to redistribute RTC streams.
51#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
52#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
53#[serde(tag = "type", rename_all = "snake_case")]
54pub enum ActiveFocus {
55    /// LiveKit is one possible type of SFU/Focus that can be used for a MatrixRTC session.
56    Livekit(ActiveLivekitFocus),
57}
58
59/// The fields to describe the `active_foci`.
60#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
61#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
62pub struct ActiveLivekitFocus {
63    /// The selection method used to select the LiveKit focus for the rtc session.
64    pub focus_selection: FocusSelection,
65}
66
67impl ActiveLivekitFocus {
68    /// Initialize a [`ActiveLivekitFocus`].
69    ///
70    /// # Arguments
71    ///
72    /// * `focus_selection` - The selection method used to select the LiveKit focus for the rtc
73    ///   session.
74    pub fn new() -> Self {
75        Self { focus_selection: FocusSelection::OldestMembership }
76    }
77}
78
79/// How to select the active focus for LiveKit
80#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
81#[derive(Clone, StringEnum)]
82#[ruma_enum(rename_all = "snake_case")]
83#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
84pub enum FocusSelection {
85    /// Select the active focus by using the oldest membership and the oldest focus.
86    OldestMembership,
87
88    #[doc(hidden)]
89    _Custom(PrivOwnedStr),
90}