diff --git a/Cargo.lock b/Cargo.lock index 3f0121d..5558a74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1109,7 +1109,7 @@ dependencies = [ [[package]] name = "interceptor" version = "0.12.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "async-trait", "bytes", @@ -1899,7 +1899,7 @@ dependencies = [ [[package]] name = "rtcp" version = "0.11.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "bytes", "thiserror", @@ -1909,10 +1909,9 @@ dependencies = [ [[package]] name = "rtp" version = "0.11.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "bytes", - "memchr", "portable-atomic", "rand", "serde", @@ -1997,9 +1996,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.10" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +checksum = "afabcee0551bd1aa3e18e5adbf2c0544722014b899adb31bd186ec638d3da97e" dependencies = [ "once_cell", "ring", @@ -2027,9 +2026,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" dependencies = [ "ring", "rustls-pki-types", @@ -2066,7 +2065,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sdp" version = "0.6.2" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "rand", "substring", @@ -2295,9 +2294,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "stun" version = "0.6.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ - "base64 0.22.1", + "base64 0.21.7", "crc", "lazy_static", "md-5", @@ -2659,10 +2658,10 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "turn" version = "0.8.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "async-trait", - "base64 0.22.1", + "base64 0.21.7", "futures", "log", "md-5", @@ -2895,7 +2894,7 @@ dependencies = [ [[package]] name = "webrtc" version = "0.11.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "arc-swap", "async-trait", @@ -2912,7 +2911,7 @@ dependencies = [ "ring", "rtcp", "rtp", - "rustls 0.23.10", + "rustls 0.23.5", "sdp", "serde", "serde_json", @@ -2938,7 +2937,7 @@ dependencies = [ [[package]] name = "webrtc-data" version = "0.9.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "bytes", "log", @@ -2952,7 +2951,7 @@ dependencies = [ [[package]] name = "webrtc-dtls" version = "0.10.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "aes", "aes-gcm", @@ -2972,7 +2971,7 @@ dependencies = [ "rand_core", "rcgen", "ring", - "rustls 0.23.10", + "rustls 0.23.5", "sec1", "serde", "sha1", @@ -2988,7 +2987,7 @@ dependencies = [ [[package]] name = "webrtc-ice" version = "0.11.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "arc-swap", "async-trait", @@ -3012,7 +3011,7 @@ dependencies = [ [[package]] name = "webrtc-mdns" version = "0.7.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "log", "socket2", @@ -3024,7 +3023,7 @@ dependencies = [ [[package]] name = "webrtc-media" version = "0.8.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "byteorder", "bytes", @@ -3036,7 +3035,7 @@ dependencies = [ [[package]] name = "webrtc-sctp" version = "0.10.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "arc-swap", "async-trait", @@ -3053,7 +3052,7 @@ dependencies = [ [[package]] name = "webrtc-srtp" version = "0.13.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "aead", "aes", @@ -3075,7 +3074,7 @@ dependencies = [ [[package]] name = "webrtc-util" version = "0.9.0" -source = "git+https://github.com/webrtc-rs/webrtc?rev=40642c8#40642c835d15a197eb0f9db36b6235ce582f7529" +source = "git+https://github.com/webrtc-rs/webrtc?rev=ae93e81#ae93e81a493c004b0270603d539ad9a40b7b3064" dependencies = [ "async-trait", "bitflags 1.3.2", diff --git a/Cargo.toml b/Cargo.toml index 0dff1c5..1950785 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ license = "MPL-2.0" repository = "https://github.com/binbat/live777" [workspace.dependencies] -webrtc = { git = "https://github.com/webrtc-rs/webrtc", rev = "40642c8" } +webrtc = { git = "https://github.com/webrtc-rs/webrtc", rev = "ae93e81" } anyhow = "1.0" clap = "4.5" diff --git a/conf/live777.toml b/conf/live777.toml index 2e3d828..6e927d3 100644 --- a/conf/live777.toml +++ b/conf/live777.toml @@ -16,6 +16,7 @@ urls = [ # urls = [ "turn:turn.22333.fun", "turn:cn.22333.fun" ] # username = "live777" # credential = "live777" +# credential_type = "password" # WHIP/WHEP auth token # Headers["Authorization"] = "Bearer {token}" diff --git a/libs/libwish/src/lib.rs b/libs/libwish/src/lib.rs index f0623ca..0e7288f 100644 --- a/libs/libwish/src/lib.rs +++ b/libs/libwish/src/lib.rs @@ -118,6 +118,12 @@ impl Client { urls: vec![link.raw_uri.to_string().replacen("://", ":", 1)], username: link.params.remove("username").unwrap_or("".to_owned()), credential: link.params.remove("credential").unwrap_or("".to_owned()), + credential_type: link + .params + .remove("credential-type") + .unwrap_or("".to_owned()) + .as_str() + .into(), }) } } @@ -168,6 +174,7 @@ mod tests { use http::header; use http::response::Builder; use reqwest::Response; + use webrtc::ice_transport::ice_credential_type::RTCIceCredentialType; use crate::Client; @@ -176,7 +183,7 @@ mod tests { let response = Builder::new() .header(header::LINK, r#"; rel="ice-server""#) .header(header::LINK, r#"; rel="ice-server""#) - .header(header::LINK, r#"; rel="ice-server"; username="live777"; credential="live777""#) + .header(header::LINK, r#"; rel="ice-server"; username="live777"; credential="live777"; credential-type="password""#) .body("") .unwrap(); let response = Response::from(response); @@ -198,6 +205,10 @@ mod tests { ); assert_eq!(ice_servers.get(2).unwrap().username, "live777"); assert_eq!(ice_servers.get(2).unwrap().credential, "live777"); + assert_eq!( + ice_servers.get(2).unwrap().credential_type, + RTCIceCredentialType::Password + ); println!("{:?}", ice_servers); } diff --git a/liveion/src/config.rs b/liveion/src/config.rs index 2e2e97b..7dbb44c 100644 --- a/liveion/src/config.rs +++ b/liveion/src/config.rs @@ -2,7 +2,11 @@ use base64::engine::general_purpose::STANDARD; use base64::Engine; use serde::{Deserialize, Serialize}; use std::{env, fs, net::SocketAddr, str::FromStr}; -use webrtc::{ice, ice_transport::ice_server::RTCIceServer, Error}; +use webrtc::{ + ice, + ice_transport::{ice_credential_type::RTCIceCredentialType, ice_server::RTCIceServer}, + Error, +}; #[derive(Debug, Default, Clone, Deserialize, Serialize)] pub struct Config { @@ -196,7 +200,24 @@ impl IceServer { return Err(Error::ErrNoTurnCredentials); } url.username.clone_from(&self.username); + + match self.credential_type.as_str().into() { + 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), + }; } + urls.push(url); } @@ -210,6 +231,7 @@ impl From for RTCIceServer { urls: val.urls, username: val.username, credential: val.credential, + credential_type: val.credential_type.as_str().into(), } } } diff --git a/tools/whepfrom/src/main.rs b/tools/whepfrom/src/main.rs index eafec99..e5a938f 100644 --- a/tools/whepfrom/src/main.rs +++ b/tools/whepfrom/src/main.rs @@ -9,6 +9,7 @@ use tokio::{ sync::mpsc::{unbounded_channel, UnboundedSender}, }; use tracing::{debug, info, trace, warn, Level}; +use webrtc::ice_transport::ice_credential_type::RTCIceCredentialType; use webrtc::{ api::{interceptor_registry::register_default_interceptors, media_engine::*, APIBuilder}, ice_transport::ice_server::RTCIceServer, @@ -189,6 +190,7 @@ async fn new_peer( urls: vec!["stun:stun.l.google.com:19302".to_string()], username: "".to_string(), credential: "".to_string(), + credential_type: RTCIceCredentialType::Unspecified, } }], ..Default::default() diff --git a/tools/whipinto/src/main.rs b/tools/whipinto/src/main.rs index 041bce6..e721676 100644 --- a/tools/whipinto/src/main.rs +++ b/tools/whipinto/src/main.rs @@ -12,7 +12,7 @@ use tokio::{ use tracing::{debug, info, trace, warn, Level}; use webrtc::{ api::{interceptor_registry::register_default_interceptors, media_engine::*, APIBuilder}, - ice_transport::ice_server::RTCIceServer, + ice_transport::{ice_credential_type::RTCIceCredentialType, ice_server::RTCIceServer}, interceptor::registry::Registry, peer_connection::{ configuration::RTCConfiguration, peer_connection_state::RTCPeerConnectionState, @@ -180,6 +180,7 @@ async fn new_peer( urls: vec!["stun:stun.l.google.com:19302".to_string()], username: "".to_string(), credential: "".to_string(), + credential_type: RTCIceCredentialType::Unspecified, } }], ..Default::default() diff --git a/tools/whipinto/src/test.rs b/tools/whipinto/src/test.rs index cb73816..fafb88f 100644 --- a/tools/whipinto/src/test.rs +++ b/tools/whipinto/src/test.rs @@ -9,6 +9,7 @@ mod tests { }; use std::sync::Arc; + use webrtc::ice_transport::ice_credential_type::RTCIceCredentialType; use webrtc::peer_connection::policy::bundle_policy::RTCBundlePolicy; use webrtc::peer_connection::policy::ice_transport_policy::RTCIceTransportPolicy; use webrtc::peer_connection::policy::rtcp_mux_policy::RTCRtcpMuxPolicy; @@ -34,6 +35,7 @@ mod tests { urls: vec!["stun:stun.l.google.com:19302".to_string()], username: "".to_string(), credential: "".to_string(), + credential_type: RTCIceCredentialType::Unspecified, }], ..Default::default() }; @@ -53,6 +55,7 @@ mod tests { ], username: "live777".to_string(), credential: "live777".to_string(), + credential_type: RTCIceCredentialType::Password, }], ..Default::default() }; @@ -74,6 +77,10 @@ mod tests { ); assert_eq!(updated_config.ice_servers[0].username, "live777"); assert_eq!(updated_config.ice_servers[0].credential, "live777"); + assert_eq!( + updated_config.ice_servers[0].credential_type, + RTCIceCredentialType::Password + ); assert_eq!( updated_config.ice_transport_policy, RTCIceTransportPolicy::Unspecified