oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1// native-portrait.mjs — portrait video on the Mac app (2026-10-21). The
2// browser's camera is held upright (portrait-camera.mjs, 720 × 1280); the
3// app shows its full-window call, live, off screen (CallsInterop's
4// `stage-open`), and reads back where the real video view put the picture
5// (`placement`, from VideoPlacementProbe):
6//
7// upright, on a 1000 × 640 window's stage: fitted — the whole height of
8// the window, narrower than it, centred — with a backdrop sampling it
9// turned on its side (1280 × 720): fills the window, as 0.4.10 did, and
10// the turn changed its shape once and its placement once
11// a portrait window (500 × 900) with the landscape picture: fitted again
12//
13// Run by TestNativeMacPortraitVideo (make native-browser).
14import { portraitCamera } from './portrait-camera.mjs';
15import { chromium } from 'playwright';
16import { spawn } from 'node:child_process';
17import { createInterface } from 'node:readline';
18
19const [origin, room, binary] = process.argv.slice(2);
20const browser = await chromium.launch({ headless: true, args: [
21 '--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream',
22 '--autoplay-policy=no-user-gesture-required', '--disable-features=WebRtcHideLocalIpsWithMdns',
23 '--mute-audio',
24] });
25const context = await browser.newContext({ permissions: ['camera', 'microphone'] });
26await context.addInitScript(portraitCamera);
27await context.addCookies([{ name: process.env.CALLS_COOKIE_NAME, value: process.env.CALLS_COOKIE_A, url: origin }]);
28const page = await context.newPage();
29let native;
30let failed = false;
31const check = (ok, what) => {
32 console.log((ok ? 'PASS ' : 'FAIL ') + what);
33 if (!ok) failed = true;
34};
35try {
36 await page.goto(`${origin}/m/${room}`);
37 await page.waitForFunction(() => !!window.meet);
38 native = spawn(binary, [], { stdio: ['pipe', 'pipe', 'pipe'] });
39 native.stdin.write(process.env.CALLS_NATIVE_INPUT + '\n');
40 let sample = null;
41 let placed = null;
42 let exited = false;
43 native.on('exit', () => { exited = true; });
44 createInterface({ input: native.stdout }).on('line', (line) => {
45 try {
46 const value = JSON.parse(line);
47 if (value.stats) sample = value;
48 if (value.placements) placed = value;
49 } catch {}
50 });
51 native.stderr.resume();
52 const wait = async (predicate, label, seconds = 40) => {
53 const until = Date.now() + seconds * 1000;
54 while (Date.now() < until) {
55 if (exited) throw new Error('native executable exited');
56 if (await predicate()) return true;
57 await new Promise((r) => setTimeout(r, 250));
58 }
59 throw new Error(label + ': ' + JSON.stringify({ stats: sample && sample.stats, placed }));
60 };
61 // The camera's picture on the stage: the one view with a camera's size
62 // that is not the app's own (the app's synthetic camera is 16:9 at most).
63 const ask = async () => {
64 placed = null;
65 native.stdin.write('placement\n');
66 const until = Date.now() + 5000;
67 while (!placed && Date.now() < until) await new Promise((r) => setTimeout(r, 50));
68 return placed;
69 };
70 const stagePicture = (p, bounds) => (p ? p.placements : []).find((v) =>
71 !v.screen && Math.abs(v.bounds[0] - bounds[0]) < 2 && Math.abs(v.bounds[1] - bounds[1]) < 2);
72
73 await wait(() => sample?.peer && sample?.stats.framesDecoded > 15, 'the app decodes the browser’s camera');
74 console.log('PASS the app is in the call and decoding the browser’s camera');
75 native.stdin.write('stage-open 1000 640\n');
76 let picture = null;
77 await wait(async () => {
78 picture = stagePicture(await ask(), [1000, 640]);
79 return picture && picture.video[0] === 720 && picture.video[1] === 1280 && placed.backdrops > 0;
80 }, 'the stage shows the upright picture with a backdrop');
81 const [x, y, w, h] = picture.frame;
82 check(picture.shape === 'portrait', `the upright camera reads as portrait (${picture.video.join(' × ')})`);
83 check(picture.fitted, 'it is fitted, not cropped to fill the landscape window');
84 check(Math.abs(h - 640) < 1 && Math.abs(y) < 1, `the whole frame is shown: its full height in the window (${h.toFixed(1)} of 640, from ${y.toFixed(1)})`);
85 check(Math.abs(w - 360) < 1 && Math.abs(x + w / 2 - 500) < 1, `centred, 9:16 (${w.toFixed(1)} wide at ${x.toFixed(1)})`);
86 check(placed.backdrops > 0, `a backdrop is sampling the picture around it (${placed.backdrops})`);
87 const before = { fit: picture.fitChanges, shape: picture.shapeChanges };
88
89 // A phone turned on its side mid-call.
90 await page.evaluate(() => window.__turnCamera(1280, 720));
91 await wait(async () => {
92 picture = stagePicture(await ask(), [1000, 640]);
93 return picture && picture.video[0] === 1280 && picture.video[1] === 720;
94 }, 'the stage sees the camera turned');
95 await new Promise((r) => setTimeout(r, 1500));
96 picture = stagePicture(await ask(), [1000, 640]);
97 check(picture.shape === 'landscape' && !picture.fitted, 'turned on its side, it fills the landscape window as before');
98 const [, ly, lw, lh] = picture.frame;
99 check(lw >= 1000 - 0.5 && lh >= 640 - 0.5 && ly <= 0.5, `filling: ${lw.toFixed(1)} × ${lh.toFixed(1)} over 1000 × 640`);
100 check(picture.fitChanges - before.fit === 1 && picture.shapeChanges - before.shape === 1,
101 `the turn switched once: placement ${picture.fitChanges - before.fit}, shape ${picture.shapeChanges - before.shape}`);
102
103 // The mirror case: a landscape picture in a portrait window.
104 native.stdin.write('stage-open 500 900\n');
105 await wait(async () => {
106 picture = stagePicture(await ask(), [500, 900]);
107 return picture && picture.fitted;
108 }, 'a landscape picture in a portrait window is fitted');
109 check(Math.abs(picture.frame[2] - 500) < 1, `a landscape camera in an upright window is fitted across it (${picture.frame[2].toFixed(1)} × ${picture.frame[3].toFixed(1)})`);
110 native.stdin.write('leave\n');
111 await new Promise((r) => setTimeout(r, 1000));
112} catch (err) {
113 failed = true;
114 console.log('FAIL ' + err.message);
115} finally {
116 native?.kill('SIGTERM');
117 await browser.close();
118}
119if (failed) process.exit(1);
120