fix(presenter): resize desktop track to 720p when presenter starts

This commit is contained in:
Jaya Allamsetty 2020-02-04 16:33:57 -05:00 committed by Jaya Allamsetty
parent 18536cb14c
commit 7b25b847ba
2 changed files with 32 additions and 11 deletions

View File

@ -1665,19 +1665,40 @@ export default {
return; return;
} }
// Create a new presenter track and apply the presenter effect.
if (!this.localPresenterVideo && !mute) { if (!this.localPresenterVideo && !mute) {
// create a new presenter track and apply the presenter effect. let { aspectRatio, height } = this.localVideo.track.getSettings();
let { 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 // Determine the constraints if the desktop track needs to be resized.
// that is being currently shared. // Resizing is needed when the resolution cannot be determined or when
if (!height) { // the window is bigger than 720p.
const desktopResizeConstraints = { 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, width: 1280,
height: 720, height: 720
resizeMode: 'crop-and-scale'
}; };
}
if (resizeDesktopStream) {
try { try {
await this.localVideo.track.applyConstraints(desktopResizeConstraints); await this.localVideo.track.applyConstraints(desktopResizeConstraints);
} catch (err) { } catch (err) {
@ -1685,7 +1706,7 @@ export default {
return; return;
} }
height = desktopResizeConstraints.height; height = this.localVideo.track.getSettings().height ?? DESKTOP_STREAM_CAP;
} }
const defaultCamera = getUserSelectedCameraDeviceId(APP.store.getState()); const defaultCamera = getUserSelectedCameraDeviceId(APP.store.getState());
let effect; let effect;

View File

@ -27,7 +27,7 @@ export async function createLocalPresenterTrack(options, desktopHeight) {
// compute the constraints of the camera track based on the resolution // compute the constraints of the camera track based on the resolution
// of the desktop screen that is being shared. // 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 proportion = 4;
const result = cameraHeights.find( const result = cameraHeights.find(
height => (desktopHeight / proportion) < height); height => (desktopHeight / proportion) < height);