Skip to content

chore: auto detect screen share based on video direction - #41366

Merged
dionisio-bot[bot] merged 1 commit into
developfrom
chore/screen-share-with-no-data
Jul 16, 2026
Merged

chore: auto detect screen share based on video direction#41366
dionisio-bot[bot] merged 1 commit into
developfrom
chore/screen-share-with-no-data

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)

The current screen share implementation relies on a data channel to notify the other side that the screen share has started/stopped. This PR removes that dependency on the data channel and makes both sides of the call auto detect when screen sharing is enabled or not based on the state of video exchange in the connection.

Issue(s)

Derived from DMV-44

Steps to test or reproduce

Further comments

Also solves this flaky test:
https://github.com/RocketChat/Rocket.Chat/actions/runs/29510595480/job/87668479725

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved screen-sharing state synchronization during WebRTC negotiations.
    • Reduced unnecessary peer-to-peer commands for screen sharing, improving connection reliability.
    • Improved handling of remote screen-share status and active connection state.
    • Simplified data-channel readiness handling for more consistent call behavior.

@dionisio-bot

dionisio-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
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: e882195

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

MediaCallWebRTCProcessor now handles screen sharing through WebRTC transceiver directions rather than P2P screen-share commands, while adding remote stream synchronization after negotiation and centralizing active-connection checks.

Changes

WebRTC screen-share signaling

Layer / File(s) Summary
P2P command handling
packages/media-signaling/src/lib/services/webrtc/Processor.ts
The data-channel command union and validation now allow only mute, unmute, and end; screen-share command cases were removed and the open-state guard was simplified.
Local screen-share direction updates
packages/media-signaling/src/lib/services/webrtc/Processor.ts
Screen-share track changes update video transceiver direction instead of sending screen-share P2P commands.
Post-negotiation remote screen state
packages/media-signaling/src/lib/services/webrtc/Processor.ts
Post-negotiation processing updates remote screen-share state from receiving video transceiver directions and uses a centralized active-connection check.

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

Sequence Diagram(s)

sequenceDiagram
  participant LocalScreenShare
  participant MediaCallWebRTCProcessor
  participant RTCPeerConnection
  participant RemoteScreenShareState
  LocalScreenShare->>MediaCallWebRTCProcessor: loadScreenVideoTrack()
  MediaCallWebRTCProcessor->>RTCPeerConnection: updateDirectionForVideoTrackChanged()
  RTCPeerConnection-->>MediaCallWebRTCProcessor: negotiated video transceiver directions
  MediaCallWebRTCProcessor->>RemoteScreenShareState: updateRemoteScreenShare()
Loading
🚥 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 matches the main change: screen share is now auto-detected from video direction instead of data-channel commands.

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.

@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.18%. Comparing base (460858e) to head (e882195).
⚠️ Report is 25 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41366      +/-   ##
===========================================
- Coverage    69.12%   68.18%   -0.95%     
===========================================
  Files         3762     3968     +206     
  Lines       147936   154740    +6804     
  Branches     26428    27844    +1416     
===========================================
+ Hits        102261   105504    +3243     
- Misses       41185    44443    +3258     
- Partials      4490     4793     +303     
Flag Coverage Δ
e2e 59.21% <ø> (-0.01%) ⬇️
e2e-api 44.04% <ø> (-5.38%) ⬇️
unit 70.60% <ø> (-0.03%) ⬇️

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.

@pierre-lehnen-rc
pierre-lehnen-rc marked this pull request as ready for review July 14, 2026 16:29
@pierre-lehnen-rc pierre-lehnen-rc added this to the 8.7.0 milestone Jul 14, 2026
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jul 14, 2026
@dionisio-bot dionisio-bot Bot removed the stat: QA assured Means it has been tested and approved by a company insider label Jul 14, 2026
@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label Jul 14, 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.

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

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

Avoid redundant state updates and logs when activating.

To make the activation logic symmetric with the deactivation logic below, consider checking !this.streams.screenShareRemote.active before logging and calling setActive(true). This prevents redundant logs and method calls during subsequent WebRTC renegotiations if the screen share is already active. Additionally, we can swap the backticks for single quotes since there's no string interpolation.

♻️ Proposed refactor
			if (transceiver.currentDirection.includes('recv')) {
-				this.config.logger?.debug(`Video Transceiver is receiving; enabling screen-share`);
-				this.streams.screenShareRemote.setActive(true);
+				if (!this.streams.screenShareRemote.active) {
+					this.config.logger?.debug('Video Transceiver is receiving; enabling screen-share');
+					this.streams.screenShareRemote.setActive(true);
+				}
				return;
			}
		}

		if (this.streams.screenShareRemote.active) {
-			this.config.logger?.debug(`No video Transceiver is receiving, disabling screen-share`);
+			this.config.logger?.debug('No video Transceiver is receiving; disabling screen-share');
			this.streams.screenShareRemote.setActive(false);
		}
🤖 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/services/webrtc/Processor.ts` around lines
631 - 642, Update the activation branch in the transceiver direction handling to
guard the debug log and streams.screenShareRemote.setActive(true) with
!this.streams.screenShareRemote.active, mirroring the existing deactivation
check. Use a single-quoted string for the non-interpolated debug message.
🤖 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/media-signaling/src/lib/services/webrtc/Processor.ts`:
- Around line 631-642: Update the activation branch in the transceiver direction
handling to guard the debug log and streams.screenShareRemote.setActive(true)
with !this.streams.screenShareRemote.active, mirroring the existing deactivation
check. Use a single-quoted string for the non-interpolated debug message.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e480bff7-2bc1-4d0b-880c-ad61acd30143

📥 Commits

Reviewing files that changed from the base of the PR and between c4bede4 and e882195.

📒 Files selected for processing (1)
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • 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/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/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/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/services/webrtc/Processor.ts
🔇 Additional comments (1)
packages/media-signaling/src/lib/services/webrtc/Processor.ts (1)

10-10: LGTM!

Also applies to: 478-480, 529-530, 593-597, 686-689, 780-781

@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

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

Re-trigger cubic

Comment thread packages/media-signaling/src/lib/services/webrtc/Processor.ts
Comment thread packages/media-signaling/src/lib/services/webrtc/Processor.ts
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jul 14, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 14, 2026

@gabriellsh gabriellsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@gabriellsh gabriellsh removed the stat: QA assured Means it has been tested and approved by a company insider label Jul 16, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 16, 2026
@gabriellsh gabriellsh 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
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 16, 2026
Merged via the queue into develop with commit 0e20907 Jul 16, 2026
48 checks passed
@dionisio-bot
dionisio-bot Bot deleted the chore/screen-share-with-no-data branch July 16, 2026 20:49
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 stat: ready to merge PR tested and approved waiting for merge type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants