mirror of
https://github.com/vector-im/element-call.git
synced 2026-11-22 09:41:09 +08:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2f7fccc6e | ||
|
|
f9dafcd5ea | ||
|
|
ded4471525 | ||
|
|
3917bbb8f2 | ||
|
|
95a646b3bc |
@@ -19,10 +19,10 @@ services:
|
||||
- ./backend/playwright_homeserver-othersite.yaml:/data/cfg/homeserver.yaml:Z
|
||||
element-web:
|
||||
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:dd8dbe372d8b7d244cd652347e802cd4732aa78b97d3dee57c9b1a666e605337
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:2f9e5d993e20adbd062453fd1c437821d554bac1f22ed3177290b7911f667848
|
||||
element-web-1:
|
||||
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:dd8dbe372d8b7d244cd652347e802cd4732aa78b97d3dee57c9b1a666e605337
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:2f9e5d993e20adbd062453fd1c437821d554bac1f22ed3177290b7911f667848
|
||||
volumes:
|
||||
# The other site opens the embedded package under test in place of the
|
||||
# copy its image bundles (the first site opens the dev server's app.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
import { SpaHelpers } from "./spa-helpers.ts";
|
||||
|
||||
test("The full screen button can be clicked while the footer overlays the video", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/");
|
||||
await SpaHelpers.createCall(page, "John Doe", "ShortWindow", true);
|
||||
await SpaHelpers.expectVideoTilesCount(page, 1);
|
||||
|
||||
const fullScreenButton = page.getByRole("button", { name: "maximise" });
|
||||
const footer = page.getByTestId("footer-container");
|
||||
|
||||
// Short enough for the footer to be drawn over the video
|
||||
await page.setViewportSize({ width: 1000, height: 500 });
|
||||
await expect(fullScreenButton).toBeVisible();
|
||||
await page.getByTestId("videoTile").first().hover();
|
||||
await expect(footer).toHaveCSS("opacity", "1");
|
||||
|
||||
const buttonBox = (await fullScreenButton.boundingBox())!;
|
||||
const footerBox = (await footer.boundingBox())!;
|
||||
expect(buttonBox.y + buttonBox.height).toBeLessThanOrEqual(footerBox.y);
|
||||
|
||||
await fullScreenButton.click();
|
||||
await expect
|
||||
.poll(async () => page.evaluate(() => document.fullscreenElement !== null))
|
||||
.toBe(true);
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
import { widgetTest } from "../fixtures/widget-user.ts";
|
||||
import { TestHelpers } from "./test-helpers.ts";
|
||||
|
||||
widgetTest.use({ callType: "dm" });
|
||||
|
||||
// The bug from issue #4403, in a real call between two users in Element Web.
|
||||
// 1. Brooks' browser is made slow: it lists its camera and microphone only
|
||||
// after the call is on screen.
|
||||
// 2. Brooks starts a video call in a DM. A DM call has no lobby.
|
||||
// 3. Whistler picks up.
|
||||
// 4. Brooks' camera button shows "on".
|
||||
// 5. Whistler must see two videos: their own and the one brooks sends.
|
||||
// Before the fix whistler saw only their own video.
|
||||
//
|
||||
// What it guards: the unit tests only check the mute button's own logic. This
|
||||
// test checks the whole chain: button, call, SFU, and what the other person
|
||||
// really sees. The bug depends on timing (camera listed before or after the
|
||||
// call opens), so the normal DM call tests pass by luck most of the time.
|
||||
// This test forces the bad timing every run, so a regression shows up always
|
||||
// and not only sometimes.
|
||||
widgetTest(
|
||||
"Publishes a camera the browser lists only once the call is on screen",
|
||||
async ({ asWidget, browserName }) => {
|
||||
test.skip(
|
||||
browserName === "firefox",
|
||||
"The is test is not working on firefox CI environment. No mic/audio device inputs so cam/mic are disabled",
|
||||
);
|
||||
|
||||
// Two Element Webs and a real call.
|
||||
test.slow();
|
||||
const { brooks, whistler } = asWidget;
|
||||
await listDevicesOnlyInTheCall(brooks.page);
|
||||
|
||||
await TestHelpers.startCallInCurrentRoom(brooks.page, false);
|
||||
await expect(whistler.page.getByText("Incoming video call")).toBeVisible();
|
||||
await whistler.page
|
||||
.getByRole("alert")
|
||||
.getByRole("button", { name: "Join" })
|
||||
.click();
|
||||
|
||||
const brooksFrame = brooks.page
|
||||
.locator('iframe[title="Element Call"]')
|
||||
.contentFrame();
|
||||
await expect(
|
||||
brooksFrame.getByRole("switch", { name: "Stop video", checked: true }),
|
||||
).toBeVisible();
|
||||
|
||||
// Whistler's own camera and the one brooks sends
|
||||
const whistlerFrame = whistler.page
|
||||
.locator('iframe[title="Element Call"]')
|
||||
.contentFrame();
|
||||
await TestHelpers.expectVisibleVideoCount(whistlerFrame, 2);
|
||||
await expect(whistlerFrame.getByText("Waiting for media...")).toHaveCount(
|
||||
0,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Holds the device list back in the widget until the call view shows a tile,
|
||||
* as a browser that is slow to answer does. Call before the widget loads.
|
||||
*
|
||||
* How: it replaces the browser's `enumerateDevices` with one that waits. It
|
||||
* checks every 50ms whether a video tile is on the page, waits half a second
|
||||
* more, and only then gives the real list. Element Web itself (the outer
|
||||
* page) is left alone; only the call inside the iframe is slowed down.
|
||||
*/
|
||||
async function listDevicesOnlyInTheCall(page: Page): Promise<void> {
|
||||
await page.addInitScript(() => {
|
||||
if (window.parent === window) return;
|
||||
const devices = navigator.mediaDevices;
|
||||
const enumerate = devices.enumerateDevices.bind(devices);
|
||||
const inTheCall = new Promise<void>((resolve) => {
|
||||
const poll = setInterval(() => {
|
||||
if (document.querySelector("[data-testid='videoTile']") === null)
|
||||
return;
|
||||
clearInterval(poll);
|
||||
setTimeout(resolve, 500);
|
||||
}, 50);
|
||||
});
|
||||
devices.enumerateDevices = async (): Promise<MediaDeviceInfo[]> => {
|
||||
await inTheCall;
|
||||
return enumerate();
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -169,6 +169,111 @@ describe("MuteState", () => {
|
||||
expect(syncingValues).toContain(true);
|
||||
expect(syncingValues.at(-1)).toBe(false);
|
||||
});
|
||||
|
||||
// The bug from issue #4403: we join a call without a lobby, and the browser
|
||||
// tells us about the camera only after the call has started.
|
||||
// 1. Start with no camera, with the camera set to be on by default.
|
||||
// 2. Set a handler, like the call does when it starts.
|
||||
// 3. The camera shows up.
|
||||
// The handler must be called with "on", so the call publishes the camera,
|
||||
// and the button must show "on" only after the handler is done.
|
||||
//
|
||||
// What it guards: the button and the real camera must never disagree. In
|
||||
// the bug the button jumped to "on" by itself and nobody told the call, so
|
||||
// the other side saw "Waiting for media". If someone changes how the
|
||||
// default is applied and forgets the handler again, this test fails.
|
||||
test("asks the handler for the default of a device listed after it was set", async () => {
|
||||
const available$ = new BehaviorSubject(new Map<string, DeviceLabel>());
|
||||
const muteState = new MuteState(
|
||||
testScope,
|
||||
aDevice(available$),
|
||||
true,
|
||||
constant(false),
|
||||
);
|
||||
const handler = vi.fn(async (desired: boolean) => Promise.resolve(desired));
|
||||
muteState.setHandler(handler);
|
||||
expect(muteState.enabled$.value).toBe(false);
|
||||
|
||||
available$.next(aCamera);
|
||||
// On only once the handler has acted on it
|
||||
expect(muteState.enabled$.value).toBe(false);
|
||||
await flushPromises();
|
||||
|
||||
expect(handler).toHaveBeenLastCalledWith(true);
|
||||
expect(muteState.enabled$.value).toBe(true);
|
||||
expect(muteState.syncing$.value).toBe(false);
|
||||
});
|
||||
|
||||
// A camera that is unplugged and plugged back in during a call.
|
||||
// 1. Start with a camera, on by default, and set a handler.
|
||||
// 2. The camera goes away, then comes back.
|
||||
// The handler is told "off" when the camera goes away and is not called
|
||||
// again. The camera stays off: we must not turn on a camera that the user
|
||||
// may have turned off before.
|
||||
//
|
||||
// What it guards: a privacy problem the fix for #4403 could cause. The fix
|
||||
// sends the default "on" to the handler. If it did that every time a
|
||||
// camera shows up, replugging a camera (or leaving earpiece mode) would
|
||||
// start sending video without the user asking. This test fails if the
|
||||
// default is ever applied a second time during a call.
|
||||
test("leaves a device that comes back under a handler off", async () => {
|
||||
const available$ = new BehaviorSubject(aCamera);
|
||||
const muteState = new MuteState(
|
||||
testScope,
|
||||
aDevice(available$),
|
||||
true,
|
||||
constant(false),
|
||||
);
|
||||
expect(muteState.enabled$.value).toBe(true);
|
||||
const handler = vi.fn(async (desired: boolean) => Promise.resolve(desired));
|
||||
muteState.setHandler(handler);
|
||||
|
||||
available$.next(new Map());
|
||||
available$.next(aCamera);
|
||||
await flushPromises();
|
||||
|
||||
expect(handler.mock.calls).toEqual([[false]]);
|
||||
expect(muteState.enabled$.value).toBe(false);
|
||||
});
|
||||
|
||||
// The lobby case, which must keep working as before: no handler is set.
|
||||
// 1. Start with no camera, with the camera set to be on by default.
|
||||
// 2. The camera shows up.
|
||||
// The button shows "on" right away, with no waiting.
|
||||
//
|
||||
// What it guards: the lobby and the join read the button's value at once
|
||||
// to decide which devices to open. If the fix for #4403 made the default
|
||||
// wait for a handler here too, the value would be "off" for a moment and
|
||||
// the lobby would open no camera. This test fails if that happens.
|
||||
test("assumes the default at once where no handler is set", () => {
|
||||
const available$ = new BehaviorSubject(new Map<string, DeviceLabel>());
|
||||
const muteState = new MuteState(
|
||||
testScope,
|
||||
aDevice(available$),
|
||||
true,
|
||||
constant(false),
|
||||
);
|
||||
|
||||
available$.next(aCamera);
|
||||
|
||||
expect(muteState.enabled$.value).toBe(true);
|
||||
});
|
||||
|
||||
// A device list with one camera in it.
|
||||
const aCamera = new Map<string, DeviceLabel>([
|
||||
["fbac11", { type: "name", name: "HD Camera" }],
|
||||
]);
|
||||
|
||||
// A fake camera whose device list the test can change while it runs.
|
||||
function aDevice(
|
||||
available$: BehaviorSubject<Map<string, DeviceLabel>>,
|
||||
): MediaDevice<DeviceLabel, SelectedDevice> {
|
||||
return {
|
||||
available$,
|
||||
selected$: constant({ id: "fbac11" }),
|
||||
select(): void {},
|
||||
} as unknown as MediaDevice<DeviceLabel, SelectedDevice>;
|
||||
}
|
||||
});
|
||||
|
||||
describe("MuteStates", () => {
|
||||
|
||||
+26
-10
@@ -53,6 +53,8 @@ export class MuteState<Label, Selected> {
|
||||
this.handler$.next(defaultHandler);
|
||||
}
|
||||
|
||||
private devicesConnectedBefore = false;
|
||||
|
||||
private readonly canControlDevices$ = combineLatest([
|
||||
this.device.available$,
|
||||
this.forceMute$,
|
||||
@@ -86,15 +88,26 @@ export class MuteState<Label, Selected> {
|
||||
};
|
||||
}
|
||||
|
||||
// Assume the default value only once devices are actually connected
|
||||
let enabled = this.enabledByDefault;
|
||||
// defaultHander = no-op hanlder = "no actual device handler available"
|
||||
const handlerAttached = this.handler$.value !== defaultHandler;
|
||||
const deviceCameBackInCall =
|
||||
handlerAttached && this.devicesConnectedBefore;
|
||||
// Set the flag. A marker, that we reached this code before.
|
||||
this.devicesConnectedBefore = true;
|
||||
const initialWanted = deviceCameBackInCall
|
||||
? false
|
||||
: this.enabledByDefault;
|
||||
// With a handler attached we start off and let the sync below actually call
|
||||
// the handler, so the switch shows "on" only once the track is really there.
|
||||
// Without one (lobby) enabled = initialWanted -> no call to handler.
|
||||
let enabled = handlerAttached ? false : initialWanted;
|
||||
const set$ = new Subject<boolean>();
|
||||
const toggle$ = new Subject<void>();
|
||||
const syncing$ = new BehaviorSubject(false);
|
||||
const desired$ = merge(set$, toggle$.pipe(map(() => !enabled)));
|
||||
const enabled$ = new Observable<boolean>((subscriber) => {
|
||||
subscriber.next(enabled);
|
||||
let latestDesired = this.enabledByDefault;
|
||||
let latestDesired = initialWanted;
|
||||
|
||||
const sync = async (): Promise<void> => {
|
||||
if (enabled === latestDesired) {
|
||||
@@ -120,16 +133,19 @@ export class MuteState<Label, Selected> {
|
||||
}
|
||||
};
|
||||
|
||||
const startSync = (): void => {
|
||||
syncing$.next(true);
|
||||
sync().catch((err) => {
|
||||
// TODO: better error handling
|
||||
logger.error("MuteState: handler error", err);
|
||||
});
|
||||
};
|
||||
|
||||
const s = desired$.subscribe((desired) => {
|
||||
latestDesired = desired;
|
||||
if (syncing$.value === false) {
|
||||
syncing$.next(true);
|
||||
sync().catch((err) => {
|
||||
// TODO: better error handling
|
||||
logger.error("MuteState: handler error", err);
|
||||
});
|
||||
}
|
||||
if (syncing$.value === false) startSync();
|
||||
});
|
||||
if (enabled !== latestDesired) startSync();
|
||||
return (): void => {
|
||||
s.unsubscribe();
|
||||
syncing$.complete();
|
||||
|
||||
@@ -111,7 +111,10 @@ Please see LICENSE in the repository root for full details.
|
||||
display: flex;
|
||||
gap: var(--cpd-space-2x);
|
||||
position: absolute;
|
||||
inset-block-end: var(--cpd-space-1x);
|
||||
/* Ensure that the buttons lie within the safe area */
|
||||
inset-block-end: calc(
|
||||
var(--call-view-safe-area-inset-bottom, 0px) + var(--cpd-space-1x)
|
||||
);
|
||||
inset-inline-end: var(--cpd-space-1x);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user