-
Notifications
You must be signed in to change notification settings - Fork 37
/
Browser.MediaStream.fs
420 lines (348 loc) · 14.8 KB
/
Browser.MediaStream.fs
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
namespace Browser.Types
open System
open Fable.Core
open Browser
open Browser.Types
type MediaTrackSupportedConstraints =
abstract autoGainControl:bool option with get, set
abstract width:bool option with get, set
abstract height:bool option with get, set
abstract aspectRatio:bool option with get, set
abstract frameRate:bool option with get, set
abstract facingMode:bool option with get, set
abstract resizeMode:bool option with get, set
abstract volume:bool option with get, set
abstract sampleRate:bool option with get, set
abstract sampleSize:bool option with get, set
abstract echoCancellation:bool option with get, set
abstract latency:bool option with get, set
abstract noiseSuppression:bool option with get, set
abstract channelCount:bool option with get, set
abstract deviceId:bool option with get, set
abstract groupId:bool option with get, set
abstract displaySurface:bool option with get, set
abstract logicalSurface:bool option with get, set
abstract cursor:bool option with get, set
abstract restrictOwnAudio:bool option with get, set
type Range<'T> =
abstract max: 'T option with get, set
abstract min: 'T option with get, set
type SteppedRange<'T> =
abstract max: 'T option with get, set
abstract min: 'T option with get, set
abstract step: 'T option with get, set
type ULongRange = Range<uint32>
type DoubleRange = Range<float>
type ConstrainRange<'T> =
inherit Range<'T>
abstract exact: 'T option with get, set
abstract ideal: 'T option with get, set
type Constrain<'T> =
abstract exact: 'T option with get, set
abstract ideal: 'T option with get, set
[<Erase>]
type ConstrainOrRange<'T> =
| Value of 'T
| ConstrainRange of ConstrainRange<'T>
type ConstrainOrRangeULong = ConstrainOrRange<uint32>
type ConstrainOrRangeDouble = ConstrainOrRange<float>
[<Erase>]
type ConstrainOrValue<'T> =
| Value of 'T
| Constrain of Constrain<'T>
type ConstrainULong = ConstrainOrValue<uint32>
type ConstrainDouble = ConstrainOrValue<float>
type ConstrainBoolean = ConstrainOrValue<bool>
type ConstrainString = ConstrainOrValue<string>
type MediaTrackConstraintSet =
abstract deviceId: ConstrainString option with get, set
abstract groupId: ConstrainString option with get, set
type MediaTrackSettings =
abstract deviceId: string
abstract groupId: string
[<Obsolete("Naming changed, please use AudioMediaTrackConstraintSet")>]
type AudioConstraint =
inherit MediaTrackConstraintSet
abstract autoGainControl: ConstrainBoolean option with get, set
abstract channelCount: ConstrainOrRangeULong option with get, set
abstract echoCancellation: ConstrainBoolean option with get, set
abstract latency: ConstrainOrRangeDouble option with get, set
abstract noiseSuppression: ConstrainBoolean option with get, set
abstract sampleRate: ConstrainOrRangeULong option with get, set
abstract sampleSize: ConstrainOrRangeULong option with get, set
abstract volume: ConstrainOrRangeDouble option with get, set
type AudioMediaTrackConstraintSet =
inherit MediaTrackConstraintSet
abstract autoGainControl: ConstrainBoolean option with get, set
abstract channelCount: ConstrainOrRangeULong option with get, set
abstract echoCancellation: ConstrainBoolean option with get, set
abstract latency: ConstrainOrRangeDouble option with get, set
abstract noiseSuppression: ConstrainBoolean option with get, set
abstract sampleRate: ConstrainOrRangeULong option with get, set
abstract sampleSize: ConstrainOrRangeULong option with get, set
abstract volume: ConstrainOrRangeDouble option with get, set
type AudioMediaTrackSettings =
inherit MediaTrackSettings
abstract autoGainControl: bool
abstract channelCount: uint32
abstract echoCancellation: bool
abstract latency: double
abstract noiseSuppression: bool
abstract sampleRate: uint32
abstract sampleSize: uint32
abstract volume: double
[<StringEnum>]
type ShotMode =
| [<CompiledName("none")>] None'
| Manual
| [<CompiledName("single-shot")>] SingleShot
| Continuous
type ConstrainShotMode = Constrain<ShotMode>
type PointsOfInterest =
abstract x:uint32 with get, set
abstract y:uint32 with get, set
[<Erase>]
type PointsOfInterestConstraint =
| Point of PointsOfInterest
| Points of ResizeArray<PointsOfInterest>
type ImageMediaTrackConstraintSet =
inherit MediaTrackConstraintSet
abstract whiteBalanceMode: ConstrainShotMode option with get, set
abstract exposureMode: ConstrainShotMode option with get, set
abstract focusMode: ConstrainShotMode option with get, set
abstract pointsOfInterest: PointsOfInterestConstraint option with get, set
abstract exposureCompensation: ConstrainDouble option with get, set
abstract colorTemperature: ConstrainDouble option with get, set
abstract iso: ConstrainDouble option with get, set
abstract brightness: ConstrainDouble option with get, set
abstract contrast: ConstrainDouble option with get, set
abstract saturation: ConstrainDouble option with get, set
abstract sharpness: ConstrainDouble option with get, set
abstract focusDistance: ConstrainDouble option with get, set
abstract zoom: ConstrainDouble option with get, set
abstract torch: ConstrainBoolean option with get, set
type ImageMediaTrackSettings =
inherit MediaTrackSettings
abstract whiteBalanceMode: ShotMode
abstract exposureMode: ShotMode
abstract focusMode: ShotMode
abstract pointsOfInterest: U2<PointsOfInterest array, PointsOfInterest> option
abstract exposureCompensation: double option
abstract colorTemperature: double option
abstract iso: double option
abstract brightness: double option
abstract contrast: double option
abstract saturation: double option
abstract sharpness: double option
abstract focusDistance: double option
abstract zoom: double option
abstract torch: bool option
[<StringEnum>]
type ResizeMode =
| [<CompiledName("none")>] None'
| [<CompiledName("crop-and-scale")>] CropAndScale
type ConstrainResizeMode = Constrain<ResizeMode>
[<StringEnum>]
type FacingMode =
| User
| Environment
| Left
| Right
type ConstrainFacingMode = Constrain<FacingMode>
type VideoMediaTrackConstraintSet =
inherit MediaTrackConstraintSet
abstract aspectRatio: ConstrainOrRangeDouble option with get, set
abstract facingMode: ConstrainFacingMode option with get, set
abstract frameRate: ConstrainOrRangeDouble option with get, set
abstract height: ConstrainOrRangeULong option with get, set
abstract width: ConstrainOrRangeULong option with get, set
abstract resizeMode: ConstrainResizeMode option with get, set
type VideoMediaTrackSettings =
inherit MediaTrackSettings
inherit ImageMediaTrackSettings
abstract aspectRatio: float
abstract facingMode: FacingMode
abstract frameRate: double
abstract height: uint32
abstract width: uint32
abstract resizeMode: ResizeMode
[<StringEnum>]
type Cursor =
| Always
| Motion
| Never
type ConstrainCursor = Constrain<ResizeArray<Cursor>>
[<StringEnum>]
type DisplaySurface =
| Application
| Browser
| Monitor
| Window
type ConstrainDisplaySurface = Constrain<ResizeArray<DisplaySurface>>
type SharedScreenMediaTrackSettings =
inherit MediaTrackSettings
abstract cursor: Cursor
abstract displaySurface: DisplaySurface
abstract logicalSurface: bool
type MediaTrackConstraints =
inherit MediaTrackConstraintSet
abstract advanced: ResizeArray<MediaTrackConstraintSet> option with get, set
type VideoMediaTrackConstraints =
inherit VideoMediaTrackConstraintSet
inherit ImageMediaTrackConstraintSet
inherit MediaTrackConstraints
type AudioMediaTrackConstraints =
inherit AudioMediaTrackConstraintSet
inherit MediaTrackConstraints
type SharedScreenMediaTrackConstraintSet =
inherit VideoMediaTrackConstraints
abstract cursor: ConstrainCursor option with get, set
abstract displaySurface: ConstrainDisplaySurface option with get, set
abstract logicalSurface: ConstrainBoolean option with get, set
abstract restrictOwnAudio: ConstrainBoolean option with get, set
[<Erase>]
type StreamConstraintOrBool<'T> =
| Bool of bool
| Constraint of 'T
type MediaStreamConstraints =
abstract video:StreamConstraintOrBool<VideoMediaTrackConstraints> with get, set
abstract audio:StreamConstraintOrBool<AudioMediaTrackConstraints> with get, set
type DisplayMediaStreamConstraints =
abstract video:StreamConstraintOrBool<SharedScreenMediaTrackConstraintSet> with get, set
abstract audio:StreamConstraintOrBool<AudioMediaTrackConstraints> with get, set
[<StringEnum>]
type TrackKind =
| Audio
| Video
[<StringEnum>]
type MediaStreamTrackState =
| Live
| Ended
type MediaTrackCapabilities =
abstract width: ULongRange option
abstract height: ULongRange option
abstract aspectRatio: DoubleRange option
abstract frameRate: DoubleRange option
abstract facingMode: FacingMode array option
abstract resizeMode: ResizeMode array option
abstract sampleRate: ULongRange option
abstract sampleSize: ULongRange option
abstract echoCancellation: bool array option
abstract autoGainControl: bool array option
abstract noiseSuppression: bool array option
abstract latency: DoubleRange option
abstract channelCount: ULongRange option
abstract deviceId: string option
abstract groupId: string option
abstract colorTemperature: SteppedRange<uint32> option
abstract exposureMode: ShotMode array option
abstract exposureCompensation: SteppedRange<float> option
abstract exposureTime: SteppedRange<uint32> option
abstract focusDistance: SteppedRange<float> option
abstract focusMode: ShotMode array option
abstract iso: SteppedRange<uint32> option
abstract torch: bool option
abstract whiteBalanceMode: ShotMode array option
abstract zoom: SteppedRange<uint32> option
type [<Global>] MediaStreamTrack =
inherit EventTarget
abstract kind: TrackKind
abstract id: string
abstract label: string
abstract enabled: bool with get, set
abstract muted: bool
abstract onmute: (Event -> unit) with get, set
abstract onunmute: (Event -> unit) with get, set
abstract onended: (Event -> unit) with get, set
abstract readyState: MediaStreamTrackState
abstract clone: unit -> MediaStreamTrack
abstract stop: unit -> unit
abstract getCapabilities: unit -> MediaTrackCapabilities
abstract getConstraints: unit -> MediaTrackConstraints
abstract getSettings: unit -> MediaTrackSettings
abstract applyConstraints: constraints:#MediaTrackConstraints option -> JS.Promise<unit>
type [<Global>] MediaStreamTrackEvent =
abstract track: MediaStreamTrack
type AudioMediaStreamTrack =
inherit MediaStreamTrack
abstract clone: unit -> AudioMediaStreamTrack
abstract applyConstraints: constraints:AudioMediaTrackConstraints option -> JS.Promise<unit>
abstract getConstraints: unit -> AudioMediaTrackConstraints
abstract getSettings: unit -> AudioMediaTrackSettings
type VideoMediaStreamTrack =
inherit MediaStreamTrack
abstract clone: unit -> VideoMediaStreamTrack
abstract applyConstraints: constraints:VideoMediaTrackConstraints option -> JS.Promise<unit>
abstract getConstraints: unit -> VideoMediaTrackConstraints
abstract getSettings: unit -> VideoMediaTrackSettings
type [<AllowNullLiteral>] MediaStreamError =
abstract constraintName: string option
abstract message: string option
abstract name: string
type [<AllowNullLiteral>] MediaStreamErrorType =
abstract prototype: MediaStreamError with get, set
[<Emit "new $0($1...)">] abstract Create: unit -> obj
type [<Global>] MediaStream =
inherit EventTarget
abstract active: bool
abstract id: string
abstract onaddtrack: (MediaStreamTrackEvent->unit) with get, set
abstract clone: unit -> MediaStream
abstract getAudioTracks: unit -> AudioMediaStreamTrack array
abstract getVideoTracks: unit -> VideoMediaStreamTrack array
abstract getTrackById: string option -> MediaStreamTrack option
abstract getTracks: unit -> MediaStreamTrack array
abstract addTrack: track:#MediaStreamTrack -> unit
abstract removeTrack: track:#MediaStreamTrack -> unit
abstract onremovetrack: (MediaStreamTrackEvent->unit) with get, set
type MediaStreamType =
[<Emit("new $0($1...)")>] abstract Create: ?streams: MediaStreamTrack array -> MediaStream
[<Emit("new $0($1...)")>] abstract Create: streams: MediaStream -> MediaStream
type CanvasCaptureMediaStreamTrack =
inherit MediaStreamTrack
abstract canvas: HTMLCanvasElement
abstract requestFrame : unit -> unit
[<StringEnum>]
type MediaDeviceKind =
| [<CompiledName("videoinput")>] VideoInput
| [<CompiledName("audioinput")>] AudioInput
| [<CompiledName("audiooutput")>] AudioOutput
type [<Global>] MediaDeviceInfo =
abstract deviceId: string
abstract groupId: string
abstract kind: MediaDeviceKind
abstract label: string
type [<Global>] MediaDevices =
inherit EventTarget
abstract getSupportedConstraints: unit -> MediaTrackSupportedConstraints
abstract getUserMedia: constraints: MediaStreamConstraints -> JS.Promise<MediaStream>
abstract getDisplayMedia: ?constraints: DisplayMediaStreamConstraints -> JS.Promise<MediaStream>
abstract enumerateDevices: unit -> JS.Promise<ResizeArray<MediaDeviceInfo>>
abstract ondevicechange: (Event->unit) with get, set
type MediaStreamConstraintsType =
[<Emit("new Object({ video: $1, audio: $2 })")>]
abstract Create: video : bool * audio : bool -> MediaStreamConstraints
[<Emit("new Object({ video: $1, audio: $2 })")>]
abstract Create: video : VideoMediaTrackConstraints * audio : bool -> MediaStreamConstraints
[<Emit("new Object({ video: $1, audio: $2 })")>]
abstract Create: video : VideoMediaTrackConstraints * audio : AudioMediaTrackConstraints -> MediaStreamConstraints
[<Emit("new Object({ video: $1, audio: $2 })")>]
abstract Create: video : bool * audio : AudioMediaTrackConstraints -> MediaStreamConstraints
type HTMLVideoElement' =
inherit HTMLVideoElement
abstract srcObject: MediaStream option with get, set
type HTMLAudioElement' =
inherit HTMLAudioElement
abstract srcObject: MediaStream option with get, set
namespace Browser
open Fable.Core
[<AutoOpenAttribute>]
module MediaStreams =
open Browser.Types
type HTMLCanvasElement with
[<Emit("$0.captureStream({{$1}})")>]
member __.captureStream(?framerate:uint32) : MediaStream = failwith ""
let [<Emit("navigator.mediaDevices")>] mediaDevices: MediaDevices = jsNative
let [<Global>] MediaStream: MediaStreamType = jsNative
let [<Global>] MediaStreamConstraints: MediaStreamConstraintsType = jsNative
let [<Global>] MediaStreamError : MediaStreamErrorType = jsNative