Skip to content

Commit

Permalink
feat(ScreenObtainer): add more control over screen obtainer (jitsi#2371)
Browse files Browse the repository at this point in the history
* feat(ScreenObtainer): add more control over screen obtainer

* fix(ScreenObtainer): fix constraints to select a preferential display surface

* fix(ScreenObtainer): remove Safari version check for displaySurface

* fix(ScreenObtainer): move all settings under screenShareSettings
  • Loading branch information
DanielMcAssey authored and subhamcyara committed Jul 19, 2024
1 parent 2db7ce8 commit 65eaa4f
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions modules/RTC/ScreenObtainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ const ScreenObtainer = {

const audio = this._getAudioConstraints();
let video = {};
const { desktopSharingFrameRate } = this.options;
const constraintOpts = {};
const {
desktopSharingFrameRate,
screenShareSettings
} = this.options;

if (typeof desktopSharingFrameRate === 'object') {
video.frameRate = desktopSharingFrameRate;
Expand All @@ -200,8 +204,25 @@ const ScreenObtainer = {
video.frameRate && delete video.frameRate.min;

if (browser.isChromiumBased()) {
// Show users the current tab is the preferred capture source, default: false.
browser.isEngineVersionGreaterThan(93)
&& (constraintOpts.preferCurrentTab = screenShareSettings?.desktopPreferCurrentTab || false);

// Allow users to select system audio, default: include.
browser.isEngineVersionGreaterThan(104)
&& (constraintOpts.systemAudio = screenShareSettings?.desktopSystemAudio || 'include');

// Allow users to seamlessly switch which tab they are sharing without having to select the tab again.
browser.isEngineVersionGreaterThan(106) && (video.surfaceSwitching = 'include');
browser.isEngineVersionGreaterThan(106)
&& (constraintOpts.surfaceSwitching = screenShareSettings?.desktopSurfaceSwitching || 'include');

// Allow a user to be shown a preference for what screen is to be captured, default: unset.
browser.isEngineVersionGreaterThan(106) && screenShareSettings?.desktopDisplaySurface
&& (video.displaySurface = screenShareSettings?.desktopDisplaySurface);

// Allow users to select the current tab as a capture source, default: exclude.
browser.isEngineVersionGreaterThan(111)
&& (constraintOpts.selfBrowserSurface = screenShareSettings?.desktopSelfBrowserSurface || 'exclude');

// Set bogus resolution constraints to work around
// https://bugs.chromium.org/p/chromium/issues/detail?id=1056311 for low fps screenshare. Capturing SS at
Expand All @@ -212,13 +233,19 @@ const ScreenObtainer = {
}
}

// Allow a user to be shown a preference for what screen is to be captured.
if (browser.isSafari() && screenShareSettings?.desktopDisplaySurface) {
video.displaySurface = screenShareSettings?.desktopDisplaySurface;
}

if (Object.keys(video).length === 0) {
video = true;
}

const constraints = {
video,
audio,
...constraintOpts,
cursor: 'always'
};

Expand Down

0 comments on commit 65eaa4f

Please sign in to comment.