pub struct Candidate { /* private fields */ }Expand description
ICE candidates are network addresses used to connect to a peer.
There are different kinds of ICE candidates. The simplest kind is a host candidate which is a socket address on a local (host) network interface.
Implementations§
Source§impl Candidate
impl Candidate
Sourcepub fn builder() -> CandidateBuilder<NoProtocol, NoRoute>
pub fn builder() -> CandidateBuilder<NoProtocol, NoRoute>
Starts the typesafe builder.
§Example
let addr: SocketAddr = "192.168.1.1:12345".parse().unwrap();
// A standard UDP host candidate
let udp_host = Candidate::builder()
.udp()
.host(addr)
.build()?;
// A TCP host candidate with a passive role
let tcp_host = Candidate::builder()
.tcp()
.host(addr)
.tcptype(TcpType::Passive)
.build()?;
Sourcepub fn host(
addr: SocketAddr,
proto: impl TryInto<Protocol>,
) -> Result<Self, IceError>
pub fn host( addr: SocketAddr, proto: impl TryInto<Protocol>, ) -> Result<Self, IceError>
Creates a host ICE candidate.
Host candidates are local sockets directly on the host.
Sourcepub fn server_reflexive(
addr: SocketAddr,
base: SocketAddr,
proto: impl TryInto<Protocol>,
) -> Result<Self, IceError>
pub fn server_reflexive( addr: SocketAddr, base: SocketAddr, proto: impl TryInto<Protocol>, ) -> Result<Self, IceError>
Creates a server reflexive ICE candidate.
Server reflexive candidates are local sockets mapped to external ip discovered
via a STUN binding request.
The base is the local interface that this address corresponds to.
Sourcepub fn relayed(
addr: SocketAddr,
local: SocketAddr,
proto: impl TryInto<Protocol>,
) -> Result<Self, IceError>
pub fn relayed( addr: SocketAddr, local: SocketAddr, proto: impl TryInto<Protocol>, ) -> Result<Self, IceError>
Creates a relayed ICE candidate.
Relayed candidates are server sockets relaying traffic to a local socket. Allocate a TURN addr to use as a local candidate.
addr- The TURN server’s allocated address that will be used for relaying traffic. This is the address that will be used for communication with the peer.local- The local interface address that corresponds to this candidate. This is the address from which the TURN allocation request was sent.proto- The transport protocol to use (UDP, TCP, etc.).
Sourcepub fn from_sdp_string(s: &str) -> Result<Self, IceError>
pub fn from_sdp_string(s: &str) -> Result<Self, IceError>
Creates a new ICE candidate from a string.
Sourcepub fn prio(&self) -> u32
pub fn prio(&self) -> u32
Returns the priority value for the specified ICE candidate.
The priority is a positive integer between 1 and 2^31 - 1 (inclusive), calculated according to the ICE specification defined in RFC 8445, Section 5.1.2.
Sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
Returns the address for the specified ICE candidate.
Sourcepub fn proto(&self) -> Protocol
pub fn proto(&self) -> Protocol
Returns a reference to the String containing the transport protocol of the ICE candidate. For example tcp/udp/..
Sourcepub fn tcptype(&self) -> Option<TcpType>
pub fn tcptype(&self) -> Option<TcpType>
Returns the candidate’s TCP role. Refer to TcpType for more details.
Sourcepub fn kind(&self) -> CandidateKind
pub fn kind(&self) -> CandidateKind
Returns the kind of this candidate.
Sourcepub fn to_sdp_string(&self) -> String
pub fn to_sdp_string(&self) -> String
Generates a candidate attribute string.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Candidate
Deserialize Candidate from a candidate info.
impl<'de> Deserialize<'de> for Candidate
Deserialize Candidate from a candidate info.
Similar to Candidate::serialize, we drop sdpMid and sdpMLineIndex when parsing.
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Serialize for Candidate
Serialize Candidate into candidate info.
impl Serialize for Candidate
Serialize Candidate into candidate info.
Always set sdpMid to null and sdpMLineIndex to 0, as we only support one media line.
e.g. serde_json would produce:
{
"candidate": "candidate:12044049749558888150 1 udp 2130706175 1.2.3.4 1234 typ host",
"sdpMid": null,
"sdpMLineIndex": 0
"usernameFragment": "ufrag"
}