feat: add desktopCapturer.getMediaSourceIdForWebContents() to get stream source id from web contents (#22701)

* feat: add desktopCapturer.getMediaSourceIdForWebContents() to get stream source id from web contents

* Cleanup from #22701 PR comments
This commit is contained in:
Jeremy Judeaux 2020-05-27 04:34:24 +08:00 committed by GitHub
parent dc72f74020
commit 204f001c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 178 additions and 2 deletions

View file

@ -130,6 +130,27 @@ desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => {
}
})
desktopCapturer.getMediaSourceIdForWebContents(remote.getCurrentWebContents().id).then(mediaSourceId => {
(navigator as any).webkitGetUserMedia({
audio: {
mandatory: {
chromeMediaSource: 'tab',
chromeMediaSourceId: mediaSourceId
}
},
video: {
mandatory: {
chromeMediaSource: 'tab',
chromeMediaSourceId: mediaSourceId,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}, gotStream, getUserMediaError)
})
function gotStream (stream: any) {
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream)
}