-
Notifications
You must be signed in to change notification settings - Fork 166
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
Avoid multiple calls to getUserMedia for getLocalDevices #311
Conversation
🦋 Changeset detectedLatest commit: de4ec44 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
I wonder if there's an alternative way to trigger the permission dialog without impacting normal devices.
Is it worth trying this approach:
- in getDevices, calling navigator.mediaDevices.getUserMedia() but with constraints that wouldn't match any device.. for example, deviceId: "dummy".
Thinking out loud, the problem only exists if we acquire the same device twice, so if we could make it so that the getUserMedia attempt in discovery grants permissions, but fails to acquire an actual device.
@@ -30,7 +31,15 @@ export async function createLocalTracks( | |||
|
|||
const opts = mergeDefaultOptions(options, audioDefaults, videoDefaults); | |||
const constraints = constraintsForOptions(opts); | |||
const stream = await navigator.mediaDevices.getUserMedia(constraints); |
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 seems like it'd be problematic when we require different constraints? It seems that each attempt could be different.
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.
ok, I totally misread the code.. it wasn't re-using it, but just caching the previous one.. clever!
this should work as well.
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.
though I think there are still some edge cases as it relates to audio/video types.
nice idea! will test that approach with a dummy deviceId. |
@davidzhao your suggestion works like a charm also on iOS. It's a great workaround! edit: ah. celebrated too early. behaviour is different for firefox. On firefox the permissions do not get granted or rather the user doesn't even get prompted for permissions if there is a
This seems to be in accordance with how the spec defines the steps: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia
The We could:
As the spec says Firefox's behaviour is the "correct" one, I'd opt for only making the Safari case an exception. What do you think? |
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.
nice!!
This reverts commit ca400b0.
This reverts commit 93b5100.
This reverts commit 6d85cdf.
This reverts commit 1574275.
* fix sourcemaps in sample * make overrides explicit or remove
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…#350) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…#353) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@davidzhao the map approach seems to work across browsers as long as the safari case is handled separately. tested across firefox/chrome/safari and iOS safari |
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.
awesome work!
fixes iOS safari video preview disappearing.
Alternative fix on the SDK level to livekit/livekit-react#60.
With this fix, we don't have to change anything in the react packages.