ELECTRON-540 - Add support for automatic selection of desktop capturer source (#404)

- Add support to automatic selection of desktop capturer source
- constraint return statements
- Remove unwanted ELECTRON_QA env
- Fix arg issue
This commit is contained in:
Kiran Niranjan
2018-06-25 14:36:20 +05:30
committed by Vishwas Shashidhar
parent 70957ccdb6
commit 5ad6ca12d0
3 changed files with 65 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ const USER_CANCELLED = 'User Cancelled';
let nextId = 0;
let includes = [].includes;
let screenShareArgv;
function getNextId() {
return ++nextId;
@@ -79,6 +80,25 @@ function getSource(options, callback) {
id = getNextId();
desktopCapturer.getSources({ types: sourceTypes, thumbnailSize: updatedOptions.thumbnailSize }, (event, sources) => {
if (screenShareArgv) {
const title = screenShareArgv.substr(screenShareArgv.indexOf('=') + 1);
const filteredSource = sources.filter(source => source.name === title);
if (Array.isArray(filteredSource) && filteredSource.length > 0) {
return callback(null, filteredSource[0]);
}
if (typeof filteredSource === 'object' && filteredSource.name) {
return callback(null, filteredSource);
}
if (sources.length > 0) {
return callback(null, sources[0]);
}
}
const updatedSources = sources.map(source => {
return Object.assign({}, source, {
thumbnail: source.thumbnail.toDataURL()
@@ -102,7 +122,15 @@ function getSource(options, callback) {
const func = successCallback.bind(this);
ipcRenderer.once('start-share' + id, func);
return null;
});
}
// event that updates screen share argv
ipcRenderer.once('screen-share-argv', (event, arg) => {
if (typeof arg === 'string') {
screenShareArgv = arg;
}
});
module.exports = getSource;