forked from Snapchat/react-camera-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
123 lines (103 loc) · 3.32 KB
/
Copy pathtypes.ts
File metadata and controls
123 lines (103 loc) · 3.32 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Lens, LensLaunchData } from "@snap/camera-kit";
export type SourceStatus =
| { state: "none" }
| { state: "loading" }
| { state: "ready" }
| { state: "error"; error: Error };
export type LensStatus =
| { state: "none" }
| { state: "loading" }
| { state: "ready" }
| { state: "error"; error: Error };
export interface CurrentSource {
status: "none" | "loading" | "ready" | "error";
error: Error | undefined;
input: SourceInput | undefined;
initializedInput: SourceOutput | undefined;
}
export interface CurrentLens {
status: "none" | "loading" | "ready" | "error";
error: Error | undefined;
lensId: string | undefined;
lensGroupId: string | undefined;
lensLaunchData: LensLaunchData | undefined;
lensReadyGuard: (() => Promise<void>) | undefined;
lens: Lens | undefined;
}
export const NO_CURRENT_LENS: CurrentLens = {
status: "none",
error: undefined,
lensId: undefined,
lensGroupId: undefined,
lensLaunchData: undefined,
lensReadyGuard: undefined,
lens: undefined,
};
export type CameraSourceInput = {
kind: "camera";
deviceId?: string;
options?: SourceOptions;
};
export type VideoSourceInput = {
kind: "video";
url: string;
autoplay?: boolean;
/**
* Optional URL of a recorded tracking-data buffer to replay against the video (e.g. a Lens Studio
* `.td` file). When provided, it is fetched and passed to `createVideoSource` as `trackingData`, so
* the lens is driven by the recorded camera pose / tracking instead of live tracking. Useful for
* previewing world-facing lenses from a recorded environment.
*/
trackingDataUrl?: string;
};
export type ImageSourceInput = { kind: "image"; url: string };
export type SourceInput = CameraSourceInput | VideoSourceInput | ImageSourceInput;
export function isCameraSource(source: SourceInput | undefined): source is CameraSourceInput {
return source?.kind === "camera";
}
export function isVideoSource(source: SourceInput | undefined): source is VideoSourceInput {
return source?.kind === "video";
}
export function isImageSource(source: SourceInput | undefined): source is ImageSourceInput {
return source?.kind === "image";
}
export interface CameraInfo {
kind: "camera";
deviceId: string;
label: string;
}
export type CameraSourceOutput = CameraInfo;
export type VideoSourceOutput = {
kind: "video";
url: string;
videoElement: HTMLVideoElement;
};
export type ImageSourceOutput = {
kind: "image";
url: string;
imageElement: HTMLImageElement;
};
export type SourceOutput = CameraSourceOutput | VideoSourceOutput | ImageSourceOutput;
/** Explicit, fixed‐pixel dimensions */
export interface FixedOutputSize {
mode: "fixed";
width: number;
height: number;
}
/** Exactly match whatever the camera/input delivers */
export interface MatchInputSize {
mode: "match-input";
}
export const CameraRotationOptions = [0, -90, 90, 180] as const;
export type OutputSize = MatchInputSize | FixedOutputSize;
export interface SourceOptions {
cameraFacing?: CameraFacing;
cameraConstraints?: CameraConstraints;
cameraRotation?: CameraRotation;
fpsLimit?: number;
outputSize?: OutputSize;
}
export type CameraFacing = "user" | "environment";
export type CameraConstraints = MediaTrackConstraints;
export type CameraRotation = (typeof CameraRotationOptions)[number];
export type CanvasType = "live" | "capture";