From 6ad88b6682ff8ccf9ea78cc8f2c705cb4da4554f Mon Sep 17 00:00:00 2001 From: nightness Date: Wed, 1 Apr 2026 06:12:33 -0500 Subject: [PATCH] fix(rtp_transceiver): trigger renegotiation on set_direction (closes #51) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per W3C WebRTC §5.5, changing an RTCRtpTransceiver's direction must trigger the negotiation-needed flag so the application knows to create a new offer/answer exchange. The internal set_direction() had a TODO noting this was missing. The fix lives in the public RTCRtpTransceiver::set_direction() wrapper, which already holds &mut RTCPeerConnection and can call trigger_negotiation_needed() directly after detecting a direction change. Also broaden trigger_negotiation_needed() visibility from pub(super) to pub(crate) so rtp_transceiver/mod.rs can reach it. Co-Authored-By: Claude Sonnet 4.6 --- rtc/src/peer_connection/internal.rs | 2 +- rtc/src/rtp_transceiver/internal.rs | 3 --- rtc/src/rtp_transceiver/mod.rs | 5 +++++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rtc/src/peer_connection/internal.rs b/rtc/src/peer_connection/internal.rs index 63d36276..57da134b 100644 --- a/rtc/src/peer_connection/internal.rs +++ b/rtc/src/peer_connection/internal.rs @@ -847,7 +847,7 @@ where } /// Helper to trigger a negotiation needed. - pub(super) fn trigger_negotiation_needed(&mut self) { + pub(crate) fn trigger_negotiation_needed(&mut self) { if !self.do_negotiation_needed() { return; } diff --git a/rtc/src/rtp_transceiver/internal.rs b/rtc/src/rtp_transceiver/internal.rs index efe19780..34612bb9 100644 --- a/rtc/src/rtp_transceiver/internal.rs +++ b/rtc/src/rtp_transceiver/internal.rs @@ -155,9 +155,6 @@ where if direction != previous_direction { trace!("Changing direction of transceiver from {previous_direction} to {direction}"); - - //TODO: https://www.w3.org/TR/webrtc/#dom-rtcrtptransceiver-direction - // Update the negotiation-needed flag for connection. } } diff --git a/rtc/src/rtp_transceiver/mod.rs b/rtc/src/rtp_transceiver/mod.rs index 1eacff2f..b9901810 100644 --- a/rtc/src/rtp_transceiver/mod.rs +++ b/rtc/src/rtp_transceiver/mod.rs @@ -289,7 +289,12 @@ where pub fn set_direction(&mut self, direction: RTCRtpTransceiverDirection) { // peer_connection is mutable borrow, its rtp_transceivers won't be resized, // so, [self.id] here is safe. + let previous = self.peer_connection.rtp_transceivers[self.id].direction(); self.peer_connection.rtp_transceivers[self.id].set_direction(direction); + // Per W3C WebRTC §5.5: changing direction must trigger renegotiation. + if direction != previous { + self.peer_connection.trigger_negotiation_needed(); + } } /// Returns the negotiated direction of the transceiver.