Skip to content

chore: improve handling of errors on screen share negotiation - #41372

Merged
pierre-lehnen-rc merged 4 commits into
developfrom
fix/screen-share-video-unsupported
Jul 31, 2026
Merged

chore: improve handling of errors on screen share negotiation#41372
pierre-lehnen-rc merged 4 commits into
developfrom
fix/screen-share-video-unsupported

Conversation

@pierre-lehnen-rc

@pierre-lehnen-rc pierre-lehnen-rc commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Proposed changes (including videos or screenshots)

Improves handling of errors when trying to share the screen with a peer that doesn't support video. This is only a refactor of the code in anticipation of this becoming a possibility, but since currently screen share is only available on internal calls, this change doesn't affect anything.

Issue(s)

Derived from DMV-44

Steps to test or reproduce

Further comments

Written on top of #41366

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of screen sharing when swapping or reusing video tracks.
    • Prevented premature stopping of an in-use screen-share track during video track updates.
    • Enhanced media tracking by using transceiver state to decide when to replace tracks.
    • Added safer recovery during renegotiation when audio/video transceivers are stopped, including automatically clearing the local screen-share video when needed.
    • Reduced media update failures during changing connection states.

@dionisio-bot

dionisio-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 8.8.0, but it targets 8.7.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7b8d966

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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 Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Screen-share replacement now updates WebRTC before stopping the previous track. Media stream synchronization uses active transceivers, handles connection state guards, and reacts when negotiation finds only stopped transceivers.

Changes

Media signaling updates

Layer / File(s) Summary
Track replacement through active transceivers
packages/media-signaling/src/lib/Call.ts, packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
Screen-share replacement preserves the old track until WebRTC updates. Track synchronization selects active transceivers and handles replacement failures.
Stopped-transceiver direction handling
packages/media-signaling/src/lib/services/webrtc/Processor.ts
Direction negotiation skips stopped transceivers and clears the screen-share track when sending is requested without a usable transceiver.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • RocketChat/Rocket.Chat#41366: Both changes update screen-share handling through WebRTC transceiver direction and stopped-transceiver logic.

Suggested labels: type: chore

Suggested reviewers: gabriellsh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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 Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: improved error handling during screen share negotiation.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • DMV-44: Request failed with status code 401

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.

@pierre-lehnen-rc pierre-lehnen-rc added this to the 8.7.0 milestone Jul 14, 2026
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.76%. Comparing base (0e20907) to head (629f72d).
⚠️ Report is 109 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41372      +/-   ##
===========================================
+ Coverage    68.52%   68.76%   +0.23%     
===========================================
  Files         4114     4155      +41     
  Lines       159688   159672      -16     
  Branches     28938    28161     -777     
===========================================
+ Hits        109432   109794     +362     
+ Misses       45213    44700     -513     
- Partials      5043     5178     +135     
Flag Coverage Δ
e2e 58.84% <ø> (-0.16%) ⬇️
e2e-api 45.98% <ø> (+0.62%) ⬆️
unit 70.70% <ø> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from chore/screen-share-with-no-data to develop July 16, 2026 20:49
@pierre-lehnen-rc
pierre-lehnen-rc marked this pull request as ready for review July 16, 2026 21:23
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jul 16, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 16, 2026

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/media-signaling/src/lib/Call.ts (1)

580-580: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the implementation comment.

The ordering should be clear from the code or an extracted method name.

As per coding guidelines, “Avoid code comments in the implementation.”

🤖 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/media-signaling/src/lib/Call.ts` at line 580, Remove the
implementation comment immediately above the track-stop logic in Call, leaving
the existing behavior and ordering unchanged.

Source: Coding guidelines

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

Inline comments:
In `@packages/media-signaling/src/lib/Call.ts`:
- Around line 574-578: The screen-share track replacement must be atomic across
both affected sites: in packages/media-signaling/src/lib/Call.ts lines 566-583,
update the flow around screenVideoTrack and webrtcProcessor.setScreenVideoTrack
so the new track is published only after replacement succeeds, or restore
oldVideoTrack on failure; in
packages/media-signaling/src/lib/media/MediaStreamWrapper.ts lines 218-236, make
sender.replaceTrack() failures propagate or roll back the wrapper state instead
of only logging them.

---

Nitpick comments:
In `@packages/media-signaling/src/lib/Call.ts`:
- Line 580: Remove the implementation comment immediately above the track-stop
logic in Call, leaving the existing behavior and ordering unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 470f484a-3e21-4134-ba5f-d621e2a5d62d

📥 Commits

Reviewing files that changed from the base of the PR and between 0e20907 and 1165431.

📒 Files selected for processing (3)
  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
🔇 Additional comments (2)
packages/media-signaling/src/lib/media/MediaStreamWrapper.ts (1)

36-38: LGTM!

Also applies to: 249-253

packages/media-signaling/src/lib/services/webrtc/Processor.ts (1)

383-391: 🎯 Functional Correctness

No change needed herecurrentDirection is the signal for a stopped transceiver; direction is the requested state and should not be used to gate this fallback.

			> Likely an incorrect or invalid review comment.

Comment thread packages/media-signaling/src/lib/Call.ts

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
Comment thread packages/media-signaling/src/lib/media/MediaStreamWrapper.ts
@pierre-lehnen-rc pierre-lehnen-rc removed the stat: QA assured Means it has been tested and approved by a company insider label Jul 22, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 22, 2026
@pierre-lehnen-rc pierre-lehnen-rc modified the milestones: 8.7.0, 8.8.0 Jul 22, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/media-signaling/src/lib/media/MediaStreamWrapper.ts

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/media-signaling/src/lib/media/MediaStreamWrapper.ts Outdated
@pierre-lehnen-rc
pierre-lehnen-rc force-pushed the fix/screen-share-video-unsupported branch from 629f72d to 7b8d966 Compare July 31, 2026 16:27
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jul 31, 2026
@pierre-lehnen-rc
pierre-lehnen-rc added this pull request to the merge queue Jul 31, 2026
Merged via the queue into develop with commit 94478c6 Jul 31, 2026
103 checks passed
@pierre-lehnen-rc
pierre-lehnen-rc deleted the fix/screen-share-video-unsupported branch July 31, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants