@pexip/media-control 16.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +967 -0
- package/LICENSE +188 -0
- package/README.md +244 -0
- package/dist/index.d.ts +923 -0
- package/dist/index.mjs +1635 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A striped version of MediaDeviceInfo
|
|
3
|
+
*
|
|
4
|
+
* @beta
|
|
5
|
+
*/
|
|
6
|
+
type MediaDeviceInfoLike = Omit<MediaDeviceInfo, 'toJSON'> & {
|
|
7
|
+
settings?: MediaTrackSettings;
|
|
8
|
+
toJSON?: MediaDeviceInfo['toJSON'];
|
|
9
|
+
};
|
|
10
|
+
type DeviceConstraint = MediaDeviceInfoLike | MediaDeviceInfoLike[];
|
|
11
|
+
interface ConstraintDeviceParameters {
|
|
12
|
+
exact?: DeviceConstraint;
|
|
13
|
+
ideal?: DeviceConstraint;
|
|
14
|
+
}
|
|
15
|
+
interface InputConstraintSet extends MediaTrackConstraints {
|
|
16
|
+
/**
|
|
17
|
+
* Same purpose as `deviceId` but it gives more information about the device
|
|
18
|
+
* so that we can have extra tolerance on device selection
|
|
19
|
+
*/
|
|
20
|
+
device?: DeviceConstraint | ConstraintDeviceParameters;
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not using video segmentation, e.g. background
|
|
23
|
+
* blur/replacement, to specify the effects, intended to be applied to the
|
|
24
|
+
* segment. Available effects are `none`, `blur`, `overlay` or `remove`
|
|
25
|
+
*/
|
|
26
|
+
videoSegmentation?: ConstrainDOMString;
|
|
27
|
+
/**
|
|
28
|
+
* Segmentation model to be used for video segmentation, currently only
|
|
29
|
+
* supports `mediapipeSelfie` and `personify`
|
|
30
|
+
*/
|
|
31
|
+
videoSegmentationModel?: ConstrainDOMString;
|
|
32
|
+
/**
|
|
33
|
+
* Whether or not using our own noise suppression
|
|
34
|
+
*/
|
|
35
|
+
denoise?: ConstrainBoolean;
|
|
36
|
+
/**
|
|
37
|
+
* Voice Activity Detection
|
|
38
|
+
*/
|
|
39
|
+
vad?: ConstrainBoolean;
|
|
40
|
+
/**
|
|
41
|
+
* Audio Signal Detection for the purpose of checking if the audio input is
|
|
42
|
+
* hardware muted or unusable
|
|
43
|
+
*/
|
|
44
|
+
asd?: ConstrainBoolean;
|
|
45
|
+
/**
|
|
46
|
+
* Audio Signal Detection for the purpose of checking if the audio input is
|
|
47
|
+
* hardware muted or unusable
|
|
48
|
+
*/
|
|
49
|
+
mixWithAdditionalMedia?: ConstrainBoolean;
|
|
50
|
+
/**
|
|
51
|
+
* Flip the video horizontally
|
|
52
|
+
*/
|
|
53
|
+
flipHorizontal?: ConstrainBoolean;
|
|
54
|
+
/**
|
|
55
|
+
* Blur size/level parameter when using video segmentation with `blur`
|
|
56
|
+
* effects
|
|
57
|
+
*/
|
|
58
|
+
backgroundBlurAmount?: ConstrainULong;
|
|
59
|
+
/**
|
|
60
|
+
* Blur amount applied to the segmented person's edge
|
|
61
|
+
*/
|
|
62
|
+
edgeBlurAmount?: ConstrainULong;
|
|
63
|
+
/**
|
|
64
|
+
* Erode level for edge smoothing when using video segmentation
|
|
65
|
+
*/
|
|
66
|
+
foregroundThreshold?: ConstrainDouble;
|
|
67
|
+
/**
|
|
68
|
+
* Image Url that is being used for video overlay effects
|
|
69
|
+
*/
|
|
70
|
+
bgImageUrl?: ConstrainDOMString;
|
|
71
|
+
}
|
|
72
|
+
type InputDeviceConstraint = DeviceConstraint | InputConstraintSet | boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The request constraints that applies to `getMediaStream`
|
|
75
|
+
*
|
|
76
|
+
* @beta
|
|
77
|
+
*/
|
|
78
|
+
interface MediaDeviceRequest {
|
|
79
|
+
/**
|
|
80
|
+
* Either a Boolean (which indicates whether or not an audio track is
|
|
81
|
+
* requested) or a {@link MediaDeviceInfoLike} object providing a hint for the
|
|
82
|
+
* audio track included in the returned MediaStream
|
|
83
|
+
*/
|
|
84
|
+
audio?: InputDeviceConstraint;
|
|
85
|
+
/**
|
|
86
|
+
* Either a Boolean (which indicates whether or not an video track is
|
|
87
|
+
* requested) or a {@link MediaDeviceInfoLike} object providing a hint for the
|
|
88
|
+
* video track included in the returned MediaStream
|
|
89
|
+
*/
|
|
90
|
+
video?: InputDeviceConstraint;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* an enum of MediaDeviceKind which can be reused
|
|
94
|
+
*
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
declare enum MediaDeviceKinds {
|
|
98
|
+
/** audio input */
|
|
99
|
+
AUDIOINPUT = "audioinput",
|
|
100
|
+
/** audio output */
|
|
101
|
+
AUDIOOUTPUT = "audiooutput",
|
|
102
|
+
/** video input */
|
|
103
|
+
VIDEOINPUT = "videoinput"
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* MediaTrackConstraints.facingMode
|
|
107
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode}
|
|
108
|
+
*/
|
|
109
|
+
declare const FACING_MODE: readonly ["user", "environment", "left", "right"];
|
|
110
|
+
type FacingMode = (typeof FACING_MODE)[number];
|
|
111
|
+
/**
|
|
112
|
+
* An enum of failure events for media device
|
|
113
|
+
*
|
|
114
|
+
* @beta
|
|
115
|
+
*/
|
|
116
|
+
declare enum MediaDeviceFailure {
|
|
117
|
+
/**
|
|
118
|
+
* some problem (not user or permissions) occurred which prevented the device
|
|
119
|
+
* from being used.
|
|
120
|
+
*/
|
|
121
|
+
AbortError = "AbortError",
|
|
122
|
+
/**
|
|
123
|
+
* Custom error for when selected audio and video device is not found
|
|
124
|
+
*/
|
|
125
|
+
AudioAndVideoDeviceNotFoundError = "AudioAndVideoDeviceNotFoundError",
|
|
126
|
+
/**
|
|
127
|
+
* Custom error for selected audio device not found
|
|
128
|
+
*/
|
|
129
|
+
AudioInputDeviceNotFoundError = "AudioInputDeviceNotFoundError",
|
|
130
|
+
/**
|
|
131
|
+
* Custom missing constraints error
|
|
132
|
+
*/
|
|
133
|
+
MissingConstraintsError = "MissingConstraintsError",
|
|
134
|
+
/**
|
|
135
|
+
* user has blocked access
|
|
136
|
+
*/
|
|
137
|
+
NotAllowedError = "NotAllowedError",
|
|
138
|
+
/**
|
|
139
|
+
* the media tracks doesn't match the constraints
|
|
140
|
+
*/
|
|
141
|
+
NotFoundError = "NotFoundError",
|
|
142
|
+
/**
|
|
143
|
+
* hardware failure after user granted access
|
|
144
|
+
*/
|
|
145
|
+
NotReadableError = "NotReadableError",
|
|
146
|
+
/**
|
|
147
|
+
* no devices met the criteria for the constraints
|
|
148
|
+
*/
|
|
149
|
+
OverconstrainedError = "OverconstrainedError",
|
|
150
|
+
/**
|
|
151
|
+
* user has blocked access old chrome
|
|
152
|
+
*/
|
|
153
|
+
PermissionDeniedError = "PermissionDeniedError",
|
|
154
|
+
/**
|
|
155
|
+
* User media support disabled by agent
|
|
156
|
+
*/
|
|
157
|
+
SecurityError = "SecurityError",
|
|
158
|
+
/**
|
|
159
|
+
* when hardware in use old chrome win os
|
|
160
|
+
*/
|
|
161
|
+
TrackStartError = "TrackStartError",
|
|
162
|
+
/**
|
|
163
|
+
* GetUserMedia invalid constraints error
|
|
164
|
+
*/
|
|
165
|
+
TypeError = "TypeError",
|
|
166
|
+
/**
|
|
167
|
+
* Custom error for selected video device not found
|
|
168
|
+
*/
|
|
169
|
+
VideoInputDeviceNotFoundError = "VideoInputDeviceNotFoundError",
|
|
170
|
+
/**
|
|
171
|
+
* action or function is not supported by the current platform
|
|
172
|
+
*/
|
|
173
|
+
NotSupportedError = "NotSupportedError",
|
|
174
|
+
/**
|
|
175
|
+
* Canvas capture is not supported
|
|
176
|
+
*/
|
|
177
|
+
StreamTrackNotFound = "StreamTrackNotFound"
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Lesser strict type of `MediaStreamTrack`
|
|
181
|
+
*
|
|
182
|
+
* @beta
|
|
183
|
+
*/
|
|
184
|
+
type MediaStreamTrackLike = Pick<MediaStreamTrack, 'id' | 'kind' | 'label' | 'getSettings' | 'stop'>;
|
|
185
|
+
/**
|
|
186
|
+
* Holds user media input devices
|
|
187
|
+
*
|
|
188
|
+
* @beta
|
|
189
|
+
*/
|
|
190
|
+
interface MediaInput {
|
|
191
|
+
audioInput?: MediaDeviceInfoLike;
|
|
192
|
+
videoInput?: MediaDeviceInfoLike;
|
|
193
|
+
}
|
|
194
|
+
type Unsubscribe = () => void;
|
|
195
|
+
type TrackEventCallback = (track: MediaStreamTrack) => void;
|
|
196
|
+
/**
|
|
197
|
+
* An object contains the event handlers
|
|
198
|
+
*/
|
|
199
|
+
interface StreamTrackEventHandlers {
|
|
200
|
+
ended?: TrackEventCallback;
|
|
201
|
+
mute?: TrackEventCallback;
|
|
202
|
+
unmute?: TrackEventCallback;
|
|
203
|
+
}
|
|
204
|
+
interface InputDevicePermission {
|
|
205
|
+
audio: PermissionState;
|
|
206
|
+
video: PermissionState;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* DeviceChange Event
|
|
211
|
+
*
|
|
212
|
+
* ```
|
|
213
|
+
* devices (raw)
|
|
214
|
+
* |--- authorized
|
|
215
|
+
* | |--- found
|
|
216
|
+
* | |--- lost
|
|
217
|
+
* |--- unauthorized
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @beta
|
|
221
|
+
*/
|
|
222
|
+
type DeviceChangedChanges = {
|
|
223
|
+
authorized: MediaDeviceInfoLike[];
|
|
224
|
+
unauthorized: MediaDeviceInfoLike[];
|
|
225
|
+
found: MediaDeviceInfoLike[];
|
|
226
|
+
lost: MediaDeviceInfoLike[];
|
|
227
|
+
devices: MediaDeviceInfoLike[];
|
|
228
|
+
};
|
|
229
|
+
interface ToKeyOptions {
|
|
230
|
+
id: string;
|
|
231
|
+
kind: string;
|
|
232
|
+
label: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Convert provided info to key for Map
|
|
236
|
+
*
|
|
237
|
+
* @beta
|
|
238
|
+
*/
|
|
239
|
+
declare const toKey: ({ id, kind, label }: ToKeyOptions) => string;
|
|
240
|
+
/**
|
|
241
|
+
* Future proofing: in case we want to alter the values or type returned
|
|
242
|
+
* by {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices | enumerateDevices}
|
|
243
|
+
*
|
|
244
|
+
* @returns
|
|
245
|
+
* a list of currently available {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo | devices}
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```javascript
|
|
249
|
+
* import {getDevices} from "media-control";
|
|
250
|
+
*
|
|
251
|
+
* const devices = await getDevices();
|
|
252
|
+
* // return MediaDeviceInfo[]
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @beta
|
|
256
|
+
*/
|
|
257
|
+
declare const getDevices: () => Promise<MediaDeviceInfo[]>;
|
|
258
|
+
declare const createTrackDevicesChanges: (prevDevices?: MediaDeviceInfoLike[]) => (devices: MediaDeviceInfoLike[]) => {
|
|
259
|
+
unauthorized: MediaDeviceInfoLike[];
|
|
260
|
+
authorized: MediaDeviceInfoLike[];
|
|
261
|
+
found: MediaDeviceInfoLike[];
|
|
262
|
+
lost: MediaDeviceInfoLike[];
|
|
263
|
+
devices: MediaDeviceInfoLike[];
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Unified interface for subscribing {@link DeviceChangedChanges} Event
|
|
267
|
+
*
|
|
268
|
+
* @beta
|
|
269
|
+
*/
|
|
270
|
+
declare const deviceChanged: (fn: (event: DeviceChangedChanges) => void) => () => void;
|
|
271
|
+
/**
|
|
272
|
+
* Convert `MediaStreamTrack` to `MediaDeviceInfoLike`
|
|
273
|
+
*
|
|
274
|
+
* @beta
|
|
275
|
+
*/
|
|
276
|
+
declare const toMediaDeviceInfoLike: (track: MediaStreamTrack) => MediaDeviceInfoLike | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Find the MediaDeviceInfo from provided MediaDeviceInfo[] by comparing with
|
|
279
|
+
* provided MediaStreamTrack
|
|
280
|
+
*
|
|
281
|
+
* @param devices - A device list used for the searching
|
|
282
|
+
* @param track - A track for the searching criteria
|
|
283
|
+
*
|
|
284
|
+
* @returns `MediaDeviceInfo` if found, otherwise `undefined`
|
|
285
|
+
*
|
|
286
|
+
* @beta
|
|
287
|
+
*/
|
|
288
|
+
declare const findMediaInputFromMediaStreamTrack: (devices: MediaDeviceInfoLike[]) => (track?: MediaStreamTrack | undefined) => MediaDeviceInfoLike | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Find media input from media stream
|
|
291
|
+
*
|
|
292
|
+
* @param devices - A list of media devices from
|
|
293
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
294
|
+
* @param stream - A media stream used for the search criteria
|
|
295
|
+
*
|
|
296
|
+
* @returns A object may contains the devices
|
|
297
|
+
*
|
|
298
|
+
* @beta
|
|
299
|
+
*/
|
|
300
|
+
declare const findMediaInputFromStream: (devices: MediaDeviceInfoLike[]) => (stream: MediaStream | undefined) => MediaInput;
|
|
301
|
+
declare const isRequestedResolution: (request: InputDeviceConstraint | undefined, response: MediaDeviceInfoLike | undefined) => boolean;
|
|
302
|
+
declare const isRequestedInputDevice: (request: InputDeviceConstraint | undefined, response: MediaDeviceInfoLike | undefined) => boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Compare request and the input to see if the request has been fulfilled
|
|
305
|
+
*/
|
|
306
|
+
declare const isRequestedInputTrack: (request: InputDeviceConstraint | undefined, current: MediaStreamTrack | MediaDeviceInfoLike | undefined) => boolean;
|
|
307
|
+
declare const hasRequestingDevice: (request: InputDeviceConstraint | undefined, kind: MediaDeviceKind, currentDevices: MediaDeviceInfoLike[]) => boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Decide if we should send a new gUM request based on the inputs
|
|
310
|
+
*
|
|
311
|
+
* @param request - Requesting input device constraint
|
|
312
|
+
* @param tracks - The current media stream tracks
|
|
313
|
+
* @param currentDevices - The current list of device of the same kind of the
|
|
314
|
+
* request
|
|
315
|
+
*
|
|
316
|
+
* @returns `true` means the request should be conducted, otherwise `false`.
|
|
317
|
+
*/
|
|
318
|
+
declare const shouldRequestDevice: (request: InputDeviceConstraint | undefined, tracks: MediaStreamTrack[], currentDevices: MediaDeviceInfoLike[]) => boolean;
|
|
319
|
+
declare const isStreamingRequestedDevicesBase: (request: MediaDeviceRequest, tracksOrDevices: {
|
|
320
|
+
audio?: MediaDeviceInfoLike | MediaStreamTrack[];
|
|
321
|
+
video?: MediaDeviceInfoLike | MediaStreamTrack[];
|
|
322
|
+
}, devices: MediaDeviceInfoLike[]) => {
|
|
323
|
+
audio: boolean;
|
|
324
|
+
video: boolean;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Check if provided request has already been fulfilled
|
|
328
|
+
*
|
|
329
|
+
* @param request - A media request constraints
|
|
330
|
+
* @param stream - Current media stream
|
|
331
|
+
*
|
|
332
|
+
* @returns
|
|
333
|
+
* audio - The stream is using the same device as requested if `true`
|
|
334
|
+
* video - The stream is using the same device as requested if `true`
|
|
335
|
+
*/
|
|
336
|
+
declare const isStreamingRequestedDevices: (request: MediaDeviceRequest, stream: MediaStream | undefined, devices: MediaDeviceInfoLike[]) => {
|
|
337
|
+
audio: boolean;
|
|
338
|
+
video: boolean;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Find in the list of devices which has permissions granted
|
|
342
|
+
*
|
|
343
|
+
* From MDN:
|
|
344
|
+
* For security reasons,the label field is always blank unless an active media stream
|
|
345
|
+
* exists or the user has granted persistent permission for media device access.
|
|
346
|
+
*
|
|
347
|
+
* @param devices - A list of media devices from
|
|
348
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
349
|
+
*
|
|
350
|
+
* @returns List of devices that has permission granted
|
|
351
|
+
*
|
|
352
|
+
* @beta
|
|
353
|
+
*/
|
|
354
|
+
declare const findPermissionGrantedDevices: (devices: MediaDeviceInfoLike[]) => MediaDeviceInfoLike[];
|
|
355
|
+
/**
|
|
356
|
+
* A wrapper for `navigator.permissions.query` with fallback to use
|
|
357
|
+
* `navigator.mediaDevices.enumerateDevices` to guess the `PermissionState`
|
|
358
|
+
*
|
|
359
|
+
* @param anyActiveStream - Has ever got an active stream to help the fallback to
|
|
360
|
+
* guess the state more accurately
|
|
361
|
+
*/
|
|
362
|
+
declare const getInputDevicePermissionState: (anyActiveStream?: boolean) => Promise<InputDevicePermission>;
|
|
363
|
+
/**
|
|
364
|
+
* Find current audio output id to be used to set as sinkId
|
|
365
|
+
*
|
|
366
|
+
* If you set the stale deviceId to setSink it will throw exception.
|
|
367
|
+
* So we want to check if audio output id still exist.
|
|
368
|
+
*
|
|
369
|
+
* @param audioOutput - Audio output as `MediaDeviceInfo`
|
|
370
|
+
* @param devices - A list of media devices from
|
|
371
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
372
|
+
*
|
|
373
|
+
* @returns Audio output id or empty string if couldn't find it.
|
|
374
|
+
*
|
|
375
|
+
* @beta
|
|
376
|
+
*/
|
|
377
|
+
declare const findCurrentAudioOutputId: (audioOutput?: MediaDeviceInfoLike, devices?: MediaDeviceInfoLike[]) => string;
|
|
378
|
+
/**
|
|
379
|
+
* Find videoinput device id in the stream
|
|
380
|
+
*
|
|
381
|
+
* @param stream - Media stream to do the lookup
|
|
382
|
+
*
|
|
383
|
+
* @returns A object may contains the devices
|
|
384
|
+
*
|
|
385
|
+
* @beta
|
|
386
|
+
*/
|
|
387
|
+
declare const findCurrentVideoInputDeviceIdFromStream: (stream: MediaStream) => string | undefined;
|
|
388
|
+
/**
|
|
389
|
+
* Finds device with given deviceId
|
|
390
|
+
*
|
|
391
|
+
* @param devices - A list of media devices from
|
|
392
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
393
|
+
* @param deviceId - id that represents desired device
|
|
394
|
+
*
|
|
395
|
+
* @returns device with given deviceId
|
|
396
|
+
*
|
|
397
|
+
* @beta
|
|
398
|
+
*/
|
|
399
|
+
declare const findDeviceWithDeviceId: (devices: MediaDeviceInfoLike[], deviceId: string) => MediaDeviceInfoLike | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Find in the list of devices with given MediaDeviceKind
|
|
402
|
+
*
|
|
403
|
+
* @param devices - A list of media devices from
|
|
404
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
405
|
+
* @param kind - A list of media devices from
|
|
406
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
407
|
+
*
|
|
408
|
+
* @returns List of devices that have required MediaDeviceKind
|
|
409
|
+
*
|
|
410
|
+
* @beta
|
|
411
|
+
*/
|
|
412
|
+
declare const findDevicesByKind: (kind: MediaDeviceKind) => (devices: MediaDeviceInfoLike[]) => MediaDeviceInfoLike[];
|
|
413
|
+
/**
|
|
414
|
+
* Find in the list of devices only the audio input ones
|
|
415
|
+
*
|
|
416
|
+
* @param devices - A list of media devices from
|
|
417
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
418
|
+
*
|
|
419
|
+
* @returns List of devices that are audio inputs
|
|
420
|
+
*
|
|
421
|
+
* @beta
|
|
422
|
+
*/
|
|
423
|
+
declare const findAudioInputDevices: (devices: MediaDeviceInfoLike[]) => MediaDeviceInfoLike[];
|
|
424
|
+
/**
|
|
425
|
+
* Find in the list of devices only the video input ones
|
|
426
|
+
*
|
|
427
|
+
* @param devices - A list of media devices from
|
|
428
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
429
|
+
*
|
|
430
|
+
* @returns List of devices that are video inputs
|
|
431
|
+
*
|
|
432
|
+
* @beta
|
|
433
|
+
*/
|
|
434
|
+
declare const findVideoInputDevices: (devices: MediaDeviceInfoLike[]) => MediaDeviceInfoLike[];
|
|
435
|
+
/**
|
|
436
|
+
* Find in the list of devices only the audio output ones
|
|
437
|
+
*
|
|
438
|
+
* @param devices - A list of media devices from
|
|
439
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
440
|
+
*
|
|
441
|
+
* @returns List of devices that are audio outputs
|
|
442
|
+
*
|
|
443
|
+
* @beta
|
|
444
|
+
*/
|
|
445
|
+
declare const findAudioOutputDevices: (devices: MediaDeviceInfoLike[]) => MediaDeviceInfoLike[];
|
|
446
|
+
/**
|
|
447
|
+
* Set `MediaStreamTrack['enabled']` according to `mute` param for the provided `stream`
|
|
448
|
+
*
|
|
449
|
+
* @param stream - Media stream
|
|
450
|
+
* @param mute - disable or enable the audio stream
|
|
451
|
+
* @param mediaType - Can either be 'audio', 'video' or 'all'
|
|
452
|
+
* @defaultValue
|
|
453
|
+
* 'all'
|
|
454
|
+
*
|
|
455
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/enabled
|
|
456
|
+
*
|
|
457
|
+
* @beta
|
|
458
|
+
*/
|
|
459
|
+
declare const muteStreamTrack: (stream?: MediaStream) => (mute: boolean, mediaType?: 'audio' | 'video' | 'all') => void;
|
|
460
|
+
/**
|
|
461
|
+
* Stops all tracks in the given stream
|
|
462
|
+
*
|
|
463
|
+
* Immediately after calling stop(), the readyState property is set to `ended`.
|
|
464
|
+
* Note that the `ended` event will not be fired in this situation
|
|
465
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/stop#description
|
|
466
|
+
*
|
|
467
|
+
* @param stream - `MediaStream` which we mutate
|
|
468
|
+
* @param onStopped - callback to be called when the track is stopped
|
|
469
|
+
*/
|
|
470
|
+
declare const stopMediaStream: (stream: MediaStream | undefined, onStopped?: ((track: MediaStreamTrack) => void) | undefined) => void;
|
|
471
|
+
/**
|
|
472
|
+
* Checks that tracks with a given type are enabled in the stream
|
|
473
|
+
*
|
|
474
|
+
* @param stream - `MediaStream` used for comparison
|
|
475
|
+
* @param type - `MediaInput` used for comparison
|
|
476
|
+
*
|
|
477
|
+
* @returns Return true when all the tracks are enabled false otherwise
|
|
478
|
+
*
|
|
479
|
+
* @beta
|
|
480
|
+
*/
|
|
481
|
+
declare const areTracksEnabled: (stream: MediaStream | undefined, type: 'audio' | 'video') => boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Check if list contains media inputs
|
|
484
|
+
*
|
|
485
|
+
* @param devices - A list of media devices from
|
|
486
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
487
|
+
*
|
|
488
|
+
* @returns True when some media inputs false otherwise
|
|
489
|
+
*
|
|
490
|
+
* @beta
|
|
491
|
+
*/
|
|
492
|
+
declare const hasAudioOrVideoInputs: (devices: MediaDeviceInfoLike[]) => boolean;
|
|
493
|
+
/**
|
|
494
|
+
* Check if list contains audio inputs
|
|
495
|
+
*
|
|
496
|
+
* @param devices - A list of media devices from
|
|
497
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
498
|
+
*
|
|
499
|
+
* @returns True when some audio inputs false otherwise
|
|
500
|
+
*
|
|
501
|
+
* @beta
|
|
502
|
+
*/
|
|
503
|
+
declare const hasAudioInputs: (devices: MediaDeviceInfoLike[]) => boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Check if list contains video inputs
|
|
506
|
+
*
|
|
507
|
+
* @param devices - A list of media devices from
|
|
508
|
+
* `navigator.mediaDevices.enumerateDevices()`. Will be used for search target
|
|
509
|
+
*
|
|
510
|
+
* @returns True when some video inputs false otherwise
|
|
511
|
+
*
|
|
512
|
+
* @beta
|
|
513
|
+
*/
|
|
514
|
+
declare const hasVideoInputs: (devices: MediaDeviceInfoLike[]) => boolean;
|
|
515
|
+
/**
|
|
516
|
+
* Check if provided devices have any granted input device
|
|
517
|
+
*
|
|
518
|
+
* @param devices - The devices to check
|
|
519
|
+
*/
|
|
520
|
+
declare const hasAnyGrantedInput: (devices: MediaDeviceInfoLike[]) => boolean;
|
|
521
|
+
/**
|
|
522
|
+
* Check if provided devices have any video and audio inputs
|
|
523
|
+
*
|
|
524
|
+
* @param devices - The devices to lookup
|
|
525
|
+
* @param grantedOnly - When it is `true`, the device label is also taken into
|
|
526
|
+
* consideration
|
|
527
|
+
* @defaultValue `false`
|
|
528
|
+
*
|
|
529
|
+
* @returns A tuple of `[anyAudioInput, anyVideoInput]`, e.g. `[true, false]`
|
|
530
|
+
* means there is audio input but no video input
|
|
531
|
+
*/
|
|
532
|
+
declare const hasAnyInputs: (devices: MediaDeviceInfoLike[], grantedOnly?: boolean) => [boolean, boolean];
|
|
533
|
+
/**
|
|
534
|
+
* An utility function to check the input device has been changed
|
|
535
|
+
*
|
|
536
|
+
* @param oldInput - The previous input device
|
|
537
|
+
* @param newInput - The current input device
|
|
538
|
+
*/
|
|
539
|
+
declare const hasChangedInput: (oldInput: MediaDeviceInfoLike | undefined, newInput: MediaDeviceInfoLike | undefined) => boolean;
|
|
540
|
+
/**
|
|
541
|
+
* An utility function to check if facing mode is supported by interpreting the
|
|
542
|
+
* device label and the API `getSupportedConstraints`
|
|
543
|
+
*
|
|
544
|
+
* @remarks
|
|
545
|
+
* Only support snooping the label for English
|
|
546
|
+
*
|
|
547
|
+
* @param currentDevices - Current list of devices available
|
|
548
|
+
* @param getSupportedConstraints - A function to get supported constraints,
|
|
549
|
+
* i.e. `navigator.mediaDevices.getSupportedConstraints()`
|
|
550
|
+
* @param tracks - Current video input track
|
|
551
|
+
*/
|
|
552
|
+
declare const areMultipleFacingModeSupportted: (currentDevices: MediaDeviceInfoLike[], getSupportedConstraints?: () => MediaTrackSupportedConstraints) => boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Interpret the current facing mode from the provided track, and try to get the
|
|
555
|
+
* mode from settings, or use the label to guess the facing mode when facingMode
|
|
556
|
+
* is not supported from settings
|
|
557
|
+
*
|
|
558
|
+
* @param currentTrack - The current video input track
|
|
559
|
+
*/
|
|
560
|
+
declare const interpretCurrentFacingMode: (currentTrack: MediaStreamTrack | undefined) => FacingMode | undefined;
|
|
561
|
+
|
|
562
|
+
declare const isAudioInput: (device: MediaDeviceInfoLike) => boolean;
|
|
563
|
+
declare const isVideoInput: (device: MediaDeviceInfoLike) => boolean;
|
|
564
|
+
declare const isAudioOutput: (device: MediaDeviceInfoLike) => boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Check if provided device is a permission-granted device by inspecting the
|
|
567
|
+
* device label
|
|
568
|
+
*
|
|
569
|
+
* @param device - The device to check
|
|
570
|
+
*
|
|
571
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/label#value}
|
|
572
|
+
**/
|
|
573
|
+
declare const isDeviceGranted: (device: MediaDeviceInfoLike) => boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Compare 2 devices to see if they are the same by `deviceId` or `label` as
|
|
576
|
+
* a fallback
|
|
577
|
+
*
|
|
578
|
+
* @beta
|
|
579
|
+
*/
|
|
580
|
+
declare const compareDevices: (deviceInfo: MediaDeviceInfoLike, key?: Exclude<keyof MediaDeviceInfoLike, 'kind' | 'settings'>) => (anotherDeviceInfo: MediaDeviceInfoLike) => boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Lookup the the `device` from `devices` list
|
|
583
|
+
*
|
|
584
|
+
* @remarks
|
|
585
|
+
* When we cannot find the device by `deviceId`, we compare the label as last
|
|
586
|
+
* resort, and return the first one.
|
|
587
|
+
*
|
|
588
|
+
* @param deviceToFind - Provide a device info to be used for the searching
|
|
589
|
+
* @param useFallback - Whether to use `label` as a fallback when there is no
|
|
590
|
+
* match from using `deviceId`
|
|
591
|
+
*
|
|
592
|
+
* @beta
|
|
593
|
+
*/
|
|
594
|
+
declare const findDevice: (deviceToFind: MediaDeviceInfoLike, useFallback?: boolean) => (devices: readonly MediaDeviceInfoLike[]) => MediaDeviceInfoLike | undefined;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Reference https://w3c.github.io/mediacapture-main/#dom-mediatrackconstraintset
|
|
598
|
+
*/
|
|
599
|
+
declare const CONSTRAIN_STRING_KEYS: readonly ["facingMode", "resizeMode", "deviceId", "groupId"];
|
|
600
|
+
declare const EXTENDED_CONSTRAIN_STRING_KEYS: readonly ["videoSegmentation", "videoSegmentationModel", "bgImageUrl"];
|
|
601
|
+
type ExtendedConstrainStringKeys = (typeof EXTENDED_CONSTRAIN_STRING_KEYS)[number];
|
|
602
|
+
type ConstrainStringKeys = (typeof CONSTRAIN_STRING_KEYS)[number];
|
|
603
|
+
declare const CONSTRAIN_U_LONG_KEYS: readonly ["width", "height", "sampleRate", "sampleSize", "channelCount"];
|
|
604
|
+
declare const EXTENDED_CONSTRAIN_U_LONG_KEYS: readonly ["backgroundBlurAmount", "edgeBlurAmount"];
|
|
605
|
+
type ExtendedConstrainULongKeys = (typeof EXTENDED_CONSTRAIN_U_LONG_KEYS)[number];
|
|
606
|
+
type ConstrainULongKeys = (typeof CONSTRAIN_U_LONG_KEYS)[number];
|
|
607
|
+
declare const CONSTRAIN_DOUBLE_KEYS: readonly ["aspectRatio", "frameRate", "latency"];
|
|
608
|
+
declare const EXTENDED_CONSTRAIN_DOUBLE_KEYS: readonly ["foregroundThreshold"];
|
|
609
|
+
type ExtendedConstrainDoubleKeys = (typeof EXTENDED_CONSTRAIN_DOUBLE_KEYS)[number];
|
|
610
|
+
type ConstrainDoubleKeys = (typeof CONSTRAIN_DOUBLE_KEYS)[number];
|
|
611
|
+
declare const CONSTRAIN_BOOLEAN_KEYS: readonly ["echoCancellation", "autoGainControl", "noiseSuppression"];
|
|
612
|
+
/**
|
|
613
|
+
* Extends boolean constraint keys for our own implementation of the media
|
|
614
|
+
* feature
|
|
615
|
+
*/
|
|
616
|
+
declare const EXTENDED_CONSTRAIN_BOOLEAN_KEYS: readonly ["vad", "asd", "mixWithAdditionalMedia", "denoise", "flipHorizontal"];
|
|
617
|
+
type ExtendedConstrainBooleanKeys = (typeof EXTENDED_CONSTRAIN_BOOLEAN_KEYS)[number];
|
|
618
|
+
type ConstrainBooleanKeys = (typeof CONSTRAIN_BOOLEAN_KEYS)[number];
|
|
619
|
+
/**
|
|
620
|
+
* Check if provided is `MediaDeviceInfo`
|
|
621
|
+
*
|
|
622
|
+
* @beta
|
|
623
|
+
*/
|
|
624
|
+
declare const isMediaDeviceInfo: (t: unknown) => t is MediaDeviceInfo;
|
|
625
|
+
declare const isMediaDeviceInfoArray: (t: unknown) => t is MediaDeviceInfo[];
|
|
626
|
+
declare const CONSTRAIN_PARAM_KEYS: readonly ["exact", "ideal"];
|
|
627
|
+
type ConstrainParamKeys = (typeof CONSTRAIN_PARAM_KEYS)[number];
|
|
628
|
+
declare const CONSTRAIN_RANGE_KEYS: readonly ["min", "max"];
|
|
629
|
+
type ConstrainRangeKeys = (typeof CONSTRAIN_RANGE_KEYS)[number];
|
|
630
|
+
type ConstrainRangeParamKeys = ConstrainParamKeys | ConstrainRangeKeys;
|
|
631
|
+
/**
|
|
632
|
+
* Check if provided is `MediaStreamTrack`
|
|
633
|
+
*
|
|
634
|
+
* @beta
|
|
635
|
+
*/
|
|
636
|
+
declare const isMediaStreamTrack: (m: unknown) => m is MediaStreamTrack;
|
|
637
|
+
declare const isFacingMode: (s: unknown) => s is "user" | "environment" | "left" | "right";
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Check if provided constraint is an `exact` device constraint
|
|
641
|
+
*/
|
|
642
|
+
declare const isExactDeviceConstraint: (constraint: InputDeviceConstraint | undefined) => boolean;
|
|
643
|
+
/**
|
|
644
|
+
* Merge base constraints with provided base constraints and another constraints
|
|
645
|
+
*/
|
|
646
|
+
declare const mergeConstraints: (baseConstraints: InputConstraintSet | boolean | undefined) => (constraints: InputDeviceConstraint | undefined) => InputConstraintSet | boolean;
|
|
647
|
+
type ConstrainNoneTuple = [undefined, 'ideal'];
|
|
648
|
+
type ConstrainStringTuple = [string[], ConstrainParamKeys];
|
|
649
|
+
type ConstrainBooleanTuple = [boolean, ConstrainParamKeys];
|
|
650
|
+
type ConstrainNumber = number | Partial<Record<ConstrainRangeParamKeys, number>>;
|
|
651
|
+
type ConstrainNumberTuple = [
|
|
652
|
+
ConstrainNumber,
|
|
653
|
+
ConstrainParamKeys | 'min-max'
|
|
654
|
+
];
|
|
655
|
+
type ConstrainDeviceTuple = [MediaDeviceInfoLike[], ConstrainParamKeys];
|
|
656
|
+
declare const getValueFromConstrainNumber: (constraint: ConstrainNumber) => number;
|
|
657
|
+
declare const getFacingModeFromConstraintString: (constraint: string) => FacingMode | undefined;
|
|
658
|
+
/**
|
|
659
|
+
* Call applyConstraints foreach track accordingly
|
|
660
|
+
*
|
|
661
|
+
* @param tracks - Tracks to be applied
|
|
662
|
+
* @param constraints - constraints to be applied
|
|
663
|
+
*/
|
|
664
|
+
declare const applyConstraints: (tracks: MediaStreamTrack[] | undefined, constraints: MediaDeviceRequest) => Promise<void>;
|
|
665
|
+
type ConstrainNumberKeys = ConstrainULongKeys | ConstrainDoubleKeys | ExtendedConstrainDoubleKeys | ExtendedConstrainULongKeys;
|
|
666
|
+
type ConstrainStrings = Record<ConstrainStringKeys | ExtendedConstrainStringKeys, ConstrainStringTuple | ConstrainNoneTuple>;
|
|
667
|
+
type ConstrainNumbers = Record<ConstrainNumberKeys, ConstrainNumberTuple | ConstrainNoneTuple>;
|
|
668
|
+
type ConstrainBooleans = Record<ConstrainBooleanKeys | ExtendedConstrainBooleanKeys, ConstrainBooleanTuple | ConstrainNoneTuple>;
|
|
669
|
+
type ConstrainDevices = Record<'device', ConstrainDeviceTuple | ConstrainNoneTuple>;
|
|
670
|
+
type Constraints = ConstrainStrings & ConstrainNumbers & ConstrainBooleans & ConstrainDevices;
|
|
671
|
+
/**
|
|
672
|
+
* Extract the constraints with provided keys
|
|
673
|
+
*
|
|
674
|
+
* @param keys - The keys to be used for the extraction
|
|
675
|
+
* @param constraints - The constraints to be used for the extraction
|
|
676
|
+
*
|
|
677
|
+
* @returns an object with the provided key and the value-param tuple
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
*
|
|
681
|
+
* ```typescript
|
|
682
|
+
* const device = {deviceId: 'xxxx', label: 'abc', kind: 'audioinput'};
|
|
683
|
+
* const constraints = { device, noiseSuppression: true };
|
|
684
|
+
* const extract = extractConstraintsWithKeys(['device', 'noiseSuppression']);
|
|
685
|
+
* const {
|
|
686
|
+
* device: [devices, deviceParam],
|
|
687
|
+
* noiseSuppression: [noiseSuppression, noiseSuppressionParam],
|
|
688
|
+
* } = extract(constraints);
|
|
689
|
+
* expect(devices).toEqual([device]);
|
|
690
|
+
* expect(deviceParam).toEqual('ideal');
|
|
691
|
+
* expect(noiseSuppression).toEqual(true);
|
|
692
|
+
* expect(noiseSuppressionParam).toEqual('ideal');
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
declare const extractConstraintsWithKeys: <T extends "deviceId" | "groupId" | "facingMode" | "resizeMode" | "videoSegmentation" | "videoSegmentationModel" | "bgImageUrl" | ConstrainNumberKeys | "echoCancellation" | "autoGainControl" | "noiseSuppression" | "vad" | "asd" | "mixWithAdditionalMedia" | "denoise" | "flipHorizontal" | "device">(keys: T[]) => (constraints: InputDeviceConstraint | undefined) => Pick<Constraints, T>;
|
|
696
|
+
/**
|
|
697
|
+
* Find device from the device list with provided constraints
|
|
698
|
+
*
|
|
699
|
+
* @param constraints - The constraints to be used for the lookup
|
|
700
|
+
* @param devices - The devices to be used for the lookup
|
|
701
|
+
*
|
|
702
|
+
* @returns `true` means it can be any devices, `undefined` means not found,
|
|
703
|
+
* otherwise, the matched device will be returned
|
|
704
|
+
*/
|
|
705
|
+
declare const findDeviceFromConstraints: (constraints: InputDeviceConstraint | undefined, devices: MediaDeviceInfoLike[]) => boolean | MediaDeviceInfoLike | undefined;
|
|
706
|
+
/**
|
|
707
|
+
* Relax input constraints to enable looking up the device by `deviceId` as well
|
|
708
|
+
* as `label` as a fallback as a best effort to get a similar device when
|
|
709
|
+
* possible.
|
|
710
|
+
*
|
|
711
|
+
* @param input - The input constraints to be relaxed
|
|
712
|
+
* @param devices - The current device list
|
|
713
|
+
*/
|
|
714
|
+
declare const relaxInputConstraint: (input: InputDeviceConstraint | undefined, devices: MediaDeviceInfoLike[]) => InputDeviceConstraint | undefined;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* MediaStreamTrack Events
|
|
718
|
+
*
|
|
719
|
+
* @remarks
|
|
720
|
+
* See MDN {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack#Events | Events}
|
|
721
|
+
*
|
|
722
|
+
* @beta
|
|
723
|
+
*/
|
|
724
|
+
declare enum MediaEventType {
|
|
725
|
+
/**
|
|
726
|
+
* Sent to the MediaStreamTrack when the value of the muted property is
|
|
727
|
+
* changed to true, indicating that the track is unable to provide data
|
|
728
|
+
* temporarily (such as when the network is experiencing a service
|
|
729
|
+
* malfunction).
|
|
730
|
+
*/
|
|
731
|
+
Mute = "mute",
|
|
732
|
+
/**
|
|
733
|
+
* Sent to the track when data becomes available again, ending the muted state.
|
|
734
|
+
*/
|
|
735
|
+
Unmute = "unmute",
|
|
736
|
+
/**
|
|
737
|
+
* Sent when playback of the track ends (when the value readyState changes to
|
|
738
|
+
* ended).
|
|
739
|
+
*/
|
|
740
|
+
Ended = "ended",
|
|
741
|
+
/**
|
|
742
|
+
* Fired when a media input or output device is attached to or removed from
|
|
743
|
+
* the user's computer.
|
|
744
|
+
*
|
|
745
|
+
* @remarks
|
|
746
|
+
* See MDN {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices#Events | Events}
|
|
747
|
+
*/
|
|
748
|
+
DevicesChanged = "devices:changed",
|
|
749
|
+
/**
|
|
750
|
+
* Found new devices from authorized device list
|
|
751
|
+
*/
|
|
752
|
+
DevicesFound = "devices:found",
|
|
753
|
+
/**
|
|
754
|
+
* Lost devices from authorized device list
|
|
755
|
+
*/
|
|
756
|
+
DevicesLost = "devices:lost",
|
|
757
|
+
/**
|
|
758
|
+
* Lost device from authorized device list
|
|
759
|
+
*/
|
|
760
|
+
DeviceLost = "device:lost",
|
|
761
|
+
/**
|
|
762
|
+
* Unauthorized devices
|
|
763
|
+
*/
|
|
764
|
+
DevicesUnauthorized = "devices:unauthorized",
|
|
765
|
+
/**
|
|
766
|
+
* No Input Devices, and no further device events will be emitted
|
|
767
|
+
*/
|
|
768
|
+
NoInputDevices = "devices:noinput",
|
|
769
|
+
/**
|
|
770
|
+
* Other errors
|
|
771
|
+
*/
|
|
772
|
+
Error = "error",
|
|
773
|
+
/**
|
|
774
|
+
* When stream
|
|
775
|
+
*/
|
|
776
|
+
Stream = "stream"
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Event object by MediaEventType
|
|
780
|
+
*
|
|
781
|
+
* @beta
|
|
782
|
+
*/
|
|
783
|
+
type Events = {
|
|
784
|
+
id: string;
|
|
785
|
+
type: MediaEventType.Mute;
|
|
786
|
+
} | {
|
|
787
|
+
id: string;
|
|
788
|
+
type: MediaEventType.Unmute;
|
|
789
|
+
} | {
|
|
790
|
+
id: string;
|
|
791
|
+
type: MediaEventType.Ended;
|
|
792
|
+
} | {
|
|
793
|
+
devices: MediaDeviceInfoLike[];
|
|
794
|
+
type: MediaEventType.DevicesChanged;
|
|
795
|
+
} | {
|
|
796
|
+
devices: MediaDeviceInfoLike[];
|
|
797
|
+
authorizedDevices: MediaDeviceInfoLike[];
|
|
798
|
+
unauthorizedDevices: MediaDeviceInfoLike[];
|
|
799
|
+
type: MediaEventType.DevicesFound;
|
|
800
|
+
} | {
|
|
801
|
+
devices: MediaDeviceInfoLike[];
|
|
802
|
+
authorizedDevices: MediaDeviceInfoLike[];
|
|
803
|
+
unauthorizedDevices: MediaDeviceInfoLike[];
|
|
804
|
+
type: MediaEventType.DevicesLost;
|
|
805
|
+
} | {
|
|
806
|
+
devices: MediaDeviceInfoLike[];
|
|
807
|
+
authorizedDevices: MediaDeviceInfoLike[];
|
|
808
|
+
type: MediaEventType.DevicesUnauthorized;
|
|
809
|
+
} | {
|
|
810
|
+
devices: MediaDeviceInfoLike[];
|
|
811
|
+
type: MediaEventType.NoInputDevices;
|
|
812
|
+
} | {
|
|
813
|
+
device: MediaDeviceInfoLike;
|
|
814
|
+
type: MediaEventType.DeviceLost;
|
|
815
|
+
} | {
|
|
816
|
+
error: Error;
|
|
817
|
+
type: MediaEventType.Error;
|
|
818
|
+
} | {
|
|
819
|
+
facingMode: boolean;
|
|
820
|
+
stream: MediaStream;
|
|
821
|
+
type: MediaEventType.Stream;
|
|
822
|
+
video: boolean;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Custom Media Event
|
|
826
|
+
* @beta
|
|
827
|
+
*/
|
|
828
|
+
type MediaEvent = CustomEvent<Events>;
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Create a MediaStreamTrack's native events subscription
|
|
832
|
+
*
|
|
833
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack#events
|
|
834
|
+
*
|
|
835
|
+
* @param track - The track used for the subscription
|
|
836
|
+
* @param handlers - An object contains the event handlers
|
|
837
|
+
*/
|
|
838
|
+
declare const createStreamTrackEventSubscriptions: (track: MediaStreamTrack, handlers: StreamTrackEventHandlers) => Unsubscribe;
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Log meta and message with respective log level
|
|
842
|
+
*/
|
|
843
|
+
type LogMethod = (meta: unknown, message?: string) => void;
|
|
844
|
+
declare enum LogLevels {
|
|
845
|
+
trace = 10,
|
|
846
|
+
debug = 20,
|
|
847
|
+
info = 30,
|
|
848
|
+
warn = 40,
|
|
849
|
+
error = 50,
|
|
850
|
+
fatal = 60,
|
|
851
|
+
silent
|
|
852
|
+
}
|
|
853
|
+
type LogLevelsString = keyof typeof LogLevels;
|
|
854
|
+
type LogMethods = {
|
|
855
|
+
[key in LogLevelsString]: LogMethod;
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* Log Level from high to low, "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
|
859
|
+
* Typically, debug and trace logs are only valid for development, and not needed in production
|
|
860
|
+
*/
|
|
861
|
+
interface Logger extends LogMethods {
|
|
862
|
+
/**
|
|
863
|
+
* Adds a value to the redaction set, which makes it replaced by [REDACTED] when logged to file.
|
|
864
|
+
*
|
|
865
|
+
* @remarks
|
|
866
|
+
* The redaction set is applied globally, and only applies to the log file, not console logs.
|
|
867
|
+
*
|
|
868
|
+
* @param value - the string to redact
|
|
869
|
+
*/
|
|
870
|
+
redact(value: string): void;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
declare function setLogger(newLogger: Logger): void;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* media-control is meant to extend the mediaDevices api methods such as
|
|
877
|
+
* `getUserMedia`, `enumerateDevices` and events on media streams and tracks.
|
|
878
|
+
* The final goal is to have a library that gives a stable and robust way to use
|
|
879
|
+
* these methods while guaranteeing that the developer has better control over
|
|
880
|
+
* which devices are delivered, fail, or exist.
|
|
881
|
+
*
|
|
882
|
+
* @packageDocumentation
|
|
883
|
+
*/
|
|
884
|
+
|
|
885
|
+
declare const
|
|
886
|
+
/**
|
|
887
|
+
* Get MediaStream with provided {@link MediaDeviceRequest | input constraints}
|
|
888
|
+
*/
|
|
889
|
+
getUserMedia: ({ audio, video, }: MediaDeviceRequest) => Promise<MediaStream>;
|
|
890
|
+
declare const /**
|
|
891
|
+
* Set default media stream constraints
|
|
892
|
+
*
|
|
893
|
+
* A {@link
|
|
894
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints |
|
|
895
|
+
* MediaStreamConstraints} object specifying the types of media to request, along with any requirements for each type.
|
|
896
|
+
*/
|
|
897
|
+
setDefaultConstraints: (newConstraints: MediaStreamConstraints) => void;
|
|
898
|
+
declare const /**
|
|
899
|
+
* Subscribe media events
|
|
900
|
+
*/
|
|
901
|
+
subscribe: (listener: (event: MediaEvent) => void) => () => void;
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* MediaControl Interface
|
|
905
|
+
*
|
|
906
|
+
* @beta
|
|
907
|
+
*/
|
|
908
|
+
interface MediaControl {
|
|
909
|
+
/** {@inheritDoc deviceChanged} */
|
|
910
|
+
deviceChanged: typeof deviceChanged;
|
|
911
|
+
/** {@inheritDoc getDevices} */
|
|
912
|
+
getDevices: typeof getDevices;
|
|
913
|
+
/** {@inheritDoc MediaEventType} */
|
|
914
|
+
MediaEventType: typeof MediaEventType;
|
|
915
|
+
/** {@inheritDoc getUserMedia} */
|
|
916
|
+
getUserMedia: typeof getUserMedia;
|
|
917
|
+
/** {@inheritDoc setDefaultConstraints} */
|
|
918
|
+
setDefaultConstraints: typeof setDefaultConstraints;
|
|
919
|
+
/** {@inheritDoc subscribe} */
|
|
920
|
+
subscribe: typeof subscribe;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export { DeviceChangedChanges, Events, FacingMode, InputConstraintSet, InputDevicePermission, MediaControl, MediaDeviceFailure, MediaDeviceInfoLike, MediaDeviceKinds, MediaDeviceRequest, MediaEvent, MediaEventType, MediaInput, MediaStreamTrackLike, StreamTrackEventHandlers, Unsubscribe, applyConstraints, areMultipleFacingModeSupportted, areTracksEnabled, compareDevices, createStreamTrackEventSubscriptions, createTrackDevicesChanges, deviceChanged, extractConstraintsWithKeys, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDevice, findDeviceFromConstraints, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDevices, getFacingModeFromConstraintString, getInputDevicePermissionState, getUserMedia, getValueFromConstrainNumber, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isAudioInput, isAudioOutput, isDeviceGranted, isExactDeviceConstraint, isFacingMode, isMediaDeviceInfo, isMediaDeviceInfoArray, isMediaStreamTrack, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isVideoInput, mergeConstraints, muteStreamTrack, relaxInputConstraint, setDefaultConstraints, setLogger, shouldRequestDevice, stopMediaStream, subscribe, toKey, toMediaDeviceInfoLike };
|