feat(client): honor SFU degradationPreference on the publisher#2241
Conversation
Picks up the new DegradationPreference enum + fields from protocol PR #1886 (PublishOption.degradation_preference, VideoSender.degradation_preference) and wires them through the Publisher: - addTransceiver uses the publish option's degradationPreference, falling back to 'maintain-framerate' when UNSPECIFIED or absent. - changePublishQuality applies the value carried on the SFU's changePublishQuality event to the sender's RTCRtpSendParameters, re-using the existing skip-setParameters-when-unchanged guard. A small helper maps the protobuf enum to RTCDegradationPreference, covering the non-standard MAINTAIN_FRAMERATE_AND_RESOLUTION value that isn't in the WebRTC typedefs yet.
|
📝 WalkthroughWalkthroughThis PR adds support for RTC degradation preferences in the video Publisher. A new helper function converts internal degradation preference enum values to RTC-compatible strings. Publisher uses this helper during transceiver initialization and quality change updates, with comprehensive test coverage for all cases. ChangesRTC Degradation Preference Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/client/src/rtc/helpers/degradationPreference.ts (1)
14-16: ⚡ Quick winConsider a fallback for cross-browser degradation preference consistency.
'maintain-framerate-and-resolution'is currently supported only in Chrome 144+; Firefox and Safari ignore this value and fall back to their default behavior without throwing an error. While this won't cause a runtime failure, it results in inconsistent video degradation behavior across browsers. If you want to ensure the same degradation preference applies universally, consider adding a fallback to'maintain-framerate'for unsupported browsers.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/client/src/rtc/helpers/degradationPreference.ts` around lines 14 - 16, The mapping for DegradationPreference.MAINTAIN_FRAMERATE_AND_RESOLUTION currently returns the Chrome-only string 'maintain-framerate-and-resolution'; update the mapping in packages/client/src/rtc/helpers/degradationPreference.ts so that it falls back to 'maintain-framerate' for browsers that don't support the Chrome 144+ value—detect support either via a lightweight userAgent check for Chrome 144+ or by feature-detecting the string (e.g., checking if RTCRtpEncodingParameters accepts 'maintain-framerate-and-resolution'), and return 'maintain-framerate-and-resolution' only when supported, otherwise return 'maintain-framerate' for cross-browser consistency when handling DegradationPreference.MAINTAIN_FRAMERATE_AND_RESOLUTION.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/client/src/rtc/helpers/degradationPreference.ts`:
- Around line 14-16: The mapping for
DegradationPreference.MAINTAIN_FRAMERATE_AND_RESOLUTION currently returns the
Chrome-only string 'maintain-framerate-and-resolution'; update the mapping in
packages/client/src/rtc/helpers/degradationPreference.ts so that it falls back
to 'maintain-framerate' for browsers that don't support the Chrome 144+
value—detect support either via a lightweight userAgent check for Chrome 144+ or
by feature-detecting the string (e.g., checking if RTCRtpEncodingParameters
accepts 'maintain-framerate-and-resolution'), and return
'maintain-framerate-and-resolution' only when supported, otherwise return
'maintain-framerate' for cross-browser consistency when handling
DegradationPreference.MAINTAIN_FRAMERATE_AND_RESOLUTION.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 39ad3043-60e0-48bf-a957-c1b3c97d81c6
⛔ Files ignored due to path filters (2)
packages/client/src/gen/video/sfu/event/events.tsis excluded by!**/gen/**packages/client/src/gen/video/sfu/models/models.tsis excluded by!**/gen/**
📒 Files selected for processing (4)
packages/client/src/rtc/Publisher.tspackages/client/src/rtc/__tests__/Publisher.test.tspackages/client/src/rtc/helpers/__tests__/degradationPreference.test.tspackages/client/src/rtc/helpers/degradationPreference.ts
💡 Overview
Picks up
DegradationPreferencefrom protocol PR #1886 and wires it through thePublisherso the SFU can drive the WebRTC degradation preference instead of it being hard-coded.🎫 Ticket: https://linear.app/stream/issue/XYZ-123