Wait for first video frame to be received before responding to waitForDimension - #2100
Conversation
🦋 Changeset detectedLatest commit: c05a42a 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 |
|
(cc @davidzhao , tagging you since you originally reviewed #898 and might have some context on why this change was made given lukas is out this week) |
size-limit report 📦
|
| if (getBrowser()?.os === 'iOS') { | ||
| // browsers report wrong initial resolution on iOS. | ||
| // when slightly delaying the call to .getSettings(), the correct resolution is being reported | ||
| await sleep(10); |
There was a problem hiding this comment.
thank you for fixing this hack
…te < 2 Otherwise the loadeddata event may not fire properly
|
Thanks for the fast turnaround, and for tracing the 10ms back to #898. Read the diff against the measurements in the issue and it matches. I then ran three checks on the iPhone 15, iOS 26.6, in normal power and in Low Power Mode, so these are answers rather than questions.
On why 10ms never worked: it was a guess at this window, and the window is about 145ms here and about 400ms on your iPhone 11, so it only passed when the read happened to land late. One thing I could not test, no iPad here. |
Overview
Fixes #2099
For background context, an ios specific delay was added to the
LocalTrack.waitForDimensionsmethod in #898 seemingly to work around some sort of platform specific issue. It's unclear exactly why this was added or why 10ms was chosen, however.In the linked #2099 issue, the reporter mentions that this previously added 10ms delay isn't always long enough on ios - they report that for the first few hundred milliseconds, the dimensions of the front camera come back in landscape orientation even when the phone is in portrait. I like the reporter's suggested fix - instead of waiting for a fixed 10ms duration, wait for the first frame to be received on the video stream and THEN report back the dimensions of the video track. I took a crack at implementing this suggested fix here.
The biggest con to the reporter's approach is that this
waitForDimensionsmethod can now take longer - on a older iPhone 11 I had handy to test with, it took ~400ms. However, this seems to me like the right tradeoff given the result of the current version onmainwas just flat out incorrect.Test plan
I had a LLM put together a small app that would let me test both sides of this - the old
waitForDimensionsimplementation, and the new function implementation side by side.What this test app was doing
Below is a screenshot of my results on an iPhone 11 - each is after a fresh page reload: