diff --git a/examples/examples/play-from-disk-renegotiation/play-from-disk-renegotiation.rs b/examples/examples/play-from-disk-renegotiation/play-from-disk-renegotiation.rs
index 503cd863d..f9d8ba20b 100644
--- a/examples/examples/play-from-disk-renegotiation/play-from-disk-renegotiation.rs
+++ b/examples/examples/play-from-disk-renegotiation/play-from-disk-renegotiation.rs
@@ -212,9 +212,12 @@ async fn remove_video(
r: Request
,
) -> Result, hyper::Error> {
let senders = pc.get_senders().await;
+
if !senders.is_empty() {
- if let Err(err) = pc.remove_track(&senders[0]).await {
- panic!("{}", err);
+ if let Some(track) = senders[0].track().await {
+ if let Err(err) = pc.remove_track(track).await {
+ panic!("{}", err);
+ }
}
}
diff --git a/webrtc/src/peer_connection/mod.rs b/webrtc/src/peer_connection/mod.rs
index b4989cef4..53fc1922d 100644
--- a/webrtc/src/peer_connection/mod.rs
+++ b/webrtc/src/peer_connection/mod.rs
@@ -1731,26 +1731,24 @@ impl RTCPeerConnection {
}
/// remove_track removes a Track from the PeerConnection
- pub async fn remove_track(&self, sender: &Arc) -> Result<()> {
+ pub async fn remove_track(&self, track: Arc) -> Result<()> {
if self.internal.is_closed.load(Ordering::SeqCst) {
return Err(Error::ErrConnectionClosed);
}
- let mut transceiver = None;
+ let mut signals = None;
{
let rtp_transceivers = self.internal.rtp_transceivers.lock().await;
for t in &*rtp_transceivers {
- if t.sender().await.id == sender.id {
- if sender.track().await.is_none() {
- return Ok(());
- }
- transceiver = Some(t.clone());
+ let sender = t.sender().await;
+ if sender.id == track.id() {
+ signals = Some((t.clone(), sender.clone()));
break;
}
}
}
- let t = transceiver.ok_or(Error::ErrSenderNotCreatedByConnection)?;
+ let (t, s) = signals.ok_or(Error::ErrSenderNotCreatedByConnection)?;
// This also happens in `set_sending_track` but we need to make sure we do this
// before we call sender.stop to avoid a race condition when removing tracks and
@@ -1760,7 +1758,7 @@ impl RTCPeerConnection {
t.direction().has_recv(),
));
// Stop the sender
- let sender_result = sender.stop().await;
+ let sender_result = s.stop().await;
// This also updates direction
let sending_track_result = t.set_sending_track(None).await;