Skip to main content

libsignal_service/websocket/
calling.rs

1use reqwest::Method;
2use serde::Deserialize;
3
4use crate::{
5    push_service::response::SignalServiceResponse,
6    websocket::{self, SignalWebSocket},
7};
8
9use super::ServiceError;
10
11/// Short-lived TURN credentials for 1:1 calls.
12///
13/// The URLs are TURN URIs (RFC 7065, e.g. `turn:host:3478?transport=udp`), meant to be
14/// handed to WebRTC as they are. `urls_with_ips` must be paired with `hostname` for TLS
15/// validation; `urls` can be used as-is.
16#[derive(Debug, Clone, Deserialize)]
17#[serde(rename_all = "camelCase")]
18pub struct TurnServer {
19    pub username: String,
20    pub password: String,
21    #[serde(rename = "ttl")]
22    pub ttl_seconds: u64,
23    #[serde(default)]
24    pub urls: Vec<String>,
25    #[serde(default)]
26    pub urls_with_ips: Vec<String>,
27    pub hostname: Option<String>,
28}
29
30impl SignalWebSocket<websocket::Identified> {
31    pub async fn get_calling_relays(
32        &mut self,
33    ) -> Result<Vec<TurnServer>, ServiceError> {
34        #[derive(Deserialize)]
35        struct GetCallingRelaysResponse {
36            relays: Vec<TurnServer>,
37        }
38
39        let response: GetCallingRelaysResponse = self
40            .http_request(Method::GET, "/v2/calling/relays")?
41            .send()
42            .await?
43            .service_error_for_status()
44            .await?
45            .json()
46            .await?;
47
48        Ok(response.relays)
49    }
50}