From a2ebe3cad8686923aee0e30df85280f0abf145d9 Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Thu, 22 Mar 2018 21:32:10 -0700 Subject: [PATCH 01/11] Add a screen_api_id parameter to the desktopCapturer API. When using the DirectX capturer on Windows, there was previously no way to associate desktopCapturer/getUserMedia and electron.screen API screens. This new parameter provides the association. --- atom/browser/api/atom_api_desktop_capturer.cc | 60 +++++++++++++++++-- atom/browser/api/atom_api_desktop_capturer.h | 7 +++ lib/browser/desktop-capturer.js | 3 +- lib/renderer/api/desktop-capturer.js | 3 +- spec/api-desktop-capturer-spec.js | 23 ++++++- 5 files changed, 87 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index d27838ad22d64..8e1b590d11d30 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -8,28 +8,36 @@ using base::PlatformThreadRef; #include "atom/common/api/atom_api_native_image.h" #include "atom/common/native_mate_converters/gfx_converter.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/media/desktop_media_list.h" #include "content/public/browser/desktop_capture.h" #include "native_mate/dictionary.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" +#if defined(OS_WIN) +#include "third_party/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h" +#include "ui/display/win/display_info.h" +#endif // defined(OS_WIN) #include "atom/common/node_includes.h" namespace mate { template<> -struct Converter { +struct Converter { static v8::Local ToV8(v8::Isolate* isolate, - const DesktopMediaList::Source& source) { + const atom::api::DesktopCapturer::Source& source) { mate::Dictionary dict(isolate, v8::Object::New(isolate)); - content::DesktopMediaID id = source.id; - dict.Set("name", base::UTF16ToUTF8(source.name)); + content::DesktopMediaID id = source.media_list_source.id; + dict.Set("name", base::UTF16ToUTF8(source.media_list_source.name)); dict.Set("id", id.ToString()); dict.Set( "thumbnail", - atom::api::NativeImage::Create(isolate, gfx::Image(source.thumbnail))); + atom::api::NativeImage::Create( + isolate, + gfx::Image(source.media_list_source.thumbnail))); + dict.Set("screen_api_id", source.screen_api_id); return ConvertToV8(isolate, dict); } }; @@ -52,6 +60,7 @@ void DesktopCapturer::StartHandling(bool capture_window, const gfx::Size& thumbnail_size) { webrtc::DesktopCaptureOptions options = content::CreateDesktopCaptureOptions(); + using_directx_capturer_ = options.allow_directx_capturer(); std::unique_ptr screen_capturer( capture_screen ? webrtc::DesktopCapturer::CreateScreenCapturer(options) @@ -82,7 +91,46 @@ void DesktopCapturer::OnSourceThumbnailChanged(int index) { } bool DesktopCapturer::OnRefreshFinished() { - Emit("finished", media_list_->GetSources()); + const auto media_list_sources = media_list_->GetSources(); + std::vector sources; + for (const auto& media_list_source : media_list_sources) { + sources.emplace_back(DesktopCapturer::Source{media_list_source, + std::string()}); + } + +#if defined(OS_WIN) + // Gather the same unique screen IDs used by the electron.screen API in order + // to provide an association between it and desktopCapturer/getUserMedia. + // This is only required when using the DirectX capturer, otherwise the IDs + // across the APIs already match. + if (using_directx_capturer_) { + std::vector device_names; + // Crucially, this list of device names will be in the same order as + // |media_list_sources|. + webrtc::DxgiDuplicatorController::Instance()->GetDeviceNames(&device_names); + int device_name_index = 0; + for (auto& source : sources) { + if (source.media_list_source.id.type == + content::DesktopMediaID::TYPE_SCREEN) { + const auto& device_name = device_names[device_name_index++]; + std::wstring wide_device_name; + base::UTF8ToWide(device_name.c_str(), device_name.size(), + &wide_device_name); + const int64_t device_id = + display::win::DisplayInfo::DeviceIdFromDeviceName( + wide_device_name.c_str()); + source.screen_api_id = base::Int64ToString(device_id); + } + } + } +#elif defined(OS_MAC) + // On Mac, the IDs across the APIs match. + for (auto& source : sources) { + source.screen_api_id = base::Int64ToString(source.id); + } +#endif // defined(OS_WIN) + + Emit("finished", sources); return false; } diff --git a/atom/browser/api/atom_api_desktop_capturer.h b/atom/browser/api/atom_api_desktop_capturer.h index 571f08bcfc63c..4a5b875afd09f 100644 --- a/atom/browser/api/atom_api_desktop_capturer.h +++ b/atom/browser/api/atom_api_desktop_capturer.h @@ -17,6 +17,12 @@ namespace api { class DesktopCapturer: public mate::EventEmitter, public DesktopMediaListObserver { public: + struct Source { + DesktopMediaList::Source media_list_source; + // Will be an empty string if not available. + std::string screen_api_id; + }; + static mate::Handle Create(v8::Isolate* isolate); static void BuildPrototype(v8::Isolate* isolate, @@ -40,6 +46,7 @@ class DesktopCapturer: public mate::EventEmitter, private: std::unique_ptr media_list_; + bool using_directx_capturer_; DISALLOW_COPY_AND_ASSIGN(DesktopCapturer); }; diff --git a/lib/browser/desktop-capturer.js b/lib/browser/desktop-capturer.js index 48a7a2ad69189..4412d5be47cb7 100644 --- a/lib/browser/desktop-capturer.js +++ b/lib/browser/desktop-capturer.js @@ -43,7 +43,8 @@ desktopCapturer.emit = (event, name, sources) => { return { id: source.id, name: source.name, - thumbnail: source.thumbnail.toDataURL() + thumbnail: source.thumbnail.toDataURL(), + screen_api_id: source.screen_api_id } }) diff --git a/lib/renderer/api/desktop-capturer.js b/lib/renderer/api/desktop-capturer.js index b9320c893fcd6..51ac7c45b64f9 100644 --- a/lib/renderer/api/desktop-capturer.js +++ b/lib/renderer/api/desktop-capturer.js @@ -35,7 +35,8 @@ exports.getSources = function (options, callback) { results.push({ id: source.id, name: source.name, - thumbnail: nativeImage.createFromDataURL(source.thumbnail) + thumbnail: nativeImage.createFromDataURL(source.thumbnail), + screen_api_id: source.screen_api_id }) }) return results diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index de623162e59d2..2d4ecf75aafb4 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -40,7 +40,7 @@ describe('desktopCapturer', () => { desktopCapturer.getSources({types: ['window', 'screen']}, callback) }) - it('responds to subsequest calls of different options', (done) => { + it('responds to subsequent calls of different options', (done) => { let callCount = 0 const callback = (error, sources) => { callCount++ @@ -51,4 +51,25 @@ describe('desktopCapturer', () => { desktopCapturer.getSources({types: ['window']}, callback) desktopCapturer.getSources({types: ['screen']}, callback) }) + + it('returns an empty screen_api_id for window sources', (done) => { + desktopCapturer.getSources({types: ['window']}, (error, sources) => { + assert.equal(error, null) + assert.notEqual(sources.length, 0) + sources.forEach((source) => { assert.equal(source.screen_api_id.length, 0) }) + done() + }) + }) + + it('returns a populated screen_api_id for screen sources on Windows and Mac', (done) => { + if (process.platform !== 'win32' && process.platform !== 'mac') { + this.skip(); + } + desktopCapturer.getSources({types: ['screen']}, (error, sources) => { + assert.equal(error, null) + assert.notEqual(sources.length, 0) + sources.forEach((source) => { assert.notEqual(source.screen_api_id.length, 0) }) + done() + }) + }) }) From 47b6a23cd930d4c543f8cdeff696b22f30b757ff Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Thu, 22 Mar 2018 22:05:18 -0700 Subject: [PATCH 02/11] Fix non-Windows build. --- atom/browser/api/atom_api_desktop_capturer.cc | 2 ++ atom/browser/api/atom_api_desktop_capturer.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 8e1b590d11d30..5a9f5fcbf2a91 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -60,7 +60,9 @@ void DesktopCapturer::StartHandling(bool capture_window, const gfx::Size& thumbnail_size) { webrtc::DesktopCaptureOptions options = content::CreateDesktopCaptureOptions(); +#if defined(OS_WIN) using_directx_capturer_ = options.allow_directx_capturer(); +#endif // defined(OS_WIN) std::unique_ptr screen_capturer( capture_screen ? webrtc::DesktopCapturer::CreateScreenCapturer(options) diff --git a/atom/browser/api/atom_api_desktop_capturer.h b/atom/browser/api/atom_api_desktop_capturer.h index 4a5b875afd09f..d1493a1ef08ac 100644 --- a/atom/browser/api/atom_api_desktop_capturer.h +++ b/atom/browser/api/atom_api_desktop_capturer.h @@ -46,7 +46,9 @@ class DesktopCapturer: public mate::EventEmitter, private: std::unique_ptr media_list_; +#if defined(OS_WIN) bool using_directx_capturer_; +#endif // defined(OS_WIN) DISALLOW_COPY_AND_ASSIGN(DesktopCapturer); }; From 7dee08811f3ad32f4597c9d6b7c23fe5f504963b Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Thu, 22 Mar 2018 22:22:32 -0700 Subject: [PATCH 03/11] Fix Mac. --- atom/browser/api/atom_api_desktop_capturer.cc | 4 ++-- spec/api-desktop-capturer-spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 5a9f5fcbf2a91..2dc5c14eec896 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -125,10 +125,10 @@ bool DesktopCapturer::OnRefreshFinished() { } } } -#elif defined(OS_MAC) +#elif defined(OS_MACOSX) // On Mac, the IDs across the APIs match. for (auto& source : sources) { - source.screen_api_id = base::Int64ToString(source.id); + source.screen_api_id = base::Int64ToString(source.media_list_source.id.id); } #endif // defined(OS_WIN) diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 2d4ecf75aafb4..991bc32ed4149 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -62,8 +62,8 @@ describe('desktopCapturer', () => { }) it('returns a populated screen_api_id for screen sources on Windows and Mac', (done) => { - if (process.platform !== 'win32' && process.platform !== 'mac') { - this.skip(); + if (process.platform !== 'win32' && process.platform !== 'darwin') { + done(); } desktopCapturer.getSources({types: ['screen']}, (error, sources) => { assert.equal(error, null) From ca19b7e834155523cb937fe846a16c109984ff8d Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Thu, 22 Mar 2018 22:24:44 -0700 Subject: [PATCH 04/11] Fix Mac harder. --- atom/browser/api/atom_api_desktop_capturer.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 2dc5c14eec896..6bf18a616c9da 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -128,7 +128,10 @@ bool DesktopCapturer::OnRefreshFinished() { #elif defined(OS_MACOSX) // On Mac, the IDs across the APIs match. for (auto& source : sources) { - source.screen_api_id = base::Int64ToString(source.media_list_source.id.id); + if (source.media_list_source.id.type == + content::DesktopMediaID::TYPE_SCREEN) { + source.screen_api_id = base::Int64ToString(source.media_list_source.id.id); + } } #endif // defined(OS_WIN) From 2b34a7ea7f0a569676625937616bc50ff740202c Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Fri, 23 Mar 2018 09:47:00 -0700 Subject: [PATCH 05/11] JS lint --- spec/api-desktop-capturer-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 991bc32ed4149..3f03b8e01094d 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -63,7 +63,7 @@ describe('desktopCapturer', () => { it('returns a populated screen_api_id for screen sources on Windows and Mac', (done) => { if (process.platform !== 'win32' && process.platform !== 'darwin') { - done(); + done() } desktopCapturer.getSources({types: ['screen']}, (error, sources) => { assert.equal(error, null) From 29ffd9d1c620b33a67408af52510f46745aeb0b8 Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Fri, 23 Mar 2018 09:48:55 -0700 Subject: [PATCH 06/11] clang-format C++ code. --- atom/browser/api/atom_api_desktop_capturer.cc | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 6bf18a616c9da..7fff4b8a541fb 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -24,19 +24,18 @@ using base::PlatformThreadRef; namespace mate { -template<> +template <> struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const atom::api::DesktopCapturer::Source& source) { + static v8::Local ToV8( + v8::Isolate* isolate, + const atom::api::DesktopCapturer::Source& source) { mate::Dictionary dict(isolate, v8::Object::New(isolate)); content::DesktopMediaID id = source.media_list_source.id; dict.Set("name", base::UTF16ToUTF8(source.media_list_source.name)); dict.Set("id", id.ToString()); - dict.Set( - "thumbnail", - atom::api::NativeImage::Create( - isolate, - gfx::Image(source.media_list_source.thumbnail))); + dict.Set("thumbnail", + atom::api::NativeImage::Create( + isolate, gfx::Image(source.media_list_source.thumbnail))); dict.Set("screen_api_id", source.screen_api_id); return ConvertToV8(isolate, dict); } @@ -96,8 +95,8 @@ bool DesktopCapturer::OnRefreshFinished() { const auto media_list_sources = media_list_->GetSources(); std::vector sources; for (const auto& media_list_source : media_list_sources) { - sources.emplace_back(DesktopCapturer::Source{media_list_source, - std::string()}); + sources.emplace_back( + DesktopCapturer::Source{media_list_source, std::string()}); } #if defined(OS_WIN) @@ -130,7 +129,8 @@ bool DesktopCapturer::OnRefreshFinished() { for (auto& source : sources) { if (source.media_list_source.id.type == content::DesktopMediaID::TYPE_SCREEN) { - source.screen_api_id = base::Int64ToString(source.media_list_source.id.id); + source.screen_api_id = + base::Int64ToString(source.media_list_source.id.id); } } #endif // defined(OS_WIN) From 9b698dd882c2a777f99968f65e2806402411307b Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Fri, 23 Mar 2018 10:01:44 -0700 Subject: [PATCH 07/11] IWYU --- atom/browser/api/atom_api_desktop_capturer.cc | 2 ++ atom/browser/api/atom_api_desktop_capturer.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 7fff4b8a541fb..f723072122f65 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -4,6 +4,8 @@ #include "atom/browser/api/atom_api_desktop_capturer.h" +#include + using base::PlatformThreadRef; #include "atom/common/api/atom_api_native_image.h" diff --git a/atom/browser/api/atom_api_desktop_capturer.h b/atom/browser/api/atom_api_desktop_capturer.h index d1493a1ef08ac..491d34852e937 100644 --- a/atom/browser/api/atom_api_desktop_capturer.h +++ b/atom/browser/api/atom_api_desktop_capturer.h @@ -5,6 +5,8 @@ #ifndef ATOM_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_ #define ATOM_BROWSER_API_ATOM_API_DESKTOP_CAPTURER_H_ +#include + #include "atom/browser/api/event_emitter.h" #include "chrome/browser/media/desktop_media_list_observer.h" #include "chrome/browser/media/native_desktop_media_list.h" From b6fbdd5e80ab7c5e7c1c6286205a07ea66ceada0 Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Mon, 26 Mar 2018 22:52:18 -0700 Subject: [PATCH 08/11] display_id, Linux comment, better test --- atom/browser/api/atom_api_desktop_capturer.cc | 9 ++++++--- atom/browser/api/atom_api_desktop_capturer.h | 2 +- lib/browser/desktop-capturer.js | 2 +- lib/renderer/api/desktop-capturer.js | 2 +- spec/api-desktop-capturer-spec.js | 14 +++++++++----- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index f723072122f65..b99fc24ce3616 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -38,7 +38,7 @@ struct Converter { dict.Set("thumbnail", atom::api::NativeImage::Create( isolate, gfx::Image(source.media_list_source.thumbnail))); - dict.Set("screen_api_id", source.screen_api_id); + dict.Set("display_id", source.display_id); return ConvertToV8(isolate, dict); } }; @@ -122,7 +122,7 @@ bool DesktopCapturer::OnRefreshFinished() { const int64_t device_id = display::win::DisplayInfo::DeviceIdFromDeviceName( wide_device_name.c_str()); - source.screen_api_id = base::Int64ToString(device_id); + source.display_id = base::Int64ToString(device_id); } } } @@ -131,11 +131,14 @@ bool DesktopCapturer::OnRefreshFinished() { for (auto& source : sources) { if (source.media_list_source.id.type == content::DesktopMediaID::TYPE_SCREEN) { - source.screen_api_id = + source.display_id = base::Int64ToString(source.media_list_source.id.id); } } #endif // defined(OS_WIN) +// TODO: Add Linux support. The IDs across APIs differ but Chrome only supports +// capturing the entire desktop on Linux. Revisit this if individual screen +// support is added. Emit("finished", sources); return false; diff --git a/atom/browser/api/atom_api_desktop_capturer.h b/atom/browser/api/atom_api_desktop_capturer.h index 491d34852e937..77058896e0b4f 100644 --- a/atom/browser/api/atom_api_desktop_capturer.h +++ b/atom/browser/api/atom_api_desktop_capturer.h @@ -22,7 +22,7 @@ class DesktopCapturer: public mate::EventEmitter, struct Source { DesktopMediaList::Source media_list_source; // Will be an empty string if not available. - std::string screen_api_id; + std::string display_id; }; static mate::Handle Create(v8::Isolate* isolate); diff --git a/lib/browser/desktop-capturer.js b/lib/browser/desktop-capturer.js index 4412d5be47cb7..c7fe1abf67c0a 100644 --- a/lib/browser/desktop-capturer.js +++ b/lib/browser/desktop-capturer.js @@ -44,7 +44,7 @@ desktopCapturer.emit = (event, name, sources) => { id: source.id, name: source.name, thumbnail: source.thumbnail.toDataURL(), - screen_api_id: source.screen_api_id + display_id: source.display_id } }) diff --git a/lib/renderer/api/desktop-capturer.js b/lib/renderer/api/desktop-capturer.js index 51ac7c45b64f9..75d3a258bf0e4 100644 --- a/lib/renderer/api/desktop-capturer.js +++ b/lib/renderer/api/desktop-capturer.js @@ -36,7 +36,7 @@ exports.getSources = function (options, callback) { id: source.id, name: source.name, thumbnail: nativeImage.createFromDataURL(source.thumbnail), - screen_api_id: source.screen_api_id + display_id: source.display_id }) }) return results diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 3f03b8e01094d..eed4b0afc09b9 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -1,5 +1,5 @@ const assert = require('assert') -const {desktopCapturer, remote} = require('electron') +const {desktopCapturer, remote, screen} = require('electron') const isCI = remote.getGlobal('isCi') @@ -52,23 +52,27 @@ describe('desktopCapturer', () => { desktopCapturer.getSources({types: ['screen']}, callback) }) - it('returns an empty screen_api_id for window sources', (done) => { + it('returns an empty display_id for window sources', (done) => { desktopCapturer.getSources({types: ['window']}, (error, sources) => { assert.equal(error, null) assert.notEqual(sources.length, 0) - sources.forEach((source) => { assert.equal(source.screen_api_id.length, 0) }) + sources.forEach((source) => { assert.equal(source.display_id.length, 0) }) done() }) }) - it('returns a populated screen_api_id for screen sources on Windows and Mac', (done) => { + it('returns display_ids matching the Screen API on Windows and Mac', (done) => { if (process.platform !== 'win32' && process.platform !== 'darwin') { done() } + const displays = screen.getAllDisplays(); desktopCapturer.getSources({types: ['screen']}, (error, sources) => { assert.equal(error, null) assert.notEqual(sources.length, 0) - sources.forEach((source) => { assert.notEqual(source.screen_api_id.length, 0) }) + assert.equal(sources.length, displays.length) + for (let i = 0; i < sources.length; i++) { + assert.equal(sources[i].display_id, displays[i].id) + } done() }) }) From 3534fdfb6a63da52724a0c85d9aa406e32f25c9d Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Tue, 27 Mar 2018 09:59:52 -0700 Subject: [PATCH 09/11] lint --- atom/browser/api/atom_api_desktop_capturer.cc | 6 +++--- spec/api-desktop-capturer-spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index b99fc24ce3616..9c3042a0eca16 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -136,9 +136,9 @@ bool DesktopCapturer::OnRefreshFinished() { } } #endif // defined(OS_WIN) -// TODO: Add Linux support. The IDs across APIs differ but Chrome only supports -// capturing the entire desktop on Linux. Revisit this if individual screen -// support is added. +// TODO(ajmacd): Add Linux support. The IDs across APIs differ but Chrome only +// supports capturing the entire desktop on Linux. Revisit this if individual +// screen support is added. Emit("finished", sources); return false; diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index eed4b0afc09b9..2f42afa26704c 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -65,7 +65,7 @@ describe('desktopCapturer', () => { if (process.platform !== 'win32' && process.platform !== 'darwin') { done() } - const displays = screen.getAllDisplays(); + const displays = screen.getAllDisplays() desktopCapturer.getSources({types: ['screen']}, (error, sources) => { assert.equal(error, null) assert.notEqual(sources.length, 0) From e2c7790990d3a100deff6fa3c224e37e715703f5 Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Tue, 27 Mar 2018 10:24:25 -0700 Subject: [PATCH 10/11] Fix tests on Linux. --- spec/api-desktop-capturer-spec.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 2f42afa26704c..c85220bce6578 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -52,7 +52,11 @@ describe('desktopCapturer', () => { desktopCapturer.getSources({types: ['screen']}, callback) }) - it('returns an empty display_id for window sources', (done) => { + it('returns an empty display_id for window sources on Windows and Mac', (done) => { + // Linux doesn't return any window sources. + if (process.platform !== 'win32' && process.platform !== 'darwin') { + return done() + } desktopCapturer.getSources({types: ['window']}, (error, sources) => { assert.equal(error, null) assert.notEqual(sources.length, 0) @@ -63,7 +67,7 @@ describe('desktopCapturer', () => { it('returns display_ids matching the Screen API on Windows and Mac', (done) => { if (process.platform !== 'win32' && process.platform !== 'darwin') { - done() + return done() } const displays = screen.getAllDisplays() desktopCapturer.getSources({types: ['screen']}, (error, sources) => { From 77f494eaf988ceeec3ddbf122b7e2d82b621a24a Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Wed, 28 Mar 2018 20:07:18 -0700 Subject: [PATCH 11/11] Add display_id documentation. --- docs/api/structures/desktop-capturer-source.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/api/structures/desktop-capturer-source.md b/docs/api/structures/desktop-capturer-source.md index 3ebe4ce49c700..083f9e64f0a8d 100644 --- a/docs/api/structures/desktop-capturer-source.md +++ b/docs/api/structures/desktop-capturer-source.md @@ -12,3 +12,8 @@ `thumbnailSize` specified in the `options` passed to `desktopCapturer.getSources`. The actual size depends on the scale of the screen or window. +* `display_id` String - A unique identifier that will correspond to the `id` of + the matching [Display](display.md) returned by the [Screen API](../screen.md). + On some platforms, this is equivalent to the `XX` portion of the `id` field + above and on others it will differ. It will be an empty string if not + available.