update desktop capturer and remove unnessary vars
This commit is contained in:
parent
1672fd22e1
commit
43e118fe45
1 changed files with 17 additions and 23 deletions
|
@ -1,46 +1,40 @@
|
||||||
const ipcRenderer = require('electron').ipcRenderer
|
const {ipcRenderer, nativeImage} = require('electron')
|
||||||
const nativeImage = require('electron').nativeImage
|
|
||||||
|
|
||||||
var nextId = 0
|
const includes = [].includes
|
||||||
var includes = [].includes
|
let currentId = 0
|
||||||
|
|
||||||
var getNextId = function () {
|
const incrementId = () => currentId += 1
|
||||||
return ++nextId
|
|
||||||
}
|
|
||||||
|
|
||||||
// |options.type| can not be empty and has to include 'window' or 'screen'.
|
// |options.type| can not be empty and has to include 'window' or 'screen'.
|
||||||
var isValid = function (options) {
|
function isValid (options) {
|
||||||
return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types)
|
const types = (options != null) ? options.types : undefined
|
||||||
|
return (types != null) && Array.isArray(options.types)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getSources = function (options, callback) {
|
exports.getSources = function (options, callback) {
|
||||||
var captureScreen, captureWindow, id
|
if (!isValid(options)) return callback(new Error('Invalid options'))
|
||||||
if (!isValid(options)) {
|
const captureWindow = includes.call(options.types, 'window')
|
||||||
return callback(new Error('Invalid options'))
|
const captureScreen = includes.call(options.types, 'screen')
|
||||||
}
|
|
||||||
captureWindow = includes.call(options.types, 'window')
|
|
||||||
captureScreen = includes.call(options.types, 'screen')
|
|
||||||
if (options.thumbnailSize == null) {
|
if (options.thumbnailSize == null) {
|
||||||
options.thumbnailSize = {
|
options.thumbnailSize = {
|
||||||
width: 150,
|
width: 150,
|
||||||
height: 150
|
height: 150
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id = getNextId()
|
|
||||||
|
const id = incrementId()
|
||||||
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, id)
|
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) {
|
return ipcRenderer.once(`ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_${id}`, (event, sources) => {
|
||||||
var source
|
callback(null, (() => {
|
||||||
callback(null, (function () {
|
|
||||||
var i, len, results
|
|
||||||
results = []
|
results = []
|
||||||
for (i = 0, len = sources.length; i < len; i++) {
|
sources.forEach(source => {
|
||||||
source = sources[i]
|
|
||||||
results.push({
|
results.push({
|
||||||
id: source.id,
|
id: source.id,
|
||||||
name: source.name,
|
name: source.name,
|
||||||
thumbnail: nativeImage.createFromDataURL(source.thumbnail)
|
thumbnail: nativeImage.createFromDataURL(source.thumbnail)
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
return results
|
return results
|
||||||
})())
|
})())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue