fix(rtp_transceiver): trigger renegotiation on set_direction (closes #51)#71
fix(rtp_transceiver): trigger renegotiation on set_direction (closes #51)#71nightness wants to merge 7 commits into
Conversation
e08e980 to
6ad88b6
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates transceiver direction changes to correctly trigger WebRTC renegotiation, aligning behavior with W3C WebRTC §5.5 and closing #51.
Changes:
- Trigger
negotiationneededwhenRTCRtpTransceiver::set_direction()actually changes the direction. - Remove the resolved TODO from the internal transceiver implementation.
- Broaden
trigger_negotiation_needed()visibility to enable calling it from the transceiver wrapper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| rtc/src/rtp_transceiver/mod.rs | Triggers negotiation-needed on actual direction changes in the public wrapper. |
| rtc/src/rtp_transceiver/internal.rs | Removes obsolete TODO/comments after behavior is implemented elsewhere. |
| rtc/src/peer_connection/internal.rs | Expands helper visibility to allow cross-module invocation within the crate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #71 +/- ##
=======================================
Coverage 71.17% 71.17%
=======================================
Files 442 442
Lines 67330 67330
=======================================
+ Hits 47922 47925 +3
+ Misses 19408 19405 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rainliu
left a comment
There was a problem hiding this comment.
since this involves public API's behavior change, please add unit test and integration test to verify negotiation is actually trigged when direction is changed.
|
Moved the |
|
Addressed Copilot review comments:
|
|
Added integration test (
This complements the existing unit tests which verify the same behavior at the internal level. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ebrtc-rs#51) 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 <noreply@anthropic.com>
…irection The internal set_direction() doesn't trigger negotiation, so the trace belongs in the public wrapper (mod.rs) where the actual negotiation logic lives. This also removes the now-unnecessary previous_direction variable from the internal setter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Keep trigger_negotiation_needed as pub(super); expose a narrow pub(crate) on_transceiver_direction_changed() method instead of broadening the general helper's visibility - Add tests verifying (1) changing direction triggers OnNegotiationNeededEvent and (2) setting the same direction is a no-op Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verifies through the public Protocol API that: 1. Changing direction triggers OnNegotiationNeededEvent 2. Setting the same direction is a no-op (no event) Uses a full offer/answer cycle with registered Opus codecs, STUN server config, and host candidates to properly initialize the negotiation state machine before testing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compare the transceiver's actual direction after the setter rather than the requested value. This is more robust if set_direction ever normalizes or refuses a value in the future. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The inline #[cfg(test)] mod tests block now exists in this file, making the commented-out TODO for a separate test module misleading. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace `use sansio::Protocol` with `use rtc::sansio::Protocol` for clarity (the import IS needed for poll_event()) - Replace hard-coded UDP ports 10000/10001 with OS-assigned ephemeral ports via 127.0.0.1:0 binding - Rewrite unit tests to use offer/answer cycle + poll_event() instead of internal state manipulation (pipeline_context.event_outs.clear() and reset_negotiation_state()) - Remove test-only reset_negotiation_state() helper from RTCPeerConnection Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
893f362 to
2d05d1d
Compare
|
Rebased onto upstream/master so this PR contains only its own changes. Previous branch structure caused merge conflicts when PRs were merged in sequence. Each PR is now independently mergeable. |
Summary
RTCRtpTransceiver::set_direction()now callstrigger_negotiation_needed()on the peer connection when the direction actually changes, per W3C WebRTC §5.5pub(crate) on_transceiver_direction_changed()method to keeptrigger_negotiation_neededatpub(super)visibilitytrace!log is moved frominternal.rstomod.rswhere the negotiation logic livesprevious_directionvariable ininternal.rsis removed//TODO: #[cfg(test)] mod rtp_transceiver_test;comment since inline tests now existReview feedback addressed
trace!from internalset_directionto publicset_direction(commit 731341b)set_direction, not input (commit e17adf6)pub(crate)exposure viaon_transceiver_direction_changed()(commit 2252d20)rtp_transceiver_testmodule (commit 8d816eb)Test plan
cargo build -p rtcpassescargo test -p rtcpasses (246 lib tests + 28 integration tests, 0 failures)cargo fmt --checkcleancargo clippycleantest_set_direction_triggers_negotiation_on_change— verifiesOnNegotiationNeededEventis emitted when direction changestest_set_direction_noop_when_unchanged— verifies no event when setting the same directiontest_set_direction_change_triggers_renegotiation— full offer/answer cycle via publicProtocolAPI with Opus codecs, STUN server, and host candidates; assertspoll_event()returnsOnNegotiationNeededEventon direction change and no event on same-direction setGenerated with Claude Code