Repository navigation
fix(publish): size controls from rendered preview content #7247
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
Changes from all commits
3c70949
f2b22f4
a5dd516
16301bb
4ddbf25
966746f
fe6a669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,6 +51,14 @@ test("the publish controls start idle and drive source, mute, and visibility", a | |||||||||||
| const source = (name: string) => | ||||||||||||
| page.getByRole("tabpanel", { name: "Source" }).getByRole("button", { name, exact: true }); | ||||||||||||
| await source("Camera").click(); | ||||||||||||
| // Wait for real capture so the clicks below cannot race the live layout change. | ||||||||||||
| await page.waitForFunction(() => { | ||||||||||||
| const publish = document.querySelector<MoqPublish>("moq-publish"); | ||||||||||||
| return !!publish?.sources.video.peek()?.out.source.peek(); | ||||||||||||
| }); | ||||||||||||
| expect(await page.locator("moq-publish video, moq-publish canvas").count()).toBe(0); | ||||||||||||
| const player = await page.locator("moq-publish-ui .player").boundingBox(); | ||||||||||||
| expect(player?.height).toBeGreaterThan(0); | ||||||||||||
| expect(await state(page)).toEqual({ source: "camera", muted: false, invisible: false }); | ||||||||||||
| expect(await page.locator("moq-publish").getAttribute("source")).toBe("camera"); | ||||||||||||
|
|
||||||||||||
|
|
@@ -78,6 +86,93 @@ test("the publish controls start idle and drive source, mute, and visibility", a | |||||||||||
| } | ||||||||||||
| }, 30_000); | ||||||||||||
|
|
||||||||||||
| test.each(["video", "canvas"] as const)( | ||||||||||||
| "publish controls follow a %s preview's rendered size", | ||||||||||||
| async (tag) => { | ||||||||||||
| const server = await createServer({ | ||||||||||||
| configFile: false, | ||||||||||||
| root: `${import.meta.dir}/publish-ui`, | ||||||||||||
| plugins: [worklet()], | ||||||||||||
| server: { host: "127.0.0.1", port: 0 }, | ||||||||||||
| }); | ||||||||||||
| await server.listen(); | ||||||||||||
| const browser = await launch(["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"]); | ||||||||||||
| try { | ||||||||||||
| const page = await browser.newPage({ viewport: { width: 960, height: 720 } }); | ||||||||||||
| await page.goto(server.resolvedUrls?.local[0] ?? ""); | ||||||||||||
| await page.getByRole("button", { name: "Settings", exact: true }).click(); | ||||||||||||
| await page | ||||||||||||
| .getByRole("tabpanel", { name: "Source" }) | ||||||||||||
| .getByRole("button", { name: "Camera", exact: true }) | ||||||||||||
| .click(); | ||||||||||||
| await page.waitForFunction(() => { | ||||||||||||
| const publish = document.querySelector<MoqPublish>("moq-publish"); | ||||||||||||
| return !!publish?.sources.video.peek()?.out.source.peek(); | ||||||||||||
| }); | ||||||||||||
| await page.evaluate((tag) => { | ||||||||||||
| const publish = document.querySelector<MoqPublish>("moq-publish"); | ||||||||||||
| if (!publish) throw new Error("missing publish element"); | ||||||||||||
| publish.backend = "2d"; | ||||||||||||
| const preview = document.createElement(tag); | ||||||||||||
| preview.style.width = "100%"; | ||||||||||||
| preview.style.height = "auto"; | ||||||||||||
|
Comment on lines
+117
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force a non-16:9 preview here. Chromium's fake device serves 1280x720 (verified), so the preview renders at the same 16:9 the empty state already reserves, and every
Suggested change
|
||||||||||||
| if (preview instanceof HTMLVideoElement) { | ||||||||||||
| preview.autoplay = true; | ||||||||||||
| preview.muted = true; | ||||||||||||
| } | ||||||||||||
| publish.append(preview); | ||||||||||||
| }, tag); | ||||||||||||
| // Both preview types must size the box before we hide and remove them. | ||||||||||||
| await page.waitForFunction((tag) => { | ||||||||||||
| const publish = document.querySelector<MoqPublish>("moq-publish"); | ||||||||||||
| const preview = publish?.querySelector(tag); | ||||||||||||
| const player = publish?.parentElement?.shadowRoot?.querySelector(".player"); | ||||||||||||
| const display = publish?.video.in.capture.peek()?.out.display.peek(); | ||||||||||||
| return ( | ||||||||||||
| preview && | ||||||||||||
| player && | ||||||||||||
| (preview instanceof HTMLVideoElement | ||||||||||||
| ? preview.videoWidth > 0 | ||||||||||||
| : display && preview.width === display.width && preview.height === display.height) && | ||||||||||||
| Math.abs(player.getBoundingClientRect().height - preview.getBoundingClientRect().height) < 0.5 | ||||||||||||
| ); | ||||||||||||
| }, tag); | ||||||||||||
| const player = page.locator("moq-publish-ui .player"); | ||||||||||||
| const visible = await player.boundingBox(); | ||||||||||||
| expect(visible?.height).toBeGreaterThan(0); | ||||||||||||
| const empty = (expected: boolean) => | ||||||||||||
| page.waitForFunction( | ||||||||||||
| (expected) => | ||||||||||||
| !!document.querySelector("moq-publish-ui")?.shadowRoot?.querySelector(".player--empty") === | ||||||||||||
| expected, | ||||||||||||
| expected, | ||||||||||||
| ); | ||||||||||||
| const preview = page.locator(`moq-publish ${tag}`); | ||||||||||||
| await preview.evaluate((preview) => { | ||||||||||||
| (preview as HTMLElement).style.display = "none"; | ||||||||||||
| }); | ||||||||||||
| await empty(true); | ||||||||||||
| expect((await player.boundingBox())?.height).toBeCloseTo(visible?.height ?? 0, 0); | ||||||||||||
| // Removing a visible preview must also fall back to the reserved size. | ||||||||||||
| await preview.evaluate((preview) => { | ||||||||||||
| (preview as HTMLElement).style.display = ""; | ||||||||||||
| }); | ||||||||||||
| await empty(false); | ||||||||||||
| await preview.evaluate((preview) => preview.remove()); | ||||||||||||
| await empty(true); | ||||||||||||
| expect(await page.locator("moq-publish video, moq-publish canvas").count()).toBe(0); | ||||||||||||
| expect((await player.boundingBox())?.height).toBeCloseTo(visible?.height ?? 0, 0); | ||||||||||||
| await page.getByRole("button", { name: "Hide video", exact: true }).click(); | ||||||||||||
| await page.getByRole("button", { name: "Mute microphone", exact: true }).click(); | ||||||||||||
| expect(await state(page)).toEqual({ source: "camera", muted: true, invisible: true }); | ||||||||||||
| } finally { | ||||||||||||
| await browser.close(); | ||||||||||||
| await server.close(); | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
| 30_000, | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| test("a selected camera stays announced while real capture is reopening", async () => { | ||||||||||||
| const server = await createServer({ | ||||||||||||
| configFile: false, | ||||||||||||
|
|
||||||||||||
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.
Script executed:
Repository: moq-dev/moq
Length of output: 16220
Script executed:
Repository: moq-dev/moq
Length of output: 23781
Invalidate the placeholder ratio when capture starts.
An idle canvas can report its default 300×150 size, so
renderedbecomes2. Capture then makessrctruthy before the first frame updates the canvas. The effect commitslastAspect = 2. If the preview is hidden or removed before that update, the player falls back to a 2:1 ratio instead of 16:9 or the last displayed ratio.Only promote a measurement produced after capture has rendered its first frame; do not commit the stale placeholder measurement.