update desktop capturer and remove unnessary vars

This commit is contained in:
Shelley Vohr 2017-10-24 12:01:51 -04:00
parent 1672fd22e1
commit 43e118fe45
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -1,46 +1,40 @@
const ipcRenderer = require('electron').ipcRenderer
const nativeImage = require('electron').nativeImage
const {ipcRenderer, nativeImage} = require('electron')
var nextId = 0
var includes = [].includes
const includes = [].includes
let currentId = 0
var getNextId = function () {
return ++nextId
}
const incrementId = () => currentId += 1
// |options.type| can not be empty and has to include 'window' or 'screen'.
var isValid = function (options) {
return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types)
function isValid (options) {
const types = (options != null) ? options.types : undefined
return (types != null) && Array.isArray(options.types)
}
exports.getSources = function (options, callback) {
var captureScreen, captureWindow, id
if (!isValid(options)) {
return callback(new Error('Invalid options'))
}
captureWindow = includes.call(options.types, 'window')
captureScreen = includes.call(options.types, 'screen')
if (!isValid(options)) return callback(new Error('Invalid options'))
const captureWindow = includes.call(options.types, 'window')
const captureScreen = includes.call(options.types, 'screen')
if (options.thumbnailSize == null) {
options.thumbnailSize = {
width: 150,
height: 150
}
}
id = getNextId()
const id = incrementId()
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, id)
return ipcRenderer.once('ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function (event, sources) {
var source
callback(null, (function () {
var i, len, results
return ipcRenderer.once(`ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_${id}`, (event, sources) => {
callback(null, (() => {
results = []
for (i = 0, len = sources.length; i < len; i++) {
source = sources[i]
sources.forEach(source => {
results.push({
id: source.id,
name: source.name,
thumbnail: nativeImage.createFromDataURL(source.thumbnail)
})
}
})
return results
})())
})