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
mandatory
property missing from MediaTrackConstraints
#27139
Comments
@jameshfisher pretty sure this is just a docs update - you should be able to use the new syntax just fine. What this error is saying (correctly) is that |
Hey, thanks @codebytere - however when I try using these properties using the modern // This works as expected - gets a screen capture
screenCaptureStream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
}
}
});
// But this just gets the default camera stream instead of the screen -
// same behavior as if these params were not present
const screenCaptureStream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
}
});
// Similarly, using `ConstrainDOMStringParameters` long form -
// same behavior, gets the default camera stream instead of the screen
const screenCaptureStream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
chromeMediaSource: { exact: 'desktop' },
chromeMediaSourceId: { exact: source.id },
}
}); So it seems like this API really is stuck in the dark ages of (Edit: above testing is on Electron 11, on macOS 11.) |
@jameshfisher hmm ok i'll check into it and see what i come up with :) |
This comment has been minimized.
This comment has been minimized.
Has there been any resolution that allows using the getUserMedia function with a specific sourceId? I found the following two threads which contain a similar issue: [1] and [2] but no further luck. As far as I can tell, every time I try to use getUserMedia, the only video stream that I can retrieve is one of the entire screen. Is there a still way to retrieve specific windows like mentioned at the start of this thread? |
Any update on this at all? |
Seems relevant to #30702 |
It seems this bug has not been fixed yet. I write my React source code in TypeScript and write a preload script in JavaScript. // preload.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('captureDesktop', function () {
return new Promise((resolve) => {
ipcRenderer.invoke('DESKTOP_CAPTURE').then((source) => {
navigator.mediaDevices
.getUserMedia({
audio: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
},
},
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
},
},
})
.then((stream) => {
console.log(stream);
const video = document.createElement('video');
video.srcObject = stream;
resolve(video);
// If we resolved MediaStream directly, we could only get an empty object.
});
});
});
}); // TypeScript
(window as any).captureDesktop().then((videoDOM: HTMLVideoElement) => {
console.log(videoDOM.srcObject); // MediaStream
}) I guess this is not the best way to implement this feature, but it does work. |
Based on this https://stackoverflow.com/questions/37613981/how-to-use-a-typescript-cast-with-jsx-tsx |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment! |
This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue. |
Hi @codebytere Any update on this issue ? |
Would also like some updates on this as have the same questions as OP, can we get this ticket reopened? |
Any update on this issue ? |
Preflight Checklist
Issue Details
Expected Behavior
TypeScript compiles with no type errors.
Actual Behavior
To Reproduce
In a TypeScript project, use the desktopCapturer API as described in its docs, e.g. just use the example code on that page, or:
Additional Information
It looks like this API is part of Chrome rather than part of Electron, and are parsed somewhere here in
media_constraints_impl.cc
. It also looks like thismandatory
section is part of some old/deprecatedgetUserMedia
API. It would be great if we could usedesktopCapturer
API with the moderngetUserMedia
API - maybe we can, but the docs don't say how.It would also be great to know what other constraints we can pass in this
mandatory
section. For example, can we set the frame rate for desktop capture?The text was updated successfully, but these errors were encountered: