Houjie
2025-04-11 1bf977929dd324f3ac64b70debd8a79443c54392
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
 * @fileoverview
 * Set of factory implementations around Camera.
 * 
 * @author mebjas <minhazav@gmail.com>
 */
 
import { Camera } from "./core";
import { CameraImpl } from "./core-impl";
 
/** Factory class for creating Camera. */
export class CameraFactory {
 
    /**
     * Returns {@link CameraFactory} if {@link navigator.mediaDevices} is
     * supported else fails.
     */
    public static async failIfNotSupported(): Promise<CameraFactory> {
        if (!navigator.mediaDevices) {
            throw "navigator.mediaDevices not supported";
        }
 
        return new CameraFactory();
    }
 
    private constructor() { /* No Op. */ }
 
    /** Creates camera instance based on constraints. */
    public async create(videoConstraints: MediaTrackConstraints)
        : Promise<Camera> {
        return CameraImpl.create(videoConstraints);
    }
}