From d6b1d341d9cde922cf4410d37abcf69800af4af0 Mon Sep 17 00:00:00 2001 From: Alex <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 29 Jun 2024 13:46:46 -0400 Subject: [PATCH] Remove `RTCIceCredentialType` (#584) The enum no longer exists in the spec: w3c/webrtc-pc@0cba163 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection#credentialtype --- .../src/ice_transport/ice_credential_type.rs | 74 ------------------- webrtc/src/ice_transport/ice_server.rs | 26 +------ webrtc/src/ice_transport/mod.rs | 1 - .../peer_connection/peer_connection_test.rs | 3 - 4 files changed, 2 insertions(+), 102 deletions(-) delete mode 100644 webrtc/src/ice_transport/ice_credential_type.rs diff --git a/webrtc/src/ice_transport/ice_credential_type.rs b/webrtc/src/ice_transport/ice_credential_type.rs deleted file mode 100644 index 5db6c6cd2..000000000 --- a/webrtc/src/ice_transport/ice_credential_type.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::fmt; - -use serde::{Deserialize, Serialize}; - -/// ICECredentialType indicates the type of credentials used to connect to -/// an ICE server. -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] -pub enum RTCIceCredentialType { - #[default] - Unspecified, - - /// ICECredential::Password describes username and password based - /// credentials as described in . - Password, - - /// ICECredential::Oauth describes token based credential as described - /// in . - /// Not supported in WebRTC 1.0 spec - Oauth, -} - -const ICE_CREDENTIAL_TYPE_PASSWORD_STR: &str = "password"; -const ICE_CREDENTIAL_TYPE_OAUTH_STR: &str = "oauth"; - -impl From<&str> for RTCIceCredentialType { - fn from(raw: &str) -> Self { - match raw { - ICE_CREDENTIAL_TYPE_PASSWORD_STR => RTCIceCredentialType::Password, - ICE_CREDENTIAL_TYPE_OAUTH_STR => RTCIceCredentialType::Oauth, - _ => RTCIceCredentialType::Unspecified, - } - } -} - -impl fmt::Display for RTCIceCredentialType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - RTCIceCredentialType::Password => write!(f, "{ICE_CREDENTIAL_TYPE_PASSWORD_STR}"), - RTCIceCredentialType::Oauth => write!(f, "{ICE_CREDENTIAL_TYPE_OAUTH_STR}"), - _ => write!(f, "{}", crate::UNSPECIFIED_STR), - } - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_new_ice_credential_type() { - let tests = vec![ - ("Unspecified", RTCIceCredentialType::Unspecified), - ("password", RTCIceCredentialType::Password), - ("oauth", RTCIceCredentialType::Oauth), - ]; - - for (ct_str, expected_ct) in tests { - assert_eq!(RTCIceCredentialType::from(ct_str), expected_ct); - } - } - - #[test] - fn test_ice_credential_type_string() { - let tests = vec![ - (RTCIceCredentialType::Unspecified, "Unspecified"), - (RTCIceCredentialType::Password, "password"), - (RTCIceCredentialType::Oauth, "oauth"), - ]; - - for (ct, expected_string) in tests { - assert_eq!(ct.to_string(), expected_string); - } - } -} diff --git a/webrtc/src/ice_transport/ice_server.rs b/webrtc/src/ice_transport/ice_server.rs index c43e2d2b8..0ae4a8208 100644 --- a/webrtc/src/ice_transport/ice_server.rs +++ b/webrtc/src/ice_transport/ice_server.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; use crate::error::{Error, Result}; -use crate::ice_transport::ice_credential_type::RTCIceCredentialType; /// ICEServer describes a single STUN and TURN server that can be used by /// the ICEAgent to establish a connection with a peer. @@ -10,7 +9,6 @@ pub struct RTCIceServer { pub urls: Vec, pub username: String, pub credential: String, - pub credential_type: RTCIceCredentialType, } impl RTCIceServer { @@ -34,23 +32,9 @@ impl RTCIceServer { if self.username.is_empty() || self.credential.is_empty() { return Err(Error::ErrNoTurnCredentials); } - url.username.clone_from(&self.username); - match self.credential_type { - RTCIceCredentialType::Password => { - // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3) - url.password.clone_from(&self.credential); - } - RTCIceCredentialType::Oauth => { - // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.4) - /*if _, ok: = s.Credential.(OAuthCredential); !ok { - return nil, - &rtcerr.InvalidAccessError{Err: ErrTurnCredentials - } - }*/ - } - _ => return Err(Error::ErrTurnCredentials), - }; + url.username.clone_from(&self.username); + url.password.clone_from(&self.credential); } urls.push(url); @@ -72,7 +56,6 @@ mod test { urls: vec!["turn:192.158.29.39?transport=udp".to_owned()], username: "unittest".to_owned(), credential: "placeholder".to_owned(), - credential_type: RTCIceCredentialType::Password, }, true, ), @@ -81,7 +64,6 @@ mod test { urls: vec!["turn:[2001:db8:1234:5678::1]?transport=udp".to_owned()], username: "unittest".to_owned(), credential: "placeholder".to_owned(), - credential_type: RTCIceCredentialType::Password, }, true, ), @@ -117,7 +99,6 @@ mod test { urls: vec!["turn:192.158.29.39?transport=udp".to_owned()], username: "unittest".to_owned(), credential: String::new(), - credential_type: RTCIceCredentialType::Password, }, Error::ErrNoTurnCredentials, ), @@ -126,7 +107,6 @@ mod test { urls: vec!["turn:192.158.29.39?transport=udp".to_owned()], username: "unittest".to_owned(), credential: String::new(), - credential_type: RTCIceCredentialType::Oauth, }, Error::ErrNoTurnCredentials, ), @@ -135,7 +115,6 @@ mod test { urls: vec!["turn:192.158.29.39?transport=udp".to_owned()], username: "unittest".to_owned(), credential: String::new(), - credential_type: RTCIceCredentialType::Unspecified, }, Error::ErrNoTurnCredentials, ), @@ -157,7 +136,6 @@ mod test { urls: vec!["stun:google.de?transport=udp".to_owned()], username: "unittest".to_owned(), credential: String::new(), - credential_type: RTCIceCredentialType::Oauth, }, ice::Error::ErrStunQuery, )]; diff --git a/webrtc/src/ice_transport/mod.rs b/webrtc/src/ice_transport/mod.rs index e2b96da53..1b5f0cfbd 100644 --- a/webrtc/src/ice_transport/mod.rs +++ b/webrtc/src/ice_transport/mod.rs @@ -31,7 +31,6 @@ pub mod ice_candidate; pub mod ice_candidate_pair; pub mod ice_candidate_type; pub mod ice_connection_state; -pub mod ice_credential_type; pub mod ice_gatherer; pub mod ice_gatherer_state; pub mod ice_gathering_state; diff --git a/webrtc/src/peer_connection/peer_connection_test.rs b/webrtc/src/peer_connection/peer_connection_test.rs index 2c9676037..0ccfed7ab 100644 --- a/webrtc/src/peer_connection/peer_connection_test.rs +++ b/webrtc/src/peer_connection/peer_connection_test.rs @@ -14,7 +14,6 @@ use crate::api::interceptor_registry::register_default_interceptors; use crate::api::media_engine::{MediaEngine, MIME_TYPE_VP8}; use crate::api::APIBuilder; use crate::ice_transport::ice_candidate_pair::RTCIceCandidatePair; -use crate::ice_transport::ice_credential_type::RTCIceCredentialType; use crate::ice_transport::ice_server::RTCIceServer; use crate::peer_connection::configuration::RTCConfiguration; use crate::rtp_transceiver::rtp_codec::RTCRtpCodecCapability; @@ -408,7 +407,6 @@ async fn test_set_get_configuration() { urls: vec!["stun:stun.l.google.com:19302".to_string()], username: "".to_string(), credential: "".to_string(), - credential_type: RTCIceCredentialType::Unspecified, }], ..Default::default() }; @@ -448,7 +446,6 @@ async fn test_set_get_configuration() { ], username: "live777".to_string(), credential: "live777".to_string(), - credential_type: RTCIceCredentialType::Password, }], ..Default::default() };