/** * @file The look capability: one still frame from a camera aimed at the TV. * Who can see the room is who holds a Look. The box shows every look, with a tap and a flash * (body/look_signal.py): no indication, no look. */ import { RpcTarget } from 'capnweb'; /** * look() returns one frame, a JPEG in base64, taken while the box shows it's looking. * One at a time: one camera. */ export class Look extends RpcTarget { #signal; #grab; /** @type {Promise} the look before this one */ #last = Promise.resolve(); /** * @param {() => Promise<() => void>} signal has the box show it's looking; resolves, once it is, to a function that stops it * @param {() => Promise} grab one frame from the camera, as JPEG */ constructor(signal, grab) { super(); this.#signal = signal; this.#grab = grab; } look() { const job = async () => { const stop = await this.#signal(); try { return Buffer.from(await this.#grab()).toString('base64'); } finally { stop(); } }; const result = this.#last.then(job); this.#last = result.catch(() => {}); return result; } }