The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | /** A synchronous, borrowed frame. The producer releases its source after present returns. */ |
| 2 | export interface DeviceFrameSink { |
| 3 | readonly present: (source: CanvasImageSource, width: number, height: number) => boolean; |
| 4 | } |
| 5 | |
| 6 | export function createCanvasFrameSink( |
| 7 | canvas: HTMLCanvasElement, |
| 8 | onFrame?: (width: number, height: number) => void, |
| 9 | ): DeviceFrameSink { |
| 10 | return { |
| 11 | present(source, width, height) { |
| 12 | const context = canvas.getContext("2d"); |
| 13 | if (!context) return false; |
| 14 | if (canvas.width !== width || canvas.height !== height) { |
| 15 | canvas.width = width; |
| 16 | canvas.height = height; |
| 17 | } |
| 18 | context.drawImage(source, 0, 0, width, height); |
| 19 | onFrame?.(width, height); |
| 20 | return true; |
| 21 | }, |
| 22 | }; |
| 23 | } |