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