pub struct Agent { /* private fields */ }Expand description
Represents the ICE agent.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn get_candidate_pairs_stats(&self, now: Instant) -> Vec<CandidatePairStats>
pub fn get_candidate_pairs_stats(&self, now: Instant) -> Vec<CandidatePairStats>
Returns a list of candidate pair stats.
Sourcepub fn get_local_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
pub fn get_local_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
Returns a list of local candidates stats.
Sourcepub fn get_remote_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
pub fn get_remote_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
Returns a list of remote candidates stats.
Source§impl Agent
impl Agent
Sourcepub fn new(
now: Instant,
config: Arc<AgentConfig>,
crypto_provider: Arc<dyn RTCCryptoProvider>,
) -> Result<Self>
pub fn new( now: Instant, config: Arc<AgentConfig>, crypto_provider: Arc<dyn RTCCryptoProvider>, ) -> Result<Self>
Creates a new Agent.
The crypto provider is supplied by the caller; this crate never resolves a default.
Builds an agent whose clock starts at now.
now is a constructor argument rather than an AgentConfig field because it is a value
consumed once at construction, not a setting that persists for the agent’s lifetime — and
because Instant has no Default, so a config field would force AgentConfig to drop
#[derive(Default)] and break every ..Default::default() in its 31 call sites.
Sourcepub fn add_local_candidate(&mut self, c: Candidate) -> Result<bool>
pub fn add_local_candidate(&mut self, c: Candidate) -> Result<bool>
Adds a new local candidate.
Sourcepub fn add_remote_candidate(&mut self, c: Candidate) -> Result<bool>
pub fn add_remote_candidate(&mut self, c: Candidate) -> Result<bool>
Adds a new remote candidate.
Sourcepub fn set_remote_credentials(
&mut self,
remote_ufrag: String,
remote_pwd: String,
) -> Result<()>
pub fn set_remote_credentials( &mut self, remote_ufrag: String, remote_pwd: String, ) -> Result<()>
Sets the credentials of the remote agent.
Sourcepub fn get_remote_credentials(&self) -> Option<&Credentials>
pub fn get_remote_credentials(&self) -> Option<&Credentials>
Returns the remote credentials.
Sourcepub fn get_local_credentials(&self) -> &Credentials
pub fn get_local_credentials(&self) -> &Credentials
Returns the local credentials. The credentials to advertise, which is what SDP generation wants.
Returns credentials staged by Agent::generate_restart_credentials when an ICE restart
is pending, so an offer carries the new ufrag/pwd. Inbound STUN validation deliberately
does not go through here — it reads local_credentials directly, so the live session
keeps working until Agent::apply_restart installs the new pair.
Sourcepub fn role(&self) -> bool
pub fn role(&self) -> bool
Whether this agent is the controlling one, which decides nomination.
Sourcepub fn set_role(&mut self, is_controlling: bool)
pub fn set_role(&mut self, is_controlling: bool)
Sets the controlling role.
Determined by which side offered; the two agents must not agree, or nomination stalls.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
The agent’s current connection state.
Sourcepub fn is_valid_non_stun_traffic(
&mut self,
now: Instant,
transport: TransportContext,
) -> bool
pub fn is_valid_non_stun_traffic( &mut self, now: Instant, transport: TransportContext, ) -> bool
Whether a non-STUN datagram on transport should be accepted as media.
Guards against accepting media from an address that has not passed a connectivity check.
Sourcepub fn get_selected_candidate_pair(&self) -> Option<(&Candidate, &Candidate)>
pub fn get_selected_candidate_pair(&self) -> Option<(&Candidate, &Candidate)>
Returns the selected pair (local_candidate, remote_candidate) or none
Sourcepub fn get_best_available_candidate_pair(
&self,
) -> Option<(&Candidate, &Candidate)>
pub fn get_best_available_candidate_pair( &self, ) -> Option<(&Candidate, &Candidate)>
The highest-priority pair that is still usable, whether or not it has been nominated.
Sourcepub fn start_connectivity_checks(
&mut self,
now: Instant,
is_controlling: bool,
remote_ufrag: String,
remote_pwd: String,
) -> Result<()>
pub fn start_connectivity_checks( &mut self, now: Instant, is_controlling: bool, remote_ufrag: String, remote_pwd: String, ) -> Result<()>
start connectivity checks
Sourcepub fn generate_restart_credentials(
&mut self,
ufrag: String,
pwd: String,
) -> Result<()>
pub fn generate_restart_credentials( &mut self, ufrag: String, pwd: String, ) -> Result<()>
Restarts the ICE Agent with the provided ufrag/pwd If no ufrag/pwd is provided the Agent will generate one itself. Stages new local credentials for an ICE restart, without disturbing the live session.
This is the half of an ICE restart that an offerer needs before generating SDP: the offer
must carry the new ufrag/pwd. It deliberately does not touch local_credentials,
candidate pairs, or connection state, because JSEP requires createOffer to be free of
side effects — and because inbound STUN is still being validated against the current
credentials until the local description is applied.
Empty ufrag / pwd are filled from the crypto provider’s RNG. Call
Agent::apply_restart to install them.
Sourcepub fn has_pending_restart(&self) -> bool
pub fn has_pending_restart(&self) -> bool
Whether Agent::generate_restart_credentials has staged a restart that is not yet applied.
Sourcepub fn apply_restart(
&mut self,
now: Instant,
keep_local_candidates: bool,
) -> Result<()>
pub fn apply_restart( &mut self, now: Instant, keep_local_candidates: bool, ) -> Result<()>
Applies a staged ICE restart, tearing down the old session and starting a new one at now.
Installs the credentials staged by Agent::generate_restart_credentials, if any, then
discards the remote credentials, pending binding requests, candidate pairs and selected
pair, and restarts the agent’s timers. With nothing staged, the current credentials are
kept and only the session is restarted.
Sourcepub fn restart(
&mut self,
now: Instant,
ufrag: String,
pwd: String,
keep_local_candidates: bool,
) -> Result<()>
pub fn restart( &mut self, now: Instant, ufrag: String, pwd: String, keep_local_candidates: bool, ) -> Result<()>
Generates and immediately applies an ICE restart.
Equivalent to Agent::generate_restart_credentials followed by
Agent::apply_restart. A JSEP-conformant offerer wants the two halves separately —
credentials at createOffer, application at setLocalDescription — but this remains the
right call for anything that restarts in one step.
Sourcepub fn get_local_candidates(&self) -> &[Candidate]
pub fn get_local_candidates(&self) -> &[Candidate]
Returns the local candidates.
Sourcepub fn get_remote_candidates(&self) -> &[Candidate]
pub fn get_remote_candidates(&self) -> &[Candidate]
The remote candidates this agent has been given, in the order they were added.