Skip to main content

ruma_client_api/discovery/
discover_homeserver.rs

1//! `GET /.well-known/matrix/client` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/v1.19/client-server-api/#getwell-knownmatrixclient
4//!
5//! Get discovery information about the domain.
6//!
7//! Since Matrix 1.20, clients should follow 30x redirects when fetching this endpoint, while
8//! avoiding redirect loops.
9
10use ruma_common::{
11    api::{auth_scheme::NoAccessToken, request, response},
12    metadata,
13};
14use serde::{Deserialize, Serialize};
15
16#[cfg(feature = "unstable-msc4143")]
17use crate::rtc::RtcTransport;
18
19metadata! {
20    method: GET,
21    rate_limited: false,
22    authentication: NoAccessToken,
23    path: "/.well-known/matrix/client",
24}
25
26/// Request type for the `client_well_known` endpoint.
27#[request]
28#[derive(Default)]
29pub struct Request {}
30
31/// Response type for the `client_well_known` endpoint.
32#[response]
33pub struct Response {
34    /// Information about the homeserver to connect to.
35    #[serde(rename = "m.homeserver")]
36    pub homeserver: HomeserverInfo,
37
38    /// Information about the identity server to connect to.
39    #[serde(rename = "m.identity_server", skip_serializing_if = "Option::is_none")]
40    pub identity_server: Option<IdentityServerInfo>,
41
42    /// Information about the tile server to use to display location data.
43    #[cfg(feature = "unstable-msc3488")]
44    #[serde(
45        rename = "org.matrix.msc3488.tile_server",
46        alias = "m.tile_server",
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub tile_server: Option<TileServerInfo>,
50
51    /// A list of the available MatrixRTC foci, ordered by priority.
52    #[cfg(feature = "unstable-msc4143")]
53    #[serde(
54        rename = "org.matrix.msc4143.rtc_foci",
55        alias = "m.rtc_foci",
56        default,
57        skip_serializing_if = "Vec::is_empty"
58    )]
59    pub rtc_foci: Vec<RtcTransport>,
60}
61
62impl Request {
63    /// Creates an empty `Request`.
64    pub fn new() -> Self {
65        Self {}
66    }
67}
68
69impl Response {
70    /// Creates a new `Response` with the given `HomeserverInfo`.
71    pub fn new(homeserver: HomeserverInfo) -> Self {
72        Self {
73            homeserver,
74            identity_server: None,
75            #[cfg(feature = "unstable-msc3488")]
76            tile_server: None,
77            #[cfg(feature = "unstable-msc4143")]
78            rtc_foci: Default::default(),
79        }
80    }
81}
82
83/// Information about a discovered homeserver.
84#[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)]
85#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
86pub struct HomeserverInfo {
87    /// The base URL for the homeserver for client-server connections.
88    pub base_url: String,
89}
90
91impl HomeserverInfo {
92    /// Creates a new `HomeserverInfo` with the given `base_url`.
93    pub fn new(base_url: String) -> Self {
94        Self { base_url }
95    }
96}
97
98/// Information about a discovered identity server.
99#[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)]
100#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
101pub struct IdentityServerInfo {
102    /// The base URL for the identity server for client-server connections.
103    pub base_url: String,
104}
105
106impl IdentityServerInfo {
107    /// Creates an `IdentityServerInfo` with the given `base_url`.
108    pub fn new(base_url: String) -> Self {
109        Self { base_url }
110    }
111}
112
113/// Information about a discovered map tile server.
114#[cfg(feature = "unstable-msc3488")]
115#[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)]
116#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
117pub struct TileServerInfo {
118    /// The URL of a map tile server's `style.json` file.
119    ///
120    /// See the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/) for more details.
121    pub map_style_url: String,
122}
123
124#[cfg(feature = "unstable-msc3488")]
125impl TileServerInfo {
126    /// Creates a `TileServerInfo` with the given map style URL.
127    pub fn new(map_style_url: String) -> Self {
128        Self { map_style_url }
129    }
130}