use super::RTCPeerConnection;
use super::event::RTCPeerConnectionEvent;
#[derive(Default)]
pub(crate) struct EarlyCandidates {
held: Vec<(String, RTCPeerConnectionEvent)>,
pub(crate) engine_candidate: bool,
}
impl RTCPeerConnection {
pub(crate) fn hold_early_candidate(
&mut self,
event: RTCPeerConnectionEvent,
ufrag: &str,
) -> Option<RTCPeerConnectionEvent> {
if self.early_candidates.engine_candidate
&& !self.local_ice_ufrags().iter().any(|u| u == ufrag)
{
self.early_candidates.held.push((ufrag.to_owned(), event));
None
} else {
Some(event)
}
}
pub(crate) fn release_early_candidates(&mut self) {
if self.early_candidates.held.is_empty() {
return;
}
let described = self.local_ice_ufrags();
let live: Vec<String> = self
.pipeline_context
.transports
.ids()
.into_iter()
.map(|id| {
self.ice_transport_of(id)
.agent
.get_local_credentials()
.ufrag
.clone()
})
.collect();
let mut waiting = vec![];
for (ufrag, event) in std::mem::take(&mut self.early_candidates.held) {
if described.contains(&ufrag) {
self.pipeline_context.event_outs.push_back(event);
} else if live.contains(&ufrag) {
waiting.push((ufrag, event));
} else {
log::debug!("a held candidate of an abandoned ICE generation is dropped");
}
}
self.early_candidates.held = waiting;
}
pub(crate) fn engine_gathering_allowed(&self) -> bool {
self.local_description_was_set || self.setting_engine.gathering_before_local_description
}
}