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
124
125
126
127
128
129
130
131
/// The directions that the camera can face, as seen from the user's perspective.
///
/// # Note
/// The enumeration is not exhaustive and merely provides a list of known values.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum FacingMode {
/// The source is facing toward the user (a self-view camera).
User,
/// The source is facing away from the user (viewing the environment).
Environment,
/// The source is facing to the left of the user.
Left,
/// The source is facing to the right of the user.
Right,
}
impl FacingMode {
/// Returns `"user"`, the string-value of the `User` facing mode.
pub fn user() -> String {
Self::User.to_string()
}
/// Returns `"environment"`, the string-value of the `Environment` facing mode.
pub fn environment() -> String {
Self::Environment.to_string()
}
/// Returns `"left"`, the string-value of the `Left` facing mode.
pub fn left() -> String {
Self::Left.to_string()
}
/// Returns `"right"`, the string-value of the `Right` facing mode.
pub fn right() -> String {
Self::Right.to_string()
}
}
impl std::fmt::Display for FacingMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::User => f.write_str("user"),
Self::Environment => f.write_str("environment"),
Self::Left => f.write_str("left"),
Self::Right => f.write_str("right"),
}
}
}
/// The means by which the resolution can be derived by the client.
///
/// # Note
/// The enumeration is not exhaustive and merely provides a list of known values.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ResizeMode {
/// This resolution and frame rate is offered by the camera, its driver, or the OS.
///
/// # Note
/// The user agent MAY report this value to disguise concurrent use,
/// but only when the camera is in use in another browsing context.
///
/// # Important
/// This value is a possible finger-printing surface.
None,
/// This resolution is downscaled and/or cropped from a higher camera resolution by the user agent,
/// or its frame rate is decimated by the User Agent.
///
/// # Important
/// The media MUST NOT be upscaled, stretched or have fake data created that did not occur in the input source.
CropAndScale,
}
impl ResizeMode {
/// Returns `"none"`, the string-value of the `None` resize mode.
pub fn none() -> String {
Self::None.to_string()
}
/// Returns `"crop-and-scale"`, the string-value of the `CropAndScale` resize mode.
pub fn crop_and_scale() -> String {
Self::CropAndScale.to_string()
}
}
impl std::fmt::Display for ResizeMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::None => f.write_str("none"),
Self::CropAndScale => f.write_str("crop-and-scale"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
mod facing_mode {
use super::*;
#[test]
fn to_string() {
assert_eq!(FacingMode::User.to_string(), "user");
assert_eq!(FacingMode::Environment.to_string(), "environment");
assert_eq!(FacingMode::Left.to_string(), "left");
assert_eq!(FacingMode::Right.to_string(), "right");
assert_eq!(FacingMode::user(), "user");
assert_eq!(FacingMode::environment(), "environment");
assert_eq!(FacingMode::left(), "left");
assert_eq!(FacingMode::right(), "right");
}
}
mod resize_mode {
use super::*;
#[test]
fn to_string() {
assert_eq!(ResizeMode::None.to_string(), "none");
assert_eq!(ResizeMode::CropAndScale.to_string(), "crop-and-scale");
assert_eq!(ResizeMode::none(), "none");
assert_eq!(ResizeMode::crop_and_scale(), "crop-and-scale");
}
}
}