| 1 | // portraitCamera is an init script for the portrait-video gates |
| 2 | // (2026-10-21): the page's camera is a canvas held upright, 720 × 1280 — |
| 3 | // a phone's camera as a receiver sees it, rotation applied — with a red |
| 4 | // band across its top and a green one across its bottom, so a receiver |
| 5 | // that shows the whole frame shows both and one that crops to fill shows |
| 6 | // neither. window.__turnCamera(w, h) turns it (1280 × 720 is a phone |
| 7 | // turned on its side); the captured track follows the canvas's size. The |
| 8 | // microphone is still Chromium's fake one. |
| 9 | export const portraitCamera = () => { |
| 10 | const md = navigator.mediaDevices; |
| 11 | if (!md) return; |
| 12 | const original = md.getUserMedia.bind(md); |
| 13 | const canvas = document.createElement('canvas'); |
| 14 | canvas.width = 720; |
| 15 | canvas.height = 1280; |
| 16 | const g = canvas.getContext('2d'); |
| 17 | let t = 0; |
| 18 | const draw = () => { |
| 19 | const w = canvas.width; |
| 20 | const h = canvas.height; |
| 21 | const sky = g.createLinearGradient(0, 0, w, h); |
| 22 | sky.addColorStop(0, '#6d8fb3'); |
| 23 | sky.addColorStop(1, '#2f3d2a'); |
| 24 | g.fillStyle = sky; |
| 25 | g.fillRect(0, 0, w, h); |
| 26 | const u = Math.min(w, h); |
| 27 | g.fillStyle = '#c99a78'; |
| 28 | g.beginPath(); g.arc(w / 2, h * 0.42, u * 0.2, 0, Math.PI * 2); g.fill(); |
| 29 | g.fillStyle = '#7a3b2e'; |
| 30 | g.beginPath(); g.ellipse(w / 2, h * 0.42 + u * 0.55, u * 0.42, u * 0.3, 0, 0, Math.PI * 2); g.fill(); |
| 31 | g.fillStyle = '#ff0000'; |
| 32 | g.fillRect(0, 0, w, Math.round(h * 0.06)); |
| 33 | g.fillStyle = '#00ff00'; |
| 34 | g.fillRect(0, h - Math.round(h * 0.06), w, Math.round(h * 0.06)); |
| 35 | g.fillStyle = '#ffffff'; |
| 36 | g.fillRect((t * 7) % w, h * 0.5, 40, 4); |
| 37 | t += 1; |
| 38 | }; |
| 39 | draw(); |
| 40 | setInterval(draw, 50); |
| 41 | window.__turnCamera = (w, h) => { |
| 42 | canvas.width = w; |
| 43 | canvas.height = h; |
| 44 | draw(); |
| 45 | }; |
| 46 | md.getUserMedia = async (c = {}) => { |
| 47 | const tracks = []; |
| 48 | if (c.audio) { |
| 49 | const mic = await original({ audio: c.audio }); |
| 50 | tracks.push(...mic.getAudioTracks()); |
| 51 | } |
| 52 | if (c.video) tracks.push(canvas.captureStream(20).getVideoTracks()[0]); |
| 53 | return new MediaStream(tracks); |
| 54 | }; |
| 55 | }; |
| 56 | |