Merge pull request #9481 from djpereira/master

Update desktopCapturer documentation
This commit is contained in:
Kevin Sawicki 2017-05-15 12:23:29 -07:00 committed by GitHub
commit 35a39944bd

View file

@ -1,7 +1,7 @@
# desktopCapturer # desktopCapturer
> Access information about media sources that can be used to capture audio and > Access information about media sources that can be used to capture audio and
> video from the desktop using the [`navigator.webkitGetUserMedia`] API. > video from the desktop using the [`navigator.mediaDevices.getUserMedia`] API.
Process: [Renderer](../glossary.md#renderer-process) Process: [Renderer](../glossary.md#renderer-process)
@ -16,7 +16,7 @@ desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
if (error) throw error if (error) throw error
for (let i = 0; i < sources.length; ++i) { for (let i = 0; i < sources.length; ++i) {
if (sources[i].name === 'Electron') { if (sources[i].name === 'Electron') {
navigator.webkitGetUserMedia({ navigator.mediaDevices.getUserMedia({
audio: false, audio: false,
video: { video: {
mandatory: { mandatory: {
@ -44,12 +44,27 @@ function handleError (e) {
``` ```
To capture video from a source provided by `desktopCapturer` the constraints To capture video from a source provided by `desktopCapturer` the constraints
passed to [`navigator.webkitGetUserMedia`] must include passed to [`navigator.mediaDevices.getUserMedia`] must include
`chromeMediaSource: 'desktop'`, and `audio: false`. `chromeMediaSource: 'desktop'`, and `audio: false`.
To capture both audio and video from the entire desktop the constraints passed To capture both audio and video from the entire desktop the constraints passed
to [`navigator.webkitGetUserMedia`] must include `chromeMediaSource: 'screen'`, to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'desktop'`,
and `audio: true`, but should not include a `chromeMediaSourceId` constraint. for both `audio` and `video`, but should not include a `chromeMediaSourceId` constraint.
```javascript
const constraints = {
audio: {
mandatory: {
chromeMediaSource: 'desktop'
}
},
video: {
mandatory: {
chromeMediaSource: 'desktop'
}
}
};
```
## Methods ## Methods
@ -73,4 +88,4 @@ and calls `callback(error, sources)` when finished.
objects, each `DesktopCapturerSource` represents a screen or an individual window that can be objects, each `DesktopCapturerSource` represents a screen or an individual window that can be
captured. captured.
[`navigator.webkitGetUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/Navigator/getUserMedia [`navigator.mediaDevices.getUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/MediaDevices/getUserMedia