Add a display_id parameter to the desktopCapturer API. (#12417)
* 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. * Fix non-Windows build. * Fix Mac. * Fix Mac harder. * JS lint * clang-format C++ code. * IWYU * display_id, Linux comment, better test * lint * Fix tests on Linux. * Add display_id documentation.
This commit is contained in:
parent
89f2eb1023
commit
6bfb122cd1
6 changed files with 119 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
const assert = require('assert')
|
||||
const {desktopCapturer, remote} = require('electron')
|
||||
const {desktopCapturer, remote, screen} = require('electron')
|
||||
|
||||
const isCI = remote.getGlobal('isCi')
|
||||
|
||||
|
@ -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,33 @@ describe('desktopCapturer', () => {
|
|||
desktopCapturer.getSources({types: ['window']}, callback)
|
||||
desktopCapturer.getSources({types: ['screen']}, callback)
|
||||
})
|
||||
|
||||
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)
|
||||
sources.forEach((source) => { assert.equal(source.display_id.length, 0) })
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns display_ids matching the Screen API on Windows and Mac', (done) => {
|
||||
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
||||
return done()
|
||||
}
|
||||
const displays = screen.getAllDisplays()
|
||||
desktopCapturer.getSources({types: ['screen']}, (error, sources) => {
|
||||
assert.equal(error, null)
|
||||
assert.notEqual(sources.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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue