// syntheticMedia is an init script, used only when CALLS_SYNTHETIC_MEDIA // is set: for a machine where Chromium's fake devices cannot be used. // Chromium asks macOS for camera and microphone access even for them, on // behalf of whatever launched it, and when that process has never been // granted it (TCC "not determined") nobody can answer and getUserMedia // never settles — every scenario then stops at "Connecting to the call." // (2026-10-05, from an agent's shell). This draws the camera and the // screen on canvases instead (a head and shoulders on a gradient, moving; // a 16:10 document) and makes the microphone a quiet tone. Scenarios that // assert on Chromium's own fake device names do not hold under it: it is // a stand-in, said so in the run, never the gate's normal way. export const syntheticMedia = () => { const md = navigator.mediaDevices; if (!md) return; const drawn = (w, h, draw) => { const c = document.createElement('canvas'); c.width = w; c.height = h; const g = c.getContext('2d'); let t = 0; draw(g, w, h, 0); setInterval(() => draw(g, w, h, ++t), 50); return c.captureStream(20).getVideoTracks()[0]; }; const camera = () => drawn(640, 360, (g, w, h, t) => { const sky = g.createLinearGradient(0, 0, w, h); sky.addColorStop(0, '#6d8fb3'); sky.addColorStop(1, '#2f3d2a'); g.fillStyle = sky; g.fillRect(0, 0, w, h); g.fillStyle = '#c99a78'; g.beginPath(); g.ellipse(w / 2, h * 0.36, w * 0.09, h * 0.2, 0, 0, Math.PI * 2); g.fill(); g.fillStyle = '#7a3b2e'; g.beginPath(); g.ellipse(w / 2, h * 1.02, w * 0.24, h * 0.42, 0, 0, Math.PI * 2); g.fill(); g.fillStyle = '#ffffff'; g.fillRect((t * 7) % w, h - 8, 40, 4); }); const screen = () => drawn(1280, 800, (g, w, h, t) => { g.fillStyle = '#f4f1ea'; g.fillRect(0, 0, w, h); g.fillStyle = '#1f6f8b'; g.fillRect(0, 0, w, 48); g.fillStyle = '#c0392b'; g.fillRect(w - 160, h - 120, 120, 80); g.fillStyle = '#333'; for (let y = 90; y < h - 40; y += 28) g.fillRect(60, y, w - 120 - ((y * 37) % 300), 10); g.fillStyle = '#f39c12'; g.fillRect((t * 9) % w, 56, 30, 30); }); const tone = () => { const ac = new AudioContext(); const o = ac.createOscillator(); const gain = ac.createGain(); gain.gain.value = 0.02; const out = ac.createMediaStreamDestination(); o.connect(gain).connect(out); o.start(); return out.stream.getAudioTracks()[0]; }; md.getUserMedia = async (c = {}) => { const tracks = []; if (c.audio) tracks.push(tone()); if (c.video) tracks.push(camera()); return new MediaStream(tracks); }; md.getDisplayMedia = async () => new MediaStream([screen()]); };