From 7b25b847ba1e0b198a0f63138c408342d00e6de7 Mon Sep 17 00:00:00 2001 From: Jaya Allamsetty Date: Tue, 4 Feb 2020 16:33:57 -0500 Subject: [PATCH] fix(presenter): resize desktop track to 720p when presenter starts --- conference.js | 41 +++++++++++++++++++------ react/features/base/tracks/functions.js | 2 +- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/conference.js b/conference.js index f329dedd5..ff8aecda7 100644 --- a/conference.js +++ b/conference.js @@ -1665,19 +1665,40 @@ export default { return; } + // Create a new presenter track and apply the presenter effect. if (!this.localPresenterVideo && !mute) { - // create a new presenter track and apply the presenter effect. - let { height } = this.localVideo.track.getSettings(); + let { aspectRatio, height } = this.localVideo.track.getSettings(); + const { width } = this.localVideo.track.getSettings(); + let desktopResizeConstraints = {}; + let resizeDesktopStream = false; + const DESKTOP_STREAM_CAP = 720; - // Workaround for Firefox since it doesn't return the correct width/height of the desktop stream - // that is being currently shared. - if (!height) { - const desktopResizeConstraints = { + // Determine the constraints if the desktop track needs to be resized. + // Resizing is needed when the resolution cannot be determined or when + // the window is bigger than 720p. + if (height && width) { + aspectRatio = aspectRatio ?? (width / height).toPrecision(4); + const advancedConstraints = [ { aspectRatio } ]; + const isPortrait = height >= width; + + // Determine which dimension needs resizing and resize only that side + // keeping the aspect ratio same as before. + if (isPortrait && width > DESKTOP_STREAM_CAP) { + resizeDesktopStream = true; + advancedConstraints.push({ width: DESKTOP_STREAM_CAP }); + } else if (!isPortrait && height > DESKTOP_STREAM_CAP) { + resizeDesktopStream = true; + advancedConstraints.push({ height: DESKTOP_STREAM_CAP }); + } + desktopResizeConstraints.advanced = advancedConstraints; + } else { + resizeDesktopStream = true; + desktopResizeConstraints = { width: 1280, - height: 720, - resizeMode: 'crop-and-scale' + height: 720 }; - + } + if (resizeDesktopStream) { try { await this.localVideo.track.applyConstraints(desktopResizeConstraints); } catch (err) { @@ -1685,7 +1706,7 @@ export default { return; } - height = desktopResizeConstraints.height; + height = this.localVideo.track.getSettings().height ?? DESKTOP_STREAM_CAP; } const defaultCamera = getUserSelectedCameraDeviceId(APP.store.getState()); let effect; diff --git a/react/features/base/tracks/functions.js b/react/features/base/tracks/functions.js index 9d8a59dca..fcfdf2eab 100644 --- a/react/features/base/tracks/functions.js +++ b/react/features/base/tracks/functions.js @@ -27,7 +27,7 @@ export async function createLocalPresenterTrack(options, desktopHeight) { // compute the constraints of the camera track based on the resolution // of the desktop screen that is being shared. - const cameraHeights = [ 180, 270, 360, 540, 720 ]; + const cameraHeights = [ 120, 180, 240, 360, 480, 600, 720 ]; const proportion = 4; const result = cameraHeights.find( height => (desktopHeight / proportion) < height);