From d253f23e84c1ba382b86ac9f4e3985a186475b26 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Mon, 1 Oct 2018 15:05:29 -0700 Subject: [PATCH] feat: disable fetching thumbnails if thumbnailSize is 0 Capturing window thmubnails is expensive as it actually uses the window capturer and it records one full frame per window and then downscale to the default size 150x150. When only interested in the window names or the app icons we do not need all of this. Underlying change is merged in chromium72 so this patch only modifies the doc, see: https://chromium.googlesource.com/chromium/src.git/+log/72.0.3626.52/chrome/browser/media/webrtc/native_desktop_media_list.cc Example: desktopCapturer.getSources({thumbnailSize: {width: 0, height: 0}}, ...) Also added a unit test in spec/api-desktop-capturer-spec.js that verifies that the returned thumbails are of type NativeImage and empty, when the user disable fetching thumbnails. notes: Can disable fetching the thumbnails for the DesktopCapturer. https://github.com/electron/electron/issues/14872 --- docs/api/desktop-capturer.md | 8 ++++++-- spec/api-desktop-capturer-spec.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index d4e51c123bcb7..b48786e69bf44 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -82,7 +82,9 @@ The `desktopCapturer` module has the following methods: * `types` String[] - An array of Strings that lists the types of desktop sources to be captured, available types are `screen` and `window`. * `thumbnailSize` [Size](structures/size.md) (optional) - The size that the media source thumbnail - should be scaled to. Default is `150` x `150`. + should be scaled to. Default is `150` x `150`. Set width or height to 0 when you do not need + the thumbnails. This will save the processing time required for capturing the content of each + window and screen. * `fetchWindowIcons` Boolean (optional) - Set to true to enable fetching window icons. The default value is false. When false the appIcon property of the sources return null. Same if a source has the type screen. @@ -107,7 +109,9 @@ captured. * `types` String[] - An array of Strings that lists the types of desktop sources to be captured, available types are `screen` and `window`. * `thumbnailSize` [Size](structures/size.md) (optional) - The size that the media source thumbnail - should be scaled to. Default is `150` x `150`. + should be scaled to. Default is `150` x `150`. Set width or height to 0 when you do not need + the thumbnails. This will save the processing time required for capturing the content of each + window and screen. * `fetchWindowIcons` Boolean (optional) - Set to true to enable fetching window icons. The default value is false. When false the appIcon property of the sources return null. Same if a source has the type screen. diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 60d90c881b8f9..22df5db6c2e4a 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -4,6 +4,7 @@ const chaiAsPromised = require('chai-as-promised') const { desktopCapturer, ipcRenderer, remote } = require('electron') const { screen } = remote const features = process.atomBinding('features') +const { emittedOnce } = require('./events-helpers') const { expect } = chai chai.use(dirtyChai) @@ -105,4 +106,20 @@ describe('desktopCapturer', () => { expect(sources).to.be.empty() }) }) + + it('disabling thumbnail should return empty images', async () => { + const { BrowserWindow } = remote + const w = new BrowserWindow({ show: false, width: 200, height: 200 }) + const wShown = emittedOnce(w, 'show') + w.show() + await wShown + + const sources = await desktopCapturer.getSources({ types: ['window', 'screen'], thumbnailSize: { width: 0, height: 0 } }) + w.destroy() + expect(sources).to.be.an('array').that.is.not.empty() + for (const { thumbnail: thumbnailImage } of sources) { + expect(thumbnailImage).to.be.a('NativeImage') + expect(thumbnailImage.isEmpty()).to.be.true() + } + }) })