tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug2000906-teams.microsoft.com-disable-resizeMode-in-gDM.js (1956B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Bug 2000906 - Microsoft Teams, for getDisplayMedia requests resizeMode: "none" but expects downscaling and frameRate decimation
      9 *
     10 * If a constraint for width, height or frameRate is present together with resizeMode: "none", we clear resizeMode.
     11 * Chrome seems to incorrectly ignore the resizeMode constraint for getDisplayMedia.
     12 */
     13 
     14 /* globals exportFunction */
     15 
     16 console.info(
     17  'getDisplayMedia has been modified to drop resizeMode: "none" for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=2000906 for details.'
     18 );
     19 
     20 function maybeDeleteResizeMode(video) {
     21  const { resizeMode, width, height, frameRate } = video;
     22  if (resizeMode == "none" && (width || height || frameRate)) {
     23    delete video.resizeMode;
     24  }
     25 }
     26 
     27 if (navigator.mediaDevices?.getDisplayMedia) {
     28  {
     29    const { prototype } = MediaDevices.wrappedJSObject;
     30    const { getDisplayMedia: gDM } = prototype;
     31    prototype.getDisplayMedia = exportFunction(function getDisplayMedia(
     32      options
     33    ) {
     34      const { video } = options || {};
     35      if (video) {
     36        maybeDeleteResizeMode(video);
     37      }
     38      return gDM.call(this, options);
     39    }, window);
     40  }
     41 
     42  {
     43    const { prototype } = MediaStreamTrack.wrappedJSObject;
     44    const { applyConstraints: aC } = prototype;
     45    prototype.applyConstraints = exportFunction(function applyConstraints(
     46      constraints
     47    ) {
     48      // Don't allow adding resizeMode if it wasn't there from the start.
     49      // Ideally we'd check for a gDM-sourced track instead but there's no
     50      // spec-compliant way to do that.
     51      if (!this.getConstraints().resizeMode) {
     52        maybeDeleteResizeMode(constraints || {});
     53      }
     54      return aC.call(this, constraints);
     55    }, window);
     56  }
     57 }