From 79c07f893eb6db39eeea69fd08f519685589cb0e Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Thu, 7 Mar 2024 19:30:43 +0100 Subject: [PATCH 1/2] Remove Chrome getDisplayMedia shim the variant which used an extension to polyfill it. This was never on by default and should be obsolete. Fixes #1139 --- src/js/chrome/chrome_shim.js | 1 - src/js/chrome/getdisplaymedia.js | 50 -------------------------------- 2 files changed, 51 deletions(-) delete mode 100644 src/js/chrome/getdisplaymedia.js diff --git a/src/js/chrome/chrome_shim.js b/src/js/chrome/chrome_shim.js index 46aee7e2f..4acab1655 100644 --- a/src/js/chrome/chrome_shim.js +++ b/src/js/chrome/chrome_shim.js @@ -10,7 +10,6 @@ import * as utils from '../utils.js'; export {shimGetUserMedia} from './getusermedia'; -export {shimGetDisplayMedia} from './getdisplaymedia'; export function shimMediaStream(window) { window.MediaStream = window.MediaStream || window.webkitMediaStream; diff --git a/src/js/chrome/getdisplaymedia.js b/src/js/chrome/getdisplaymedia.js deleted file mode 100644 index 1e8f6ec5a..000000000 --- a/src/js/chrome/getdisplaymedia.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ -/* eslint-env node */ -'use strict'; -export function shimGetDisplayMedia(window, getSourceId) { - if (window.navigator.mediaDevices && - 'getDisplayMedia' in window.navigator.mediaDevices) { - return; - } - if (!(window.navigator.mediaDevices)) { - return; - } - // getSourceId is a function that returns a promise resolving with - // the sourceId of the screen/window/tab to be shared. - if (typeof getSourceId !== 'function') { - console.error('shimGetDisplayMedia: getSourceId argument is not ' + - 'a function'); - return; - } - window.navigator.mediaDevices.getDisplayMedia = - function getDisplayMedia(constraints) { - return getSourceId(constraints) - .then(sourceId => { - const widthSpecified = constraints.video && constraints.video.width; - const heightSpecified = constraints.video && - constraints.video.height; - const frameRateSpecified = constraints.video && - constraints.video.frameRate; - constraints.video = { - mandatory: { - chromeMediaSource: 'desktop', - chromeMediaSourceId: sourceId, - maxFrameRate: frameRateSpecified || 3 - } - }; - if (widthSpecified) { - constraints.video.mandatory.maxWidth = widthSpecified; - } - if (heightSpecified) { - constraints.video.mandatory.maxHeight = heightSpecified; - } - return window.navigator.mediaDevices.getUserMedia(constraints); - }); - }; -} From fdf88a461d0d7a1d1bad24c563a1f00d6866f727 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Sun, 24 Mar 2024 12:34:24 -0700 Subject: [PATCH 2/2] remove tests too --- test/unit/chrome.test.js | 96 ---------------------------------------- 1 file changed, 96 deletions(-) diff --git a/test/unit/chrome.test.js b/test/unit/chrome.test.js index c6cc26730..edac9e5b6 100644 --- a/test/unit/chrome.test.js +++ b/test/unit/chrome.test.js @@ -111,100 +111,4 @@ describe('Chrome shim', () => { shim.shimGetUserMedia(window); }); }); - - describe('getDisplayMedia shim', () => { - const getSourceId = jest.fn().mockReturnValue(Promise.resolve('abc')); - - it('does not overwrite an existing ' + - 'navigator.mediaDevices.getDisplayMedia', () => { - window.navigator.mediaDevices.getDisplayMedia = 'foo'; - shim.shimGetDisplayMedia(window, getSourceId); - expect(window.navigator.mediaDevices.getDisplayMedia).toBe('foo'); - }); - - it('does not if navigator.mediaDevices does not exist', () => { - delete window.navigator.mediaDevices; - shim.shimGetDisplayMedia(window); - expect(window.navigator.mediaDevices).toBe(undefined); - }); - - it('shims navigator.mediaDevices.getDisplayMedia', () => { - shim.shimGetDisplayMedia(window, getSourceId); - expect(typeof window.navigator.mediaDevices.getDisplayMedia) - .toBe('function'); - }); - - it('calls getUserMedia with the sourceId', async() => { - shim.shimGetDisplayMedia(window, getSourceId); - await window.navigator.mediaDevices.getDisplayMedia({video: true}); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) - .toBe(1); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) - .toEqual({ - video: { - mandatory: { - chromeMediaSource: 'desktop', - chromeMediaSourceId: 'abc', - maxFrameRate: 3, - } - } - }); - }); - - it('translates frameRate to legacy maxFrameRate', async() => { - shim.shimGetDisplayMedia(window, getSourceId); - await window.navigator.mediaDevices - .getDisplayMedia({video: {frameRate: 25}}); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) - .toBe(1); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) - .toEqual({ - video: { - mandatory: { - chromeMediaSource: 'desktop', - chromeMediaSourceId: 'abc', - maxFrameRate: 25, - } - } - }); - }); - - it('translates width to legacy maxWidth', async() => { - shim.shimGetDisplayMedia(window, getSourceId); - await window.navigator.mediaDevices - .getDisplayMedia({video: {width: 640}}); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) - .toBe(1); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) - .toEqual({ - video: { - mandatory: { - chromeMediaSource: 'desktop', - chromeMediaSourceId: 'abc', - maxFrameRate: 3, - maxWidth: 640, - } - } - }); - }); - - it('translates height to legacy maxHeight', async() => { - shim.shimGetDisplayMedia(window, getSourceId); - await window.navigator.mediaDevices - .getDisplayMedia({video: {height: 480}}); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls.length) - .toBe(1); - expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]) - .toEqual({ - video: { - mandatory: { - chromeMediaSource: 'desktop', - chromeMediaSourceId: 'abc', - maxFrameRate: 3, - maxHeight: 480, - } - } - }); - }); - }); });