feat: Add Element Call / MatrixRTC support
This commit is contained in:
committed by
Jason Volk
parent
888f72d8d0
commit
e1f89b69ea
@@ -51,5 +51,16 @@ pub(crate) async fn get_capabilities_route(
|
|||||||
json!({"enabled": services.config.forget_forced_upon_leave}),
|
json!({"enabled": services.config.forget_forced_upon_leave}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// MSC4143: MatrixRTC - advertise RTC transport support
|
||||||
|
if !services
|
||||||
|
.server
|
||||||
|
.config
|
||||||
|
.well_known
|
||||||
|
.rtc_transports
|
||||||
|
.is_empty()
|
||||||
|
{
|
||||||
|
capabilities.set("org.matrix.msc4143.rtc_foci", json!({"supported": true}))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(get_capabilities::v3::Response { capabilities })
|
Ok(get_capabilities::v3::Response { capabilities })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use axum::{Json, extract::State, response::IntoResponse};
|
use axum::{Json, extract::State, response::IntoResponse};
|
||||||
use ruma::api::client::discovery::{
|
use ruma::api::client::discovery::discover_support::{self, Contact};
|
||||||
discover_homeserver::{self, HomeserverInfo},
|
use serde_json::{Value, json};
|
||||||
discover_support::{self, Contact},
|
|
||||||
};
|
|
||||||
use tuwunel_core::{Err, Result};
|
use tuwunel_core::{Err, Result};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -10,20 +8,58 @@ use crate::Ruma;
|
|||||||
/// # `GET /.well-known/matrix/client`
|
/// # `GET /.well-known/matrix/client`
|
||||||
///
|
///
|
||||||
/// Returns the .well-known URL if it is configured, otherwise returns 404.
|
/// Returns the .well-known URL if it is configured, otherwise returns 404.
|
||||||
|
/// Also includes RTC transport configuration for Element Call (MSC4143).
|
||||||
pub(crate) async fn well_known_client(
|
pub(crate) async fn well_known_client(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
_body: Ruma<discover_homeserver::Request>,
|
) -> Result<Json<Value>> {
|
||||||
) -> Result<discover_homeserver::Response> {
|
|
||||||
let client_url = match services.server.config.well_known.client.as_ref() {
|
let client_url = match services.server.config.well_known.client.as_ref() {
|
||||||
| Some(url) => url.to_string(),
|
| Some(url) => url.to_string(),
|
||||||
| None => return Err!(Request(NotFound("Not found."))),
|
| None => return Err!(Request(NotFound("Not found."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(discover_homeserver::Response {
|
let mut response = json!({
|
||||||
homeserver: HomeserverInfo { base_url: client_url },
|
"m.homeserver": {
|
||||||
identity_server: None,
|
"base_url": client_url
|
||||||
tile_server: None,
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
// Add RTC transport configuration if available (MSC4143 / Element Call)
|
||||||
|
// Element Call has evolved through several versions with different field
|
||||||
|
// expectations
|
||||||
|
if !services
|
||||||
|
.server
|
||||||
|
.config
|
||||||
|
.well_known
|
||||||
|
.rtc_transports
|
||||||
|
.is_empty()
|
||||||
|
{
|
||||||
|
if let Some(obj) = response.as_object_mut() {
|
||||||
|
// Element Call expects "org.matrix.msc4143.rtc_foci" (not rtc_foci_preferred)
|
||||||
|
// with an array of transport objects
|
||||||
|
obj.insert(
|
||||||
|
"org.matrix.msc4143.rtc_foci".to_owned(),
|
||||||
|
json!(services.server.config.well_known.rtc_transports),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Also add the LiveKit URL directly for backward compatibility
|
||||||
|
if let Some(first_transport) = services
|
||||||
|
.server
|
||||||
|
.config
|
||||||
|
.well_known
|
||||||
|
.rtc_transports
|
||||||
|
.first()
|
||||||
|
{
|
||||||
|
if let Some(livekit_url) = first_transport.get("livekit_service_url") {
|
||||||
|
obj.insert(
|
||||||
|
"org.matrix.msc4143.livekit_service_url".to_owned(),
|
||||||
|
livekit_url.clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Json(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /.well-known/matrix/support`
|
/// # `GET /.well-known/matrix/support`
|
||||||
|
|||||||
@@ -190,7 +190,8 @@ pub fn build(router: Router<State>, server: &Server) -> Router<State> {
|
|||||||
get(client::get_room_summary_legacy)
|
get(client::get_room_summary_legacy)
|
||||||
)
|
)
|
||||||
.ruma_route(&client::well_known_support)
|
.ruma_route(&client::well_known_support)
|
||||||
.ruma_route(&client::well_known_client)
|
// this is the only thing currently needed to support Element Video Rooms / Calls.
|
||||||
|
.route("/.well-known/matrix/client", get(client::well_known_client))
|
||||||
.route("/_tuwunel/server_version", get(client::tuwunel_server_version))
|
.route("/_tuwunel/server_version", get(client::tuwunel_server_version))
|
||||||
.ruma_route(&client::room_initial_sync_route)
|
.ruma_route(&client::room_initial_sync_route)
|
||||||
.route("/client/server.json", get(client::syncv3_client_server_json));
|
.route("/client/server.json", get(client::syncv3_client_server_json));
|
||||||
|
|||||||
@@ -2146,6 +2146,26 @@ pub struct WellKnownConfig {
|
|||||||
///
|
///
|
||||||
/// example "@admin:example.com"
|
/// example "@admin:example.com"
|
||||||
pub support_mxid: Option<OwnedUserId>,
|
pub support_mxid: Option<OwnedUserId>,
|
||||||
|
|
||||||
|
/// Element Call / MatrixRTC configuration (MSC4143).
|
||||||
|
/// Configures the LiveKit SFU server for voice/video calls.
|
||||||
|
///
|
||||||
|
/// Requires a LiveKit server with JWT authentication.
|
||||||
|
/// The `livekit_service_url` should point to your LiveKit JWT endpoint.
|
||||||
|
///
|
||||||
|
/// Note: You must also set `client` above to your homeserver URL.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```toml
|
||||||
|
/// [global.well_known]
|
||||||
|
/// client = "https://matrix.yourdomain.com"
|
||||||
|
///
|
||||||
|
/// [[global.well_known.rtc_transports]]
|
||||||
|
/// type = "livekit"
|
||||||
|
/// livekit_service_url = "https://livekit.yourdomain.com"
|
||||||
|
/// ```
|
||||||
|
#[serde(default)]
|
||||||
|
pub rtc_transports: Vec<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Default)]
|
#[derive(Clone, Copy, Debug, Deserialize, Default)]
|
||||||
|
|||||||
@@ -1832,6 +1832,26 @@
|
|||||||
#
|
#
|
||||||
#support_mxid =
|
#support_mxid =
|
||||||
|
|
||||||
|
# Element Call / MatrixRTC configuration (MSC4143).
|
||||||
|
# Configures the LiveKit SFU server for voice/video calls.
|
||||||
|
#
|
||||||
|
# Requires a LiveKit server with JWT authentication.
|
||||||
|
# The `livekit_service_url` should point to your LiveKit JWT endpoint.
|
||||||
|
#
|
||||||
|
# Note: You must also set `client` above to your homeserver URL.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# ```toml
|
||||||
|
# [global.well_known]
|
||||||
|
# client = "https://matrix.yourdomain.com"
|
||||||
|
#
|
||||||
|
# [[global.well_known.rtc_transports]]
|
||||||
|
# type = "livekit"
|
||||||
|
# livekit_service_url = "https://livekit.yourdomain.com"
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
#rtc_transports = false
|
||||||
|
|
||||||
#[global.blurhashing]
|
#[global.blurhashing]
|
||||||
|
|
||||||
# blurhashing x component, 4 is recommended by https://blurha.sh/
|
# blurhashing x component, 4 is recommended by https://blurha.sh/
|
||||||
|
|||||||
Reference in New Issue
Block a user