Skip to content

feat(client): honor SFU degradationPreference on the publisher#2241

Merged
oliverlaz merged 1 commit into
mainfrom
feat/publisher-degradation-preference
May 18, 2026
Merged

feat(client): honor SFU degradationPreference on the publisher#2241
oliverlaz merged 1 commit into
mainfrom
feat/publisher-degradation-preference

Conversation

@oliverlaz

@oliverlaz oliverlaz commented May 18, 2026

Copy link
Copy Markdown
Member

💡 Overview

Picks up DegradationPreference from protocol PR #1886 and wires it through the Publisher so the SFU can drive the WebRTC degradation preference instead of it being hard-coded.

🎫 Ticket: https://linear.app/stream/issue/XYZ-123

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.
@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a0fbc8c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This 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.

Changes

RTC Degradation Preference Support

Layer / File(s) Summary
Degradation preference conversion helper
packages/client/src/rtc/helpers/degradationPreference.ts, packages/client/src/rtc/helpers/__tests__/degradationPreference.test.ts
New toRTCDegradationPreference helper converts DegradationPreference enum values to RTC string forms (balanced, maintain-framerate, maintain-resolution, maintain-framerate-and-resolution), returning undefined for UNSPECIFIED, with unit tests covering each variant.
Publisher degradation preference integration
packages/client/src/rtc/Publisher.ts, packages/client/src/rtc/__tests__/Publisher.test.ts
Publisher imports and applies degradation preference during transceiver initialization with maintain-framerate fallback, and during quality updates when preferences differ. Test fixtures, event payloads, and invocations are updated with explicit preferences, and new tests verify that quality changes correctly apply and respect degradation preferences.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A preference flows through channels new,
RTC strings from enums true—
Framerate balanced, resolution kept,
Publisher's quality deeply stepped!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding support for SFU-driven degradation preference in the publisher, which is the core objective of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description includes the required Overview section and ticket reference, but is missing the optional Implementation notes and Docs sections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/publisher-degradation-preference

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@oliverlaz oliverlaz requested a review from jdimovska May 18, 2026 09:23

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/client/src/rtc/helpers/degradationPreference.ts (1)

14-16: ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between d3f017b and a0fbc8c.

⛔ Files ignored due to path filters (2)
  • packages/client/src/gen/video/sfu/event/events.ts is excluded by !**/gen/**
  • packages/client/src/gen/video/sfu/models/models.ts is excluded by !**/gen/**
📒 Files selected for processing (4)
  • packages/client/src/rtc/Publisher.ts
  • packages/client/src/rtc/__tests__/Publisher.test.ts
  • packages/client/src/rtc/helpers/__tests__/degradationPreference.test.ts
  • packages/client/src/rtc/helpers/degradationPreference.ts

@oliverlaz oliverlaz merged commit 85b34a3 into main May 18, 2026
20 checks passed
@oliverlaz oliverlaz deleted the feat/publisher-degradation-preference branch May 18, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants