@@ -1437,7 +1437,7 @@ impl RTCPeerConnection {
1437
1437
1438
1438
if we_offer {
1439
1439
// WebRTC Spec 1.0 https://www.w3.org/TR/webrtc/
1440
- // Section 4.4.1.5
1440
+ // 4.5.9.2
1441
1441
// This is an answer from the remote.
1442
1442
if let Some ( parsed) = remote_description. as_ref ( ) . and_then ( |r| r. parsed . as_ref ( ) ) {
1443
1443
for media in & parsed. media_descriptions {
@@ -1466,17 +1466,19 @@ impl RTCPeerConnection {
1466
1466
if let Some ( t) = find_by_mid ( mid_value, & mut local_transceivers) . await {
1467
1467
let previous_direction = t. direction ( ) ;
1468
1468
1469
- // 4.9.2.9
1469
+ // 4.5. 9.2.9
1470
1470
// Let direction be an RTCRtpTransceiverDirection value representing the direction
1471
1471
// from the media description, but with the send and receive directions reversed to
1472
1472
// represent this peer's point of view. If the media description is rejected,
1473
1473
// set direction to "inactive".
1474
1474
let reversed_direction = direction. reverse ( ) ;
1475
1475
1476
- // 4.9.2.13.2
1476
+ // 4.5. 9.2.13.2
1477
1477
// Set transceiver.[[CurrentDirection]] and transceiver.[[Direction]]s to direction.
1478
- t. set_direction_internal ( reversed_direction) ;
1479
1478
t. set_current_direction ( reversed_direction) ;
1479
+ // TODO: According to the specification we should set
1480
+ // transceiver.[[Direction]] here, however libWebrtc doesn't do this.
1481
+ // t.set_direction_internal(reversed_direction);
1480
1482
t. process_new_current_direction ( previous_direction) . await ?;
1481
1483
}
1482
1484
}
@@ -1766,18 +1768,24 @@ impl RTCPeerConnection {
1766
1768
}
1767
1769
}
1768
1770
1769
- if let Some ( t) = transceiver {
1770
- let sender_result = sender. stop ( ) . await ;
1771
- // This also updates direction
1772
- let sending_track_result = t. set_sending_track ( None ) . await ;
1771
+ let t = transceiver. ok_or ( Error :: ErrSenderNotCreatedByConnection ) ?;
1773
1772
1774
- if sender_result. is_ok ( ) && sending_track_result. is_ok ( ) {
1775
- self . internal . trigger_negotiation_needed ( ) . await ;
1776
- }
1777
- Ok ( ( ) )
1778
- } else {
1779
- Err ( Error :: ErrSenderNotCreatedByConnection )
1773
+ // This also happens in `set_sending_track` but we need to make sure we do this
1774
+ // before we call sender.stop to avoid a race condition when removing tracks and
1775
+ // generating offers.
1776
+ t. set_direction_internal ( RTCRtpTransceiverDirection :: from_send_recv (
1777
+ false ,
1778
+ t. direction ( ) . has_recv ( ) ,
1779
+ ) ) ;
1780
+ // Stop the sender
1781
+ let sender_result = sender. stop ( ) . await ;
1782
+ // This also updates direction
1783
+ let sending_track_result = t. set_sending_track ( None ) . await ;
1784
+
1785
+ if sender_result. is_ok ( ) && sending_track_result. is_ok ( ) {
1786
+ self . internal . trigger_negotiation_needed ( ) . await ;
1780
1787
}
1788
+ Ok ( ( ) )
1781
1789
}
1782
1790
1783
1791
/// add_transceiver_from_kind Create a new RtpTransceiver and adds it to the set of transceivers.
0 commit comments