-
Notifications
You must be signed in to change notification settings - Fork 15.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add desktopCapturer.getMediaSourceIdForWebContents() to get stream source id from web contents #22701
Conversation
💖 Thanks for opening this pull request! 💖 We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
} | ||
} | ||
|
||
VLOG(0) << "DEVICES " << devices.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed that whole file change, it was actually an experiment to use getDisplayMedia
and should not have been committed.
cc @electron/wg-api |
docs/api/desktop-capturer.md
Outdated
@@ -94,6 +138,13 @@ Returns `Promise<DesktopCapturerSource[]>` - Resolves with an array of [`Desktop | |||
**Note** Capturing the screen contents requires user consent on macOS 10.15 Catalina or higher, | |||
which can detected by [`systemPreferences.getMediaAccessStatus`]. | |||
|
|||
### `desktopCapturer.getWebContentsStream(options)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe getWebContentsStreamInfo
? It's not really a stream yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right
At some point I was considering returning a DesktopCapturerSource
, but:
- the description of
DesktopCapturerSource.id
would not match this case (not "screen:XX" format, that's the "mediaId") - don't know if it should return the "mediaId" in the
display_id
field or not, since that's different format name
,thumbnail
,appIcon
are not provided- At this point, the returned
id
is expected to be used, otherwise it will leak insideDesktopStreamsRegistry
. This behavior is not similar to screen/application sources.
I don't know if getWebContentsSource
would be a good name or more confusing.
fc60001
to
b70cf58
Compare
@Volune what do you think about moving this to be on WebContents? I think |
@MarshallOfSound just wondering if this is close to getting approved/merged? I'd love to be able to try of this feature. It would be great to know If this is just around the corner as I could abort my n00bish attempt to build electron from this branch :-) Apologies if this question sounds demanding/entitled, or is not in keeping with electron community expectations/conventions. Thanks everyone for your efforts with this great framework! |
@loc The issue I have with that is I need to know the requesting WebContents in order to call (I feel like I already replied that, I guess I forgot to submit my response
The API is not stabilized, so probably not. I will try to update the PR (rebase on top of master) during next week. |
I am in need for this feature hope it will 🙏 done soon 😊 |
Sorry for dropping the ball on this @Volune. I spent some time today thinking about how we could make this better, but couldn't come up with anything that didn't involve significant patching. In the future, I'll try to find an opportunity to improve Chrome's deference to embedders on the issue of screen capture. One last minor suggestion. I've gone back and forth, but I think I'd prefer to change the signature from:
to
The name is more clear about what it's returning and, though it's reasonable to want to use options objects here to make this more extensible, I think that is pretty unlikely and comes at the cost of a stranger API. Also, since the mediaId is not useful to the consumer, we can safely get rid of it. Also, we should add a note in the docs that this media source ID is only valid for 10 seconds after it's called. WDYT? |
…eam source id from web contents
b70cf58
to
b9cfaba
Compare
@loc ok for me I rebased on top of master, and made the API changes. Tests passed on my Windows, and a small demo app worked too. |
@@ -0,0 +1,6 @@ | |||
# WebContentsStreamResult Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of this object now.
docs/api/desktop-capturer.md
Outdated
* `webContentsId` number - Id of the WebContents to get stream of | ||
|
||
Returns `Promise<string>` - Resolves with the identifier of a WebContents stream, this identifier can be | ||
used with [`navigator.mediaDevices.getUserMedia`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this extra indent be removed?
lib/renderer/api/desktop-capturer.ts
Outdated
@@ -37,3 +37,7 @@ export async function getSources (options: Electron.SourcesOptions) { | |||
|
|||
return deserialize(sources); | |||
} | |||
|
|||
export function getMediaSourceIdForWebContents (webContentsId: number) { | |||
return ipcRendererInternal.invoke<Electron.WebContentsStreamResult>('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_MEDIA_SOURCE_ID_FOR_WEB_CONTENTS', webContentsId, getCurrentStack()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ipcRendererInternal.invoke<Electron.WebContentsStreamResult>('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_MEDIA_SOURCE_ID_FOR_WEB_CONTENTS', webContentsId, getCurrentStack()); | |
return ipcRendererInternal.invoke<string>('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_MEDIA_SOURCE_ID_FOR_WEB_CONTENTS', webContentsId, getCurrentStack()); |
|
@Volune the failing mac tests were flakes that disappeared on a re-run. In regards to the release notes, I updated your PR description to have a release note that matches the feature. The |
Congrats on merging your first pull request! 🎉🎉🎉 |
Release Notes Persisted
|
Hello, @Volune. I have a question about this feature. Is it possible to add alpha channel (transparency) when capturing tab? It will be very useful for third party widgets (ex. stickers) |
Description of Change
New feature: add
desktopCapturer.getWebContentsStream()
to provide a way to get a MediaStream from a WebContents usinggetUserMedia
.An example code is provided in
docs/api/desktop-capturer.md
This should be enough to resolve #4776
Checklist
npm test
passesRelease Notes
Notes: Added desktopCapturer.getMediaSourceIdForWebContents(), can be used with getUserMedia to get a stream for a WebContent.
Comments
Feedbacks on the API (especially on functions and arguments naming) are welcomed
These two tests failed locally. Since they don't seem related with the code changes, I assume it's caused by the test environment.