pub struct Stream { /* private fields */ }
Implementations§
source§impl Stream
impl Stream
sourcepub fn add_component(&self) -> Result<Arc<Component>, AgentError>
pub fn add_component(&self) -> Result<Arc<Component>, AgentError>
Add a Component
to this stream.
Examples
Add a Component
let agent = Agent::default();
let stream = agent.add_stream();
let component = stream.add_component().unwrap();
assert_eq!(component.id, component::RTP);
sourcepub fn remove_component(&self, component_id: usize) -> Result<(), AgentError>
pub fn remove_component(&self, component_id: usize) -> Result<(), AgentError>
Remove a Component
from this stream. If the index doesn’t exist or a component is not
available at that index, an error is returned
Examples
Remove a Component
let agent = Agent::default();
let stream = agent.add_stream();
let component = stream.add_component().unwrap();
assert_eq!(component.id, component::RTP);
assert!(stream.remove_component(component::RTP).is_ok());
Removing a Component
that was never added will return an error
let agent = Agent::default();
let stream = agent.add_stream();
assert!(matches!(stream.remove_component(component::RTP), Err(AgentError::ResourceNotFound)));
sourcepub fn component(&self, index: usize) -> Option<Arc<Component>>
pub fn component(&self, index: usize) -> Option<Arc<Component>>
Retrieve a Component
from this stream. If the index doesn’t exist or a component is not
available at that index, an error is returned
Examples
Remove a Component
let agent = Agent::default();
let stream = agent.add_stream();
let component = stream.add_component().unwrap();
assert_eq!(component.id, component::RTP);
assert!(stream.component(component::RTP).is_some());
Retrieving a Component
that doesn’t exist will return None
let agent = Agent::default();
let stream = agent.add_stream();
assert!(stream.component(component::RTP).is_none());
sourcepub fn set_local_credentials(&self, credentials: Credentials)
pub fn set_local_credentials(&self, credentials: Credentials)
Set local ICE credentials for this Stream
.
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let credentials = Credentials {ufrag: "1".to_owned(), passwd: "2".to_owned()};
stream.set_local_credentials(credentials);
sourcepub fn local_credentials(&self) -> Option<Credentials>
pub fn local_credentials(&self) -> Option<Credentials>
Retreive the previouly set local ICE credentials for this Stream
.
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let credentials = Credentials {ufrag: "1".to_owned(), passwd: "2".to_owned()};
stream.set_local_credentials(credentials.clone());
assert_eq!(stream.local_credentials(), Some(credentials));
sourcepub fn set_remote_credentials(&self, credentials: Credentials)
pub fn set_remote_credentials(&self, credentials: Credentials)
Set remote ICE credentials for this Stream
.
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let credentials = Credentials {ufrag: "1".to_owned(), passwd: "2".to_owned()};
stream.set_remote_credentials(credentials);
sourcepub fn remote_credentials(&self) -> Option<Credentials>
pub fn remote_credentials(&self) -> Option<Credentials>
Retreive the previouly set remote ICE credentials for this Stream
.
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let credentials = Credentials {ufrag: "1".to_owned(), passwd: "2".to_owned()};
stream.set_remote_credentials(credentials.clone());
assert_eq!(stream.remote_credentials(), Some(credentials));
sourcepub fn add_remote_candidate(
&self,
component_id: usize,
cand: Candidate
) -> Result<(), AgentError>
pub fn add_remote_candidate(
&self,
component_id: usize,
cand: Candidate
) -> Result<(), AgentError>
Add a remote candidate for connection checks for use with this stream
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let component = stream.add_component().unwrap();
let addr = "127.0.0.1:9999".parse().unwrap();
let candidate = Candidate::builder(
0,
CandidateType::Host,
TransportType::Udp,
"0",
addr
)
.build();
stream.add_remote_candidate(component.id, candidate).unwrap();
sourcepub async fn gather_candidates(&self) -> Result<(), AgentError>
pub async fn gather_candidates(&self) -> Result<(), AgentError>
Start gathering local candidates. Credentials must have been set before this function can be called.
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let local_credentials = Credentials {ufrag: "luser".to_owned(), passwd: "lpass".to_owned()};
stream.set_local_credentials(local_credentials);
let remote_credentials = Credentials {ufrag: "ruser".to_owned(), passwd: "rpass".to_owned()};
stream.set_remote_credentials(remote_credentials);
let component = stream.add_component().unwrap();
task::block_on(async move {
stream.gather_candidates().await.unwrap();
});
sourcepub fn local_candidates(&self) -> Vec<Candidate> ⓘ
pub fn local_candidates(&self) -> Vec<Candidate> ⓘ
Retrieve previously gathered local candidates
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let local_credentials = Credentials {ufrag: "luser".to_owned(), passwd: "lpass".to_owned()};
stream.set_local_credentials(local_credentials);
let remote_credentials = Credentials {ufrag: "ruser".to_owned(), passwd: "rpass".to_owned()};
stream.set_remote_credentials(remote_credentials);
let component = stream.add_component().unwrap();
task::block_on(async move {
stream.gather_candidates().await.unwrap();
let local_candidates = stream.local_candidates();
});
sourcepub fn remote_candidates(&self) -> Vec<Candidate> ⓘ
pub fn remote_candidates(&self) -> Vec<Candidate> ⓘ
Retrieve previously set remote candidates for connection checks from this stream
Examples
let agent = Agent::default();
let stream = agent.add_stream();
let component = stream.add_component().unwrap();
let addr = "127.0.0.1:9999".parse().unwrap();
let candidate = Candidate::builder(
0,
CandidateType::Host,
TransportType::Udp,
"0",
addr
)
.build();
stream.add_remote_candidate(component.id, candidate.clone()).unwrap();
let remote_cands = stream.remote_candidates();
assert_eq!(remote_cands.len(), 1);
assert_eq!(remote_cands[0], candidate);