Spaces:
Running
Running
Download src/webcam-session.js from LiquidAI/LFM2.5-VL-3B-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 877 Bytes
-
https://huggingface.co/spaces/LiquidAI/LFM2.5-VL-3B-WebGPU/resolve/main/src/webcam-session.js
- Command line
-
hf download hf://spaces/LiquidAI/LFM2.5-VL-3B-WebGPU/src/webcam-session.js
-
curl -L -o webcam-session.js https://huggingface.co/spaces/LiquidAI/LFM2.5-VL-3B-WebGPU/resolve/main/src/webcam-session.js
877 Bytes
| function stopStream(stream) { | |
| stream?.getTracks?.().forEach(track => track.stop()); | |
| } | |
| export class WebcamSession { | |
| constructor(acquire) { | |
| this.acquire = acquire; | |
| this.stream = null; | |
| this.pending = null; | |
| this.version = 0; | |
| } | |
| async open(constraints) { | |
| if (this.stream) return this.stream; | |
| if (this.pending) return this.pending; | |
| const version = this.version; | |
| const pending = Promise.resolve(this.acquire(constraints)).then(stream => { | |
| if (version !== this.version) { | |
| stopStream(stream); | |
| return null; | |
| } | |
| this.stream = stream; | |
| return stream; | |
| }).finally(() => { | |
| if (this.pending === pending) this.pending = null; | |
| }); | |
| this.pending = pending; | |
| return pending; | |
| } | |
| close() { | |
| this.version += 1; | |
| this.pending = null; | |
| stopStream(this.stream); | |
| this.stream = null; | |
| } | |
| } | |