-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmedia_constraints.dart
150 lines (137 loc) · 4.32 KB
/
media_constraints.dart
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class MediaTrackConstraints {
MediaTrackConstraints({this.deviceId, this.groupId});
factory MediaTrackConstraints.fromMap(Map<String, dynamic> map) {
return MediaTrackConstraints(
deviceId: map['deviceId'] as String?,
groupId: map['groupId'] as String?,
);
}
final String? deviceId;
final String? groupId;
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
};
}
}
class AudioTrackConstraints extends MediaTrackConstraints {
AudioTrackConstraints({
required String deviceId,
required String groupId,
this.autoGainControl,
this.channelCount,
this.echoCancellation,
this.latency,
this.noiseSuppression,
this.sampleRate,
this.sampleSize,
this.volume,
}) : super(deviceId: deviceId, groupId: groupId);
factory AudioTrackConstraints.fromMap(Map<String, dynamic> map) {
return AudioTrackConstraints(
deviceId: map['deviceId'] as String,
groupId: map['groupId'] as String,
autoGainControl: map['autoGainControl'] as bool?,
channelCount: map['channelCount'] as bool?,
echoCancellation: map['echoCancellation'] as bool?,
latency: map['latency'] as bool?,
noiseSuppression: map['noiseSuppression'] as bool?,
sampleRate: map['sampleRate'] as bool?,
sampleSize: map['sampleSize'] as bool?,
volume: map['volume'] as bool?,
);
}
bool? autoGainControl;
bool? channelCount;
bool? echoCancellation;
bool? latency;
bool? noiseSuppression;
bool? sampleRate;
bool? sampleSize;
bool? volume;
@override
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
if (autoGainControl != null) 'autoGainControl': autoGainControl,
if (channelCount != null) 'channelCount': channelCount,
if (echoCancellation != null) 'echoCancellation': echoCancellation,
if (latency != null) 'latency': latency,
if (noiseSuppression != null) 'noiseSuppression': noiseSuppression,
if (sampleRate != null) 'sampleRate': sampleRate,
if (sampleSize != null) 'sampleSize': sampleSize,
if (volume != null) 'volume': volume,
};
}
}
class VideoTrackConstraints extends MediaTrackConstraints {
VideoTrackConstraints({
required String deviceId,
required String groupId,
this.aspectRatio,
this.frameRate,
this.facingMode,
this.height,
this.width,
}) : super(deviceId: deviceId, groupId: groupId);
factory VideoTrackConstraints.fromMap(Map<String, dynamic> map) {
return VideoTrackConstraints(
deviceId: map['deviceId'] as String,
groupId: map['groupId'] as String,
aspectRatio: map['aspectRatio'] as bool?,
frameRate: map['frameRate'] as bool?,
facingMode: map['facingMode'] as bool?,
height: map['height'] as bool?,
width: map['width'] as bool?,
);
}
bool? aspectRatio;
bool? frameRate;
bool? facingMode;
bool? height;
bool? width;
@override
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
if (aspectRatio != null) 'aspectRatio': aspectRatio,
if (frameRate != null) 'frameRate': frameRate,
if (facingMode != null) 'facingMode': facingMode,
if (height != null) 'height': height,
if (width != null) 'width': width,
};
}
}
class MediaStreamConstraints {
MediaStreamConstraints({
this.audio,
this.video,
});
factory MediaStreamConstraints.fromMap(Map<String, dynamic> map) {
return MediaStreamConstraints(
audio: map['audio'] is bool
? map['audio']
: AudioTrackConstraints.fromMap(map['audio']),
video: map['video'] is bool
? map['video']
: VideoTrackConstraints.fromMap(map['video']),
);
}
// bool or AudioTrackConstraints
dynamic audio;
// bool or VideoTrackConstraints
dynamic video;
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (audio != null)
'audio':
audio is bool ? audio : (audio as AudioTrackConstraints).toMap(),
if (video != null)
'video':
video is bool ? video : (video as VideoTrackConstraints).toMap(),
};
}
}