From 2801e30301387d9257191d7b8251d0cfeec36872 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Mon, 30 Sep 2024 14:57:19 +0200 Subject: [PATCH 1/4] Add get_turn_server_info --- src/push_service/calling.rs | 34 ++++++++++++++++++++++++++++++++++ src/push_service/mod.rs | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 src/push_service/calling.rs diff --git a/src/push_service/calling.rs b/src/push_service/calling.rs new file mode 100644 index 000000000..ef9a7edc8 --- /dev/null +++ b/src/push_service/calling.rs @@ -0,0 +1,34 @@ +use super::{HttpAuthOverride, PushService, ReqwestExt, ServiceError}; +use crate::configuration::Endpoint; +use reqwest::Method; +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TurnServerInfo { + pub username: String, + pub password: String, + pub hostname: Option, + pub urls: Vec, + #[serde(default)] + pub urls_with_ips: Vec, +} + +impl PushService { + pub async fn get_turn_server_info( + &mut self, + ) -> Result { + Ok(self + .request( + Method::GET, + Endpoint::service("/v1/calling/relays"), + HttpAuthOverride::NoOverride, + )? + .send() + .await? + .service_error_for_status() + .await? + .json() + .await?) + } +} diff --git a/src/push_service/mod.rs b/src/push_service/mod.rs index cae93a75c..98c372c59 100644 --- a/src/push_service/mod.rs +++ b/src/push_service/mod.rs @@ -24,6 +24,7 @@ pub const KEEPALIVE_TIMEOUT_SECONDS: Duration = Duration::from_secs(55); pub const DEFAULT_DEVICE_ID: u32 = 1; mod account; +mod calling; mod cdn; mod error; mod keys; @@ -34,6 +35,7 @@ mod response; mod stickers; pub use account::*; +pub use calling::*; pub use cdn::*; pub use error::*; pub use keys::*; From 0a21f26ca4e08ed7bba452d8a8811fd8dd2c3fd2 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 26 Oct 2024 20:49:15 +0200 Subject: [PATCH 2/4] Get Turn server info v2 As per https://github.com/signalapp/Signal-Server/commit/cacd4afbbba4fdd412de8118e00dce17477c78d2 --- src/push_service/calling.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/push_service/calling.rs b/src/push_service/calling.rs index ef9a7edc8..12ba7c6f6 100644 --- a/src/push_service/calling.rs +++ b/src/push_service/calling.rs @@ -31,4 +31,28 @@ impl PushService { .json() .await?) } + + pub async fn get_turn_server_info_v2( + &mut self, + ) -> Result, ServiceError> { + #[derive(Debug, Deserialize)] + #[serde(rename_all = "camelCase")] + struct GetRelaysResponse { + relays: Vec, + } + + Ok(self + .request( + Method::GET, + Endpoint::service("/v2/calling/relays"), + HttpAuthOverride::NoOverride, + )? + .send() + .await? + .service_error_for_status() + .await? + .json::() + .await? + .relays) + } } From 516750a05bd0d78cc866a89f68ab1277a41d7c39 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 16 Nov 2024 14:53:48 +0100 Subject: [PATCH 3/4] Deprecate get_turn_server_info --- src/push_service/calling.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/push_service/calling.rs b/src/push_service/calling.rs index 12ba7c6f6..0f8d91dee 100644 --- a/src/push_service/calling.rs +++ b/src/push_service/calling.rs @@ -15,6 +15,9 @@ pub struct TurnServerInfo { } impl PushService { + #[deprecated( + note = "Use get_turn_server_info_v2 instead. This method is still used by the Android and iOS clients, and will be kept in as long as that's the case." + )] pub async fn get_turn_server_info( &mut self, ) -> Result { From 00b4adb9b872b7682a5079a94904017bf1e5b655 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 16 Nov 2024 14:55:18 +0100 Subject: [PATCH 4/4] Remove relays v1 endpoint Android moved away, so we can safely assume the new endpoint is the intended new version. --- src/push_service/calling.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/push_service/calling.rs b/src/push_service/calling.rs index 0f8d91dee..ef2b0a726 100644 --- a/src/push_service/calling.rs +++ b/src/push_service/calling.rs @@ -15,28 +15,8 @@ pub struct TurnServerInfo { } impl PushService { - #[deprecated( - note = "Use get_turn_server_info_v2 instead. This method is still used by the Android and iOS clients, and will be kept in as long as that's the case." - )] pub async fn get_turn_server_info( &mut self, - ) -> Result { - Ok(self - .request( - Method::GET, - Endpoint::service("/v1/calling/relays"), - HttpAuthOverride::NoOverride, - )? - .send() - .await? - .service_error_for_status() - .await? - .json() - .await?) - } - - pub async fn get_turn_server_info_v2( - &mut self, ) -> Result, ServiceError> { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")]