2015-10-04 01:35:00 +00:00
|
|
|
# desktop-capturer
|
|
|
|
|
|
|
|
The `desktop-capturer` is a renderer module used to capture the content of
|
|
|
|
screen and individual app windows.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
// In the renderer process.
|
|
|
|
var desktopCapturer = require('desktop-capturer');
|
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
desktopCapturer.getSources({types: ['window', 'screen']}, function(sources) {
|
|
|
|
for (var i = 0; i < sources.length; ++i) {
|
|
|
|
if (sources[i].name == "Electron") {
|
|
|
|
navigator.webkitGetUserMedia({
|
|
|
|
audio: false,
|
|
|
|
video: {
|
|
|
|
mandatory: {
|
|
|
|
chromeMediaSource: 'desktop',
|
|
|
|
chromeMediaSourceId: sources[i].id,
|
|
|
|
minWidth: 1280,
|
|
|
|
maxWidth: 1280,
|
|
|
|
minHeight: 720,
|
|
|
|
maxHeight: 720
|
|
|
|
}
|
2015-10-04 01:35:00 +00:00
|
|
|
}
|
2015-10-06 06:34:54 +00:00
|
|
|
}, gotStream, getUserMediaError);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-04 01:35:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function gotStream(stream) {
|
|
|
|
document.querySelector('video').src = URL.createObjectURL(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserMediaError(e) {
|
|
|
|
console.log('getUserMediaError');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
## Methods
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
The `desktopCapturer` module has the following methods:
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
### `desktopCapturer.getSources(options, callback)`
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
`options` Object, properties:
|
|
|
|
* `types` Array - An array of String that enums the types of desktop sources.
|
|
|
|
* `screen` String - Screen
|
|
|
|
* `window` String - Individual window
|
|
|
|
* `thumnailSize` Object (optional) - The suggested size that thumbnail should be
|
|
|
|
scaled.
|
|
|
|
* `width` Integer - The width of thumbnail. By default, it is 150px.
|
|
|
|
* `height` Integer - The height of thumbnail. By default, it is 150px.
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
`callback` Function - `function(sources) {}`
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
* `Sources` Array - An array of Source
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
Gets all desktop sources.
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
**Note:** There is no garuantee that the size of `source.thumbnail` is always
|
|
|
|
the same as the `thumnailSize` in `options`. It also depends on the scale of the
|
|
|
|
screen or window.
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
## Source
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
`Source` is an object represents a captured screen or individual window. It has
|
|
|
|
following properties:
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-05 03:32:12 +00:00
|
|
|
* `id` String - The id of the captured window or screen used in
|
2015-10-06 06:34:54 +00:00
|
|
|
`navigator.webkitGetUserMedia`. The format looks like 'window:XX' or
|
|
|
|
'screen:XX' where XX is a random generated number.
|
|
|
|
* `name` String - The descriped name of the capturing screen or window. If the
|
|
|
|
source is a screen, the name will be 'Entire Screen' or 'Screen <index>'; if
|
|
|
|
it is a window, the name will be the window's title.
|
2015-10-05 03:32:12 +00:00
|
|
|
* `thumbnail` [NativeImage](NativeImage.md) - A thumbnail image.
|