Browse Source

ref(presenter): refactor the desktop resize logic for presenter.

master
Jaya Allamsetty 4 years ago
parent
commit
1e07385ac0
1 changed files with 23 additions and 24 deletions
  1. 23
    24
      conference.js

+ 23
- 24
conference.js View File

@@ -1651,39 +1651,37 @@ export default {
1651 1651
         // Create a new presenter track and apply the presenter effect.
1652 1652
         if (!this.localPresenterVideo && !mute) {
1653 1653
             const { height, width } = this.localVideo.track.getSettings() ?? this.localVideo.track.getConstraints();
1654
-            let desktopResizeConstraints = {};
1655
-            let resizeDesktopStream = false;
1654
+            const isPortrait = height >= width;
1656 1655
             const DESKTOP_STREAM_CAP = 720;
1657 1656
 
1658
-            // Resizing the desktop track for presenter is causing blurriness of the desktop share.
1659
-            // Disable this behavior for now until it is fixed in Chrome. The stream needs to be resized
1660
-            // Firefox always.
1661
-            if ((config.videoQuality && config.videoQuality.resizeDesktopForPresenter) || browser.isFirefox()) {
1662
-                // Resizing is needed when the window is bigger than 720p.
1657
+            // Config.js setting for resizing high resolution desktop tracks to 720p when presenter is turned on.
1658
+            const resizeEnabled = config.videoQuality && config.videoQuality.resizeDesktopForPresenter;
1659
+            const highResolutionTrack
1660
+                = (isPortrait && width > DESKTOP_STREAM_CAP) || (!isPortrait && height > DESKTOP_STREAM_CAP);
1661
+
1662
+            // Resizing the desktop track for presenter is causing blurriness of the desktop share on chrome.
1663
+            // Disable resizing by default, enable it only when config.js setting is enabled.
1664
+            // Firefox doesn't return width and height for desktop tracks. Therefore, track needs to be resized
1665
+            // for creating the canvas for presenter.
1666
+            const resizeDesktopStream = browser.isFirefox() || (highResolutionTrack && resizeEnabled);
1667
+
1668
+            if (resizeDesktopStream) {
1669
+                let desktopResizeConstraints = {};
1670
+
1663 1671
                 if (height && width) {
1664 1672
                     const advancedConstraints = [ { aspectRatio: (width / height).toPrecision(4) } ];
1665
-                    const isPortrait = height >= width;
1666
-
1667
-                    // Determine which dimension needs resizing and resize only that side
1668
-                    // keeping the aspect ratio same as before.
1669
-                    if (isPortrait && width > DESKTOP_STREAM_CAP) {
1670
-                        resizeDesktopStream = true;
1671
-                        advancedConstraints.push({ width: DESKTOP_STREAM_CAP });
1672
-                    } else if (!isPortrait && height > DESKTOP_STREAM_CAP) {
1673
-                        resizeDesktopStream = true;
1674
-                        advancedConstraints.push({ height: DESKTOP_STREAM_CAP });
1675
-                    }
1673
+                    const constraint = isPortrait ? { width: DESKTOP_STREAM_CAP } : { height: DESKTOP_STREAM_CAP };
1674
+
1675
+                    advancedConstraints.push(constraint);
1676 1676
                     desktopResizeConstraints.advanced = advancedConstraints;
1677 1677
                 } else {
1678
-                    resizeDesktopStream = true;
1679 1678
                     desktopResizeConstraints = {
1680 1679
                         width: 1280,
1681 1680
                         height: 720
1682 1681
                     };
1683 1682
                 }
1684
-            }
1685 1683
 
1686
-            if (resizeDesktopStream) {
1684
+                // Apply the contraints on the desktop track.
1687 1685
                 try {
1688 1686
                     await this.localVideo.track.applyConstraints(desktopResizeConstraints);
1689 1687
                 } catch (err) {
@@ -1695,17 +1693,18 @@ export default {
1695 1693
             const trackHeight = resizeDesktopStream
1696 1694
                 ? this.localVideo.track.getSettings().height ?? DESKTOP_STREAM_CAP
1697 1695
                 : height;
1698
-            const defaultCamera = getUserSelectedCameraDeviceId(APP.store.getState());
1699 1696
             let effect;
1700 1697
 
1701 1698
             try {
1702
-                effect = await this._createPresenterStreamEffect(trackHeight, defaultCamera);
1699
+                effect = await this._createPresenterStreamEffect(trackHeight);
1703 1700
             } catch (err) {
1704
-                logger.error('Failed to unmute Presenter Video');
1701
+                logger.error('Failed to unmute Presenter Video', err);
1705 1702
                 maybeShowErrorDialog(err);
1706 1703
 
1707 1704
                 return;
1708 1705
             }
1706
+
1707
+            // Replace the desktop track on the peerconnection.
1709 1708
             try {
1710 1709
                 await this.localVideo.setEffect(effect);
1711 1710
                 APP.store.dispatch(setVideoMuted(mute, MEDIA_TYPE.PRESENTER));

Loading…
Cancel
Save