// native-portrait.mjs — portrait video on the Mac app (2026-10-21). The // browser's camera is held upright (portrait-camera.mjs, 720 × 1280); the // app shows its full-window call, live, off screen (CallsInterop's // `stage-open`), and reads back where the real video view put the picture // (`placement`, from VideoPlacementProbe): // // upright, on a 1000 × 640 window's stage: fitted — the whole height of // the window, narrower than it, centred — with a backdrop sampling it // turned on its side (1280 × 720): fills the window, as 0.4.10 did, and // the turn changed its shape once and its placement once // a portrait window (500 × 900) with the landscape picture: fitted again // // Run by TestNativeMacPortraitVideo (make native-browser). import { portraitCamera } from './portrait-camera.mjs'; import { chromium } from 'playwright'; import { spawn } from 'node:child_process'; import { createInterface } from 'node:readline'; const [origin, room, binary] = process.argv.slice(2); const browser = await chromium.launch({ headless: true, args: [ '--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream', '--autoplay-policy=no-user-gesture-required', '--disable-features=WebRtcHideLocalIpsWithMdns', '--mute-audio', ] }); const context = await browser.newContext({ permissions: ['camera', 'microphone'] }); await context.addInitScript(portraitCamera); await context.addCookies([{ name: process.env.CALLS_COOKIE_NAME, value: process.env.CALLS_COOKIE_A, url: origin }]); const page = await context.newPage(); let native; let failed = false; const check = (ok, what) => { console.log((ok ? 'PASS ' : 'FAIL ') + what); if (!ok) failed = true; }; try { await page.goto(`${origin}/m/${room}`); await page.waitForFunction(() => !!window.meet); native = spawn(binary, [], { stdio: ['pipe', 'pipe', 'pipe'] }); native.stdin.write(process.env.CALLS_NATIVE_INPUT + '\n'); let sample = null; let placed = null; let exited = false; native.on('exit', () => { exited = true; }); createInterface({ input: native.stdout }).on('line', (line) => { try { const value = JSON.parse(line); if (value.stats) sample = value; if (value.placements) placed = value; } catch {} }); native.stderr.resume(); const wait = async (predicate, label, seconds = 40) => { const until = Date.now() + seconds * 1000; while (Date.now() < until) { if (exited) throw new Error('native executable exited'); if (await predicate()) return true; await new Promise((r) => setTimeout(r, 250)); } throw new Error(label + ': ' + JSON.stringify({ stats: sample && sample.stats, placed })); }; // The camera's picture on the stage: the one view with a camera's size // that is not the app's own (the app's synthetic camera is 16:9 at most). const ask = async () => { placed = null; native.stdin.write('placement\n'); const until = Date.now() + 5000; while (!placed && Date.now() < until) await new Promise((r) => setTimeout(r, 50)); return placed; }; const stagePicture = (p, bounds) => (p ? p.placements : []).find((v) => !v.screen && Math.abs(v.bounds[0] - bounds[0]) < 2 && Math.abs(v.bounds[1] - bounds[1]) < 2); await wait(() => sample?.peer && sample?.stats.framesDecoded > 15, 'the app decodes the browser’s camera'); console.log('PASS the app is in the call and decoding the browser’s camera'); native.stdin.write('stage-open 1000 640\n'); let picture = null; await wait(async () => { picture = stagePicture(await ask(), [1000, 640]); return picture && picture.video[0] === 720 && picture.video[1] === 1280 && placed.backdrops > 0; }, 'the stage shows the upright picture with a backdrop'); const [x, y, w, h] = picture.frame; check(picture.shape === 'portrait', `the upright camera reads as portrait (${picture.video.join(' × ')})`); check(picture.fitted, 'it is fitted, not cropped to fill the landscape window'); 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)})`); check(Math.abs(w - 360) < 1 && Math.abs(x + w / 2 - 500) < 1, `centred, 9:16 (${w.toFixed(1)} wide at ${x.toFixed(1)})`); check(placed.backdrops > 0, `a backdrop is sampling the picture around it (${placed.backdrops})`); const before = { fit: picture.fitChanges, shape: picture.shapeChanges }; // A phone turned on its side mid-call. await page.evaluate(() => window.__turnCamera(1280, 720)); await wait(async () => { picture = stagePicture(await ask(), [1000, 640]); return picture && picture.video[0] === 1280 && picture.video[1] === 720; }, 'the stage sees the camera turned'); await new Promise((r) => setTimeout(r, 1500)); picture = stagePicture(await ask(), [1000, 640]); check(picture.shape === 'landscape' && !picture.fitted, 'turned on its side, it fills the landscape window as before'); const [, ly, lw, lh] = picture.frame; check(lw >= 1000 - 0.5 && lh >= 640 - 0.5 && ly <= 0.5, `filling: ${lw.toFixed(1)} × ${lh.toFixed(1)} over 1000 × 640`); check(picture.fitChanges - before.fit === 1 && picture.shapeChanges - before.shape === 1, `the turn switched once: placement ${picture.fitChanges - before.fit}, shape ${picture.shapeChanges - before.shape}`); // The mirror case: a landscape picture in a portrait window. native.stdin.write('stage-open 500 900\n'); await wait(async () => { picture = stagePicture(await ask(), [500, 900]); return picture && picture.fitted; }, 'a landscape picture in a portrait window is fitted'); 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)})`); native.stdin.write('leave\n'); await new Promise((r) => setTimeout(r, 1000)); } catch (err) { failed = true; console.log('FAIL ' + err.message); } finally { native?.kill('SIGTERM'); await browser.close(); } if (failed) process.exit(1);