Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 113 additions & 14 deletions suite/meet/e2e/fixtures/media.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Fake camera/display media for Playwright.
*
* On GitHub Actions (headless Linux Chrome), off-DOM canvases driven only by
* requestAnimationFrame often produce a live MediaStreamTrack with zero encoded
* frames. Remote video then stays at readyState 0 forever while local preview
* may still look "dark navy" from a single paint.
*
* Use setInterval + CanvasCaptureMediaStreamTrack.requestFrame() so frames keep
* flowing under timer throttling. Create a fresh stream per getUserMedia /
* getDisplayMedia call so stopping one clone does not end tracks for others.
*/
export const STUB_MEDIA_SCRIPT = `(() => {
window.localStorage.setItem("mediaPref.autoHideToolbar", "0");

Expand All @@ -10,28 +22,76 @@ export const STUB_MEDIA_SCRIPT = `(() => {

function createFakeStream(label) {
const canvas = document.createElement("canvas");
canvas.width = 1280;
canvas.height = 720;
const context = canvas.getContext("2d");
canvas.width = 640;
canvas.height = 360;
// Keep the canvas in the document so some Chromium builds keep capturing.
canvas.style.cssText =
"position:fixed;left:-9999px;top:0;width:1px;height:1px;opacity:0;pointer-events:none;";
document.documentElement.appendChild(canvas);

const context = canvas.getContext("2d", { alpha: false, desynchronized: true });
let tick = 0;

const draw = () => {
if (!context) {
return;
}
context.fillStyle = "#111827";
// Distinct, high-contrast frame so decoders always get a real keyframe-ish delta.
const hue = (tick * 17) % 360;
context.fillStyle = "hsl(" + hue + " 70% 40%)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#f9fafb";
context.font = "32px sans-serif";
context.fillText(label, 48, 80);
context.font = "20px monospace";
context.fillText(String(++tick), 48, 128);
requestAnimationFrame(draw);
context.font = "28px sans-serif";
context.fillText(label, 24, 48);
context.font = "18px monospace";
context.fillText(String(++tick), 24, 84);
context.fillRect(24 + (tick % 40) * 8, 120, 40, 40);
};

// Initial paint before capture so the first frame is never empty.
draw();

const stream = canvas.captureStream(12);
// Prefer manual frames via requestFrame (best under headless throttling).
// Fall back to a fixed capture rate when requestFrame is unavailable.
const probeStream = canvas.captureStream(0);
const probeTrack = probeStream.getVideoTracks()[0];
const canRequestFrame =
probeTrack && typeof probeTrack.requestFrame === "function";

let stream;
let videoTrack;
if (canRequestFrame) {
stream = probeStream;
videoTrack = probeTrack;
} else {
for (const track of probeStream.getTracks()) {
track.stop();
}
stream = canvas.captureStream(15);
videoTrack = stream.getVideoTracks()[0];
}

const pushFrame = () => {
draw();
if (videoTrack && typeof videoTrack.requestFrame === "function") {
try {
videoTrack.requestFrame();
} catch {}
}
};

// setInterval is far less throttled than rAF for background/headless tabs.
const intervalId = window.setInterval(pushFrame, 1000 / 15);
pushFrame();

const stopCapture = () => {
window.clearInterval(intervalId);
canvas.remove();
};

for (const track of stream.getVideoTracks()) {
track.addEventListener("ended", stopCapture, { once: true });
}

try {
const AudioContextCtor = window.AudioContext || window.webkitAudioContext;
Expand All @@ -41,21 +101,60 @@ export const STUB_MEDIA_SCRIPT = `(() => {
const gainNode = audioContext.createGain();
const destination = audioContext.createMediaStreamDestination();
gainNode.gain.value = 0.001;
oscillator.frequency.value = 440;
oscillator.connect(gainNode);
gainNode.connect(destination);
oscillator.start();
for (const track of destination.stream.getAudioTracks()) {
stream.addTrack(track);
track.addEventListener(
"ended",
() => {
try {
oscillator.stop();
audioContext.close();
} catch {}
},
{ once: true },
);
}
}
} catch {}

return stream;
}

const userStream = createFakeStream("camera");
const displayStream = createFakeStream("screen");
navigator.mediaDevices.getUserMedia = async () => createFakeStream("camera");
navigator.mediaDevices.getDisplayMedia = async () => createFakeStream("screen");

navigator.mediaDevices.getUserMedia = async () => userStream.clone();
navigator.mediaDevices.getDisplayMedia = async () => displayStream.clone();
// Enumerate devices so UI paths that wait on device lists do not hang in CI.
navigator.mediaDevices.enumerateDevices = async () => [
{
deviceId: "fake-camera",
groupId: "fake-group",
kind: "videoinput",
label: "Fake Camera",
toJSON() {
return this;
},
},
{
deviceId: "fake-mic",
groupId: "fake-group",
kind: "audioinput",
label: "Fake Microphone",
toJSON() {
return this;
},
},
{
deviceId: "fake-speaker",
groupId: "fake-group",
kind: "audiooutput",
label: "Fake Speaker",
toJSON() {
return this;
},
},
];
})();`;
50 changes: 27 additions & 23 deletions suite/meet/e2e/helpers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ export async function expectRemoteVideoReceiving(
export async function expectVideoReceiving(video: Locator): Promise<void> {
await expect(video).toBeVisible({ timeout: 45_000 });

// Headless CI sometimes attaches a live track but leaves the element paused.
await video.evaluate(async (element) => {
const videoEl = element as HTMLVideoElement;
videoEl.muted = true;
if (videoEl.paused) {
try {
await videoEl.play();
} catch {
// Autoplay may still fail; the poll below is the real assertion.
}
}
});

// Single poll: live track + enough decoded media to prove remote video works.
// readyState >= 2 (HAVE_CURRENT_DATA) is enough; requiring 4 (HAVE_ENOUGH_DATA)
// is flaky under CI load even when frames are clearly rendering.
await expect
.poll(
async () =>
Expand All @@ -23,36 +39,24 @@ export async function expectVideoReceiving(video: Locator): Promise<void> {
const quality = videoEl.getVideoPlaybackQuality?.();
const stream = videoEl.srcObject as MediaStream | null;
const videoTrack = stream?.getVideoTracks()[0] ?? null;
const decodedFrames = quality?.totalVideoFrames ?? 0;
const hasPixels = videoEl.videoWidth > 0 && videoEl.videoHeight > 0;
const hasPlayback =
videoEl.currentTime > 0 || decodedFrames > 0 || hasPixels;
return {
currentTime: videoEl.currentTime,
decodedFrames: quality?.totalVideoFrames ?? 0,
decodedFrames,
hasPlayback,
height: videoEl.videoHeight,
ok:
videoTrack?.readyState === "live" &&
videoEl.readyState >= 2 &&
Comment thread
greptile-apps[bot] marked this conversation as resolved.
hasPlayback,
readyState: videoEl.readyState,
trackState: videoTrack?.readyState ?? null,
width: videoEl.videoWidth,
};
}),
{ timeout: 45_000 },
)
.toMatchObject({
readyState: 4,
trackState: "live",
});

await expect
.poll(
async () =>
video.evaluate((element) => {
const videoEl = element as HTMLVideoElement;
const quality = videoEl.getVideoPlaybackQuality?.();
return (
videoEl.currentTime > 0 &&
(quality?.totalVideoFrames ?? 0) > 0 &&
videoEl.videoWidth > 0 &&
videoEl.videoHeight > 0
);
}),
{ timeout: 45_000 },
)
.toBe(true);
.toMatchObject({ ok: true, trackState: "live" });
}
11 changes: 8 additions & 3 deletions suite/meet/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: 1,
maxFailures: process.env.CI ? 3 : undefined,
timeout: 60_000,
maxFailures: process.env.CI ? 3 : undefined,
// Media/WebRTC join + decode polls need headroom on GitHub runners.
timeout: process.env.CI ? 90_000 : 60_000,
expect: {
timeout: 10_000,
},
Expand All @@ -28,7 +29,7 @@ export default defineConfig({
screenshot: "only-on-failure",
viewport: { width: 1440, height: 900 },
actionTimeout: 15_000,
navigationTimeout: 30_000,
navigationTimeout: 30_000,
},
projects: [
{
Expand All @@ -39,6 +40,10 @@ export default defineConfig({
launchOptions: {
args: [
"--use-fake-ui-for-media-stream",
// Keep timers/rAF alive across multi-page WebRTC tests in CI.
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-renderer-backgrounding",
"--disable-audio-track-processing",
"--disable-webrtc-apm-in-audio-service",
"--allow-insecure-localhost",
Expand Down
Loading