oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1// native-ice.mjs — spec §15.28 between the Mac app and a browser: a
2// connection that cannot come up for a while (ICETestBlock, the app's
3// every candidate either way pointed at nothing) is mended once the path
4// is back, with nobody pressing anything. Driven by TestNativeMacIceBrowser.
5//
6// node native-ice.mjs <origin> <room> <interop binary> <case>
7//
8// case "both": both sides are this release. "app-old": the app neither
9// mends nor says its version (an app from before §15.28), so the browser
10// mends it alone, and once a minute has passed says the app may be old.
11// "web-old": the browser's recovery is off, so the app mends it alone.
12// The browser's camera is off: its own camera watch (§15.16) resets a pair
13// whose camera stops encoding, which mends a blocked pair by accident and
14// would hide whether the recovery did.
15import { chromium } from 'playwright';
16import { spawn } from 'node:child_process';
17import { createInterface } from 'node:readline';
18
19const [origin, room, binary, kase] = process.argv.slice(2);
20const blockMs = Number(process.env.ICE_BLOCK_MS || 25000);
21const within = Number(process.env.ICE_RECOVER_WITHIN || 90000);
22let failed = false;
23const check = (ok, what) => {
24 console.log((ok ? 'PASS ' : 'FAIL ') + what);
25 if (!ok) failed = true;
26 return ok;
27};
28const browser = await chromium.launch({ headless: true, args: [
29 '--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream',
30 '--autoplay-policy=no-user-gesture-required', '--disable-features=WebRtcHideLocalIpsWithMdns', '--mute-audio',
31] });
32const context = await browser.newContext({ permissions: ['camera', 'microphone'] });
33await context.addCookies([{ name: process.env.CALLS_COOKIE_NAME, value: process.env.CALLS_COOKIE_A, url: origin }]);
34const page = await context.newPage();
35let native;
36try {
37 await page.goto(`${origin}/m/${room}`);
38 await page.waitForFunction(() => !!window.meet);
39 await page.waitForFunction(() => window.meet.state().admitted, null, { timeout: 20000 });
40 await page.click('#camera');
41 if (kase === 'web-old') await page.evaluate(() => window.meet.recoveryForTest(false));
42
43 const env = { ...process.env, CALLS_TEST_ICE_BLOCK_MS: String(blockMs) };
44 if (kase === 'app-old') Object.assign(env, { CALLS_AUTO_RECOVERY: '0', CALLS_TEST_NO_CLIENT: '1' });
45 const blockedAt = Date.now();
46 native = spawn(binary, [], { stdio: ['pipe', 'pipe', 'pipe'], env });
47 native.stdin.write(process.env.CALLS_NATIVE_INPUT + '\n');
48 let sample = null;
49 let exited = false;
50 native.on('exit', () => { exited = true; });
51 // Only the gate's own observations: never library output, which can
52 // carry SDP and candidates.
53 createInterface({ input: native.stdout }).on('line', (line) => {
54 try {
55 const v = JSON.parse(line);
56 if (v.stats) sample = v;
57 } catch { /* not ours */ }
58 });
59 native.stderr.resume();
60 const until = async (pred, ms) => {
61 const end = Date.now() + ms;
62 while (Date.now() < end) {
63 if (exited) return false;
64 const v = await pred();
65 if (v) return v;
66 await new Promise((r) => setTimeout(r, 250));
67 }
68 return false;
69 };
70 const web = (id) => page.evaluate((id) => {
71 const s = window.meet.state();
72 return { connection: Object.fromEntries(s.connection)[id] || '', hearing: s.hearingList.includes(id),
73 recovery: s.recovery[id] || null, autoRestarts: s.autoRestarts, autoRebuilds: s.autoRebuilds,
74 note: s.notes[id] || '', client: s.clients[id], reconnecting: s.reconnect.peers.includes(id),
75 connecting: !!(s.connecting[id] && s.connecting[id].shown) };
76 }, id);
77
78 const inCall = await until(() => sample && sample.phase === 'admitted' && sample.peer ? sample : false, 30000);
79 if (!check(inCall, 'the app is in the call')) throw new Error('no app');
80 const app = inCall.peer;
81
82 // The block: nothing comes up, and nothing worse than "connecting" or
83 // "Reconnecting to …" is said before the minute.
84 let said = false;
85 let early = '';
86 let failure = false;
87 let maybeOld = false;
88 while (Date.now() - blockedAt < blockMs) {
89 const w = await web(app);
90 if (w.connection === 'connected') {
91 check(false, 'the browser connected to the app through the block');
92 break;
93 }
94 if (w.reconnecting || w.connecting) said = true;
95 if (/^Could not connect/.test(w.note)) {
96 if (Date.now() - blockedAt < 50000) early = w.note;
97 failure = true;
98 }
99 if (/may be on an old version of Calls/.test(w.note)) maybeOld = true;
100 await new Promise((r) => setTimeout(r, 250));
101 }
102 console.log('block over: browser ' + JSON.stringify(await web(app)) + '; app ' +
103 JSON.stringify({ iceConnected: sample.stats.iceConnectedPeers, recoveryTrying: sample.stats.recoveryTrying,
104 autoRestarts: sample.stats.autoRestarts, autoRebuilds: sample.stats.autoRebuilds, mangled: sample.stats.iceBlockMangled }));
105 check(said, 'the browser’s tile for the app said it was connecting, or Reconnecting to …');
106 check(!early, 'no failure sentence before its minute (' + early + ')');
107 if (blockMs >= 75000) {
108 check(failure, 'the failure sentence came once the minute had passed');
109 check(maybeOld === (kase === 'app-old'), 'the tile says the app may be old exactly when it does not say its version (' + maybeOld + ')');
110 }
111 check((await web(app)).client === (kase === 'app-old' ? 'native' : 'mac 9.9.9'),
112 'the roster names the app’s client (' + (await web(app)).client + ')');
113
114 // Nobody does anything.
115 const audio = sample.stats.audioBytesReceived;
116 const mended = await until(async () => {
117 const w = await web(app);
118 return w.connection === 'connected' && w.hearing && sample.stats.iceConnectedPeers === 1 &&
119 sample.stats.audioBytesReceived > audio + 10000 ? w : false;
120 }, within);
121 const w = await web(app);
122 console.log('browser: ' + JSON.stringify(w));
123 console.log('app: ' + JSON.stringify({ status: sample.status, notices: sample.notices, autoRestarts: sample.stats.autoRestarts,
124 autoRebuilds: sample.stats.autoRebuilds }));
125 if (check(mended, 'the browser and the app hear each other again within ' + within / 1000 + ' s of the block lifting, with nobody acting')) {
126 console.log('recovered ' + Math.round((Date.now() - blockedAt - blockMs) / 1000) + ' s after the block lifted');
127 }
128 if (kase === 'app-old') check(sample.stats.autoRestarts === 0 && w.autoRestarts > 0, 'the browser mended it alone');
129 if (kase === 'web-old') check(w.autoRestarts === 0 && sample.stats.autoRestarts > 0, 'the app mended it alone');
130 const quiet = await until(async () => {
131 const v = await web(app);
132 return !v.note && !v.reconnecting && !sample.status.includes('could not connect') ? v : false;
133 }, 5000);
134 check(quiet, 'the words go with the trouble, both sides');
135} catch (err) {
136 check(false, String(err && err.message || err));
137} finally {
138 if (native) {
139 try { native.stdin.write('leave\n'); } catch { /* gone */ }
140 await new Promise((r) => setTimeout(r, 1500));
141 native.kill();
142 }
143 await browser.close();
144}
145process.exit(failed ? 1 : 0);
146