@pexip/media-control 21.0.0 → 22.1.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api-docs/README.mdx +1 -0
  3. package/api-docs/functions/applyConstraints.mdx +2 -2
  4. package/api-docs/functions/areMultipleFacingModeSupported.mdx +1 -1
  5. package/api-docs/functions/areTracksEnabled.mdx +2 -2
  6. package/api-docs/functions/compareDevices.mdx +1 -1
  7. package/api-docs/functions/createTrackDevicesChanges.mdx +1 -1
  8. package/api-docs/functions/deviceChanged.mdx +1 -1
  9. package/api-docs/functions/extractConstrainDevice.mdx +4 -2
  10. package/api-docs/functions/extractConstraints.mdx +87 -0
  11. package/api-docs/functions/extractConstraintsWithKeys.mdx +3 -3
  12. package/api-docs/functions/findCurrentVideoInputDeviceIdFromStream.mdx +3 -1
  13. package/api-docs/functions/findDevice.mdx +6 -2
  14. package/api-docs/functions/findDeviceFromConstraints.mdx +9 -3
  15. package/api-docs/functions/findDeviceWithDeviceId.mdx +6 -2
  16. package/api-docs/functions/findMediaInputFromMediaStreamTrack.mdx +6 -2
  17. package/api-docs/functions/findMediaInputFromStream.mdx +1 -1
  18. package/api-docs/functions/getDevices.mdx +3 -1
  19. package/api-docs/functions/getFacingModeFromConstraintString.mdx +3 -1
  20. package/api-docs/functions/getInputDevicePermissionState.mdx +4 -2
  21. package/api-docs/functions/hasAnyInputs.mdx +3 -1
  22. package/api-docs/functions/interpretCurrentFacingMode.mdx +4 -2
  23. package/api-docs/functions/isRequestedResolution.mdx +1 -1
  24. package/api-docs/functions/isStreamingRequestedDevices.mdx +1 -1
  25. package/api-docs/functions/isStreamingRequestedDevicesBase.mdx +3 -3
  26. package/api-docs/functions/isStreamingRequestingDevice.mdx +1 -1
  27. package/api-docs/functions/mergeConstraints.mdx +9 -3
  28. package/api-docs/functions/muteStreamTrack.mdx +1 -1
  29. package/api-docs/functions/relaxInputConstraint.mdx +7 -3
  30. package/api-docs/functions/resolveMediaDeviceConstraints.mdx +4 -2
  31. package/api-docs/functions/stopMediaStream.mdx +2 -2
  32. package/api-docs/functions/toKey.mdx +3 -3
  33. package/api-docs/functions/toMediaDeviceInfoLike.mdx +6 -2
  34. package/api-docs/functions/toMediaDeviceInputKind.mdx +4 -2
  35. package/api-docs/interfaces/DisplayMediaOptions.mdx +2 -2
  36. package/api-docs/interfaces/IndexedDevices.mdx +9 -3
  37. package/api-docs/interfaces/InputConstraintSet.mdx +4 -7
  38. package/api-docs/interfaces/MediaControl.mdx +5 -5
  39. package/api-docs/type-aliases/MediaDeviceInfoLike.mdx +1 -1
  40. package/api-docs/variables/getUserMedia.mdx +1 -1
  41. package/api-docs/variables/subscribe.mdx +1 -1
  42. package/dist/constraints.js +0 -1
  43. package/dist/devices.d.ts +6 -4
  44. package/dist/devices.js +0 -2
  45. package/dist/index.d.ts +2 -2
  46. package/dist/index.js +2 -2
  47. package/dist/streamTrackMap.d.ts +3 -2
  48. package/dist/streamTrackMap.js +66 -15
  49. package/dist/typeGuards.d.ts +3 -3
  50. package/dist/typeGuards.js +1 -6
  51. package/dist/types.d.ts +0 -5
  52. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 22.1.0
4
+
5
+ ### Patch Changes
6
+
7
+ - a9456de: Increase performance when tracking tracks and device changes.
8
+ - Updated dependencies [44ad859]
9
+ - Updated dependencies [514c523]
10
+ - @pexip/utils@17.4.0
11
+
12
+ ## 22.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - 498ff3b: - **`extractConstraints` newly exported**
17
+ - **`videoSegmentationModel`** removed from `EXTENDED_CONSTRAIN_STRING_KEYS`
18
+ and `InputConstraintSet`.
19
+
20
+ ### Patch Changes
21
+
22
+ - fb41d4d: Changes related to Typescript V6 Upgrade
23
+ - Updated dependencies [498ff3b]
24
+ - Updated dependencies [fb41d4d]
25
+ - Updated dependencies [b99c070]
26
+ - @pexip/utils@17.3.0
27
+
3
28
  ## 21.0.0
4
29
 
5
30
  ### Minor Changes
@@ -319,6 +319,7 @@ which devices are delivered, fail, or exist.
319
319
  | [getFacingModeFromConstraintString](functions/getFacingModeFromConstraintString.mdx) | - |
320
320
  | [resolveMediaDeviceConstraints](functions/resolveMediaDeviceConstraints.mdx) | Resolve *constraints* and mediaTrackConstraints by checking the type and try to return the best possible from mediaTrackConstraints. |
321
321
  | [applyConstraints](functions/applyConstraints.mdx) | Call applyConstraints foreach track accordingly |
322
+ | [extractConstraints](functions/extractConstraints.mdx) | - |
322
323
  | [extractConstraintsWithKeys](functions/extractConstraintsWithKeys.mdx) | Extract the constraints with provided keys |
323
324
  | [findDeviceFromConstraints](functions/findDeviceFromConstraints.mdx) | Find device from the device list with provided constraints |
324
325
  | [relaxInputConstraint](functions/relaxInputConstraint.mdx) | Relax input constraints to enable looking up the device by `deviceId` as well as `label` as a fallback as a best effort to get a similar device when possible. If the the device is found we will use the `exact` constraint otherwise we will use the `ideal`. |
@@ -8,9 +8,9 @@ Call applyConstraints foreach track accordingly
8
8
 
9
9
  | Parameter | Type | Description |
10
10
  | ------ | ------ | ------ |
11
- | `tracks` | `MediaStreamTrack`[] \| `undefined` | Tracks to be applied |
11
+ | `tracks` | `MediaStreamTrack[] \| undefined` | Tracks to be applied |
12
12
  | `constraints` | [`MediaDeviceRequest`](../interfaces/MediaDeviceRequest.mdx) | constraints to be applied |
13
13
 
14
14
  ## Returns
15
15
 
16
- `Promise`\<`void`\>
16
+ `Promise<void>`
@@ -10,7 +10,7 @@ device label and the API `getSupportedConstraints`
10
10
  | Parameter | Type | Description |
11
11
  | ------ | ------ | ------ |
12
12
  | `currentDevices` | [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)[] | Current list of devices available |
13
- | `getSupportedConstraints` | () => `MediaTrackSupportedConstraints` | A function to get supported constraints, i.e. `navigator.mediaDevices.getSupportedConstraints()` |
13
+ | `getSupportedConstraints` | `() => MediaTrackSupportedConstraints` | A function to get supported constraints, i.e. `navigator.mediaDevices.getSupportedConstraints()` |
14
14
 
15
15
  ## Returns
16
16
 
@@ -8,8 +8,8 @@ function areTracksEnabled(stream, type): boolean;
8
8
 
9
9
  | Parameter | Type |
10
10
  | ------ | ------ |
11
- | `stream` | `MediaStream` \| `undefined` |
12
- | `type` | `"audio"` \| `"video"` |
11
+ | `stream` | `MediaStream \| undefined` |
12
+ | `type` | `"audio" \| "video"` |
13
13
 
14
14
  ## Returns
15
15
 
@@ -9,7 +9,7 @@ function compareDevices(deviceInfo, key): (anotherDeviceInfo) => boolean;
9
9
  | Parameter | Type | Default value |
10
10
  | ------ | ------ | ------ |
11
11
  | `deviceInfo` | [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) | `undefined` |
12
- | `key` | `"toJSON"` \| `"deviceId"` \| `"groupId"` \| `"label"` | `'deviceId'` |
12
+ | `key` | `"toJSON" \| "deviceId" \| "groupId" \| "label"` | `'deviceId'` |
13
13
 
14
14
  ## Returns
15
15
 
@@ -6,7 +6,7 @@ function createTrackDevicesChanges(prevDevices): (devices) => object;
6
6
 
7
7
  | Parameter | Type | Default value |
8
8
  | ------ | ------ | ------ |
9
- | `prevDevices` | [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)[] | `[]` |
9
+ | `prevDevices` | [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)[] | []`` |
10
10
 
11
11
  ## Returns
12
12
 
@@ -8,7 +8,7 @@ function deviceChanged(fn): () => void;
8
8
 
9
9
  | Parameter | Type |
10
10
  | ------ | ------ |
11
- | `fn` | (`event`) => `void` |
11
+ | `fn` | `(event) => void` |
12
12
 
13
13
  ## Returns
14
14
 
@@ -7,8 +7,10 @@ function extractConstrainDevice(constraints, initialParam): ConstrainNoneTuple |
7
7
  | Parameter | Type | Default value |
8
8
  | ------ | ------ | ------ |
9
9
  | `constraints` | \| [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx) \| `undefined` | `undefined` |
10
- | `initialParam` | `"exact"` \| `"ideal"` | `'ideal'` |
10
+ | `initialParam` | `"exact" \| "ideal"` | `'ideal'` |
11
11
 
12
12
  ## Returns
13
13
 
14
- `ConstrainNoneTuple` \| `ConstrainDeviceTuple`
14
+ ```ts
15
+ ConstrainNoneTuple | ConstrainDeviceTuple
16
+ ```
@@ -0,0 +1,87 @@
1
+ ## Call Signature
2
+
3
+ ```ts
4
+ function extractConstraints<T>(key): ExtractConstraintFn<ConstrainDeviceTuple>;
5
+ ```
6
+
7
+ ### Type Parameters
8
+
9
+ | Type Parameter |
10
+ | ------ |
11
+ | `T extends "device"` |
12
+
13
+ ### Parameters
14
+
15
+ | Parameter | Type |
16
+ | ------ | ------ |
17
+ | `key` | `T` |
18
+
19
+ ### Returns
20
+
21
+ `ExtractConstraintFn<ConstrainDeviceTuple>`
22
+
23
+ ## Call Signature
24
+
25
+ ```ts
26
+ function extractConstraints<T>(key): ExtractConstraintFn<ConstrainStringTuple>;
27
+ ```
28
+
29
+ ### Type Parameters
30
+
31
+ | Type Parameter |
32
+ | ------ |
33
+ | `T extends \| "deviceId" \| "groupId" \| "videoSegmentation" \| "backgroundImageUrl" \| "resizeMode" \| "contentHint" \| "facingMode"` |
34
+
35
+ ### Parameters
36
+
37
+ | Parameter | Type |
38
+ | ------ | ------ |
39
+ | `key` | `T` |
40
+
41
+ ### Returns
42
+
43
+ `ExtractConstraintFn<ConstrainStringTuple>`
44
+
45
+ ## Call Signature
46
+
47
+ ```ts
48
+ function extractConstraints<T>(key): ExtractConstraintFn<ConstrainNumberTuple>;
49
+ ```
50
+
51
+ ### Type Parameters
52
+
53
+ | Type Parameter |
54
+ | ------ |
55
+ | `T extends ConstrainNumberKeys` |
56
+
57
+ ### Parameters
58
+
59
+ | Parameter | Type |
60
+ | ------ | ------ |
61
+ | `key` | `T` |
62
+
63
+ ### Returns
64
+
65
+ `ExtractConstraintFn<ConstrainNumberTuple>`
66
+
67
+ ## Call Signature
68
+
69
+ ```ts
70
+ function extractConstraints<T>(key): ExtractConstraintFn<ConstrainBooleanTuple>;
71
+ ```
72
+
73
+ ### Type Parameters
74
+
75
+ | Type Parameter |
76
+ | ------ |
77
+ | `T extends \| "denoise" \| "vad" \| "asd" \| "mixWithAdditionalMedia" \| "excludeBystanders" \| "pan" \| "tilt" \| "zoom" \| "echoCancellation" \| "autoGainControl" \| "noiseSuppression"` |
78
+
79
+ ### Parameters
80
+
81
+ | Parameter | Type |
82
+ | ------ | ------ |
83
+ | `key` | `T` |
84
+
85
+ ### Returns
86
+
87
+ `ExtractConstraintFn<ConstrainBooleanTuple>`
@@ -8,13 +8,13 @@ Extract the constraints with provided keys
8
8
 
9
9
  | Type Parameter |
10
10
  | ------ |
11
- | `T` *extends* \| `"deviceId"` \| `"groupId"` \| `"device"` \| `"videoSegmentation"` \| `"videoSegmentationModel"` \| `"denoise"` \| `"vad"` \| `"asd"` \| `"mixWithAdditionalMedia"` \| `"backgroundImageUrl"` \| `"excludeBystanders"` \| `"resizeMode"` \| `"pan"` \| `"tilt"` \| `"zoom"` \| `"contentHint"` \| `"facingMode"` \| `"echoCancellation"` \| `"autoGainControl"` \| `"noiseSuppression"` \| `ConstrainNumberKeys` |
11
+ | `T extends \| "deviceId" \| "groupId" \| "device" \| "videoSegmentation" \| "denoise" \| "vad" \| "asd" \| "mixWithAdditionalMedia" \| "backgroundImageUrl" \| "excludeBystanders" \| "resizeMode" \| "pan" \| "tilt" \| "zoom" \| "contentHint" \| "facingMode" \| "echoCancellation" \| "autoGainControl" \| "noiseSuppression" \| ConstrainNumberKeys` |
12
12
 
13
13
  ## Parameters
14
14
 
15
15
  | Parameter | Type | Description |
16
16
  | ------ | ------ | ------ |
17
- | `keys` | readonly `T`[] | The keys to be used for the extraction |
17
+ | `keys` | readonly `T[]` | The keys to be used for the extraction |
18
18
 
19
19
  ## Returns
20
20
 
@@ -32,7 +32,7 @@ an object with the provided key and the value-param tuple
32
32
 
33
33
  ### Returns
34
34
 
35
- `Pick`\<`Constraints`, `T`\>
35
+ `Pick<Constraints, T>`
36
36
 
37
37
  ## Example
38
38
 
@@ -12,4 +12,6 @@ function findCurrentVideoInputDeviceIdFromStream(stream): string | undefined;
12
12
 
13
13
  ## Returns
14
14
 
15
- `string` \| `undefined`
15
+ ```ts
16
+ string | undefined
17
+ ```
@@ -29,5 +29,9 @@ function findDevice(deviceToFind, useFallback): (devices) =>
29
29
 
30
30
  ### Returns
31
31
 
32
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
33
- \| `undefined`
32
+ ```ts
33
+ | MediaDeviceInfoLike
34
+ ```
35
+ ```ts
36
+ | undefined
37
+ ```
@@ -16,9 +16,15 @@ Find device from the device list with provided constraints
16
16
 
17
17
  ## Returns
18
18
 
19
- \| `boolean`
20
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
21
- \| `undefined`
19
+ ```ts
20
+ | boolean
21
+ ```
22
+ ```ts
23
+ | MediaDeviceInfoLike
24
+ ```
25
+ ```ts
26
+ | undefined
27
+ ```
22
28
 
23
29
  `true` means it can be any devices, `undefined` means not found,
24
30
  otherwise, the matched device will be returned
@@ -15,5 +15,9 @@ function findDeviceWithDeviceId(devices, deviceId):
15
15
 
16
16
  ## Returns
17
17
 
18
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
19
- \| `undefined`
18
+ ```ts
19
+ | MediaDeviceInfoLike
20
+ ```
21
+ ```ts
22
+ | undefined
23
+ ```
@@ -28,5 +28,9 @@ function findMediaInputFromMediaStreamTrack(devices): (track?) =>
28
28
 
29
29
  ### Returns
30
30
 
31
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
32
- \| `undefined`
31
+ ```ts
32
+ | MediaDeviceInfoLike
33
+ ```
34
+ ```ts
35
+ | undefined
36
+ ```
@@ -20,7 +20,7 @@ function findMediaInputFromStream(devices): (stream) => MediaInput;
20
20
 
21
21
  | Parameter | Type |
22
22
  | ------ | ------ |
23
- | `stream` | `MediaStream` \| `undefined` |
23
+ | `stream` | `MediaStream \| undefined` |
24
24
 
25
25
  ### Returns
26
26
 
@@ -6,4 +6,6 @@ function getDevices(): Promise<MediaDeviceInfo[]>;
6
6
 
7
7
  ## Returns
8
8
 
9
- `Promise`\<`MediaDeviceInfo`[]\>
9
+ ```ts
10
+ Promise<MediaDeviceInfo[]>
11
+ ```
@@ -10,4 +10,6 @@ function getFacingModeFromConstraintString(constraint): "user" | "environment" |
10
10
 
11
11
  ## Returns
12
12
 
13
- `"user"` \| `"environment"` \| `"left"` \| `"right"` \| `undefined`
13
+ ```ts
14
+ "user" | "environment" | "left" | "right" | undefined
15
+ ```
@@ -14,8 +14,10 @@ A wrapper for `navigator.permissions.query` with fallback to use
14
14
  | ------ | ------ | ------ | ------ |
15
15
  | `anyActiveAudioTrack` | `boolean` | `false` | Has ever got an active audio to help the fallback to guess the state more accurately |
16
16
  | `anyActiveVideoTrack` | `boolean` | `false` | Has ever got an active video to help the fallback to guess the state more accurately |
17
- | `getDevices` | () => `Promise`\<`MediaDeviceInfo`[]\> | `...` | A function to get the list of devices, e.g. navigator.mediaDevices.enumerateDevices |
17
+ | `getDevices` | `() => Promise<MediaDeviceInfo[]>` | `...` | A function to get the list of devices, e.g. navigator.mediaDevices.enumerateDevices |
18
18
 
19
19
  ## Returns
20
20
 
21
- `Promise`\<[`InputDevicePermission`](../interfaces/InputDevicePermission.mdx)\>
21
+ ```ts
22
+ Promise<InputDevicePermission>
23
+ ```
@@ -13,7 +13,9 @@ Check if provided devices have any video and audio inputs
13
13
 
14
14
  ## Returns
15
15
 
16
- \[`boolean`, `boolean`\]
16
+ ```ts
17
+ [boolean, boolean]
18
+ ```
17
19
 
18
20
  A tuple of `[anyAudioInput, anyVideoInput]`, e.g. `[true, false]`
19
21
  means there is audio input but no video input
@@ -10,8 +10,10 @@ is not supported from settings
10
10
 
11
11
  | Parameter | Type | Description |
12
12
  | ------ | ------ | ------ |
13
- | `currentTrack` | `MediaStreamTrack` \| `undefined` | The current video input track |
13
+ | `currentTrack` | `MediaStreamTrack \| undefined` | The current video input track |
14
14
 
15
15
  ## Returns
16
16
 
17
- `"user"` \| `"environment"` \| `"left"` \| `"right"` \| `undefined`
17
+ ```ts
18
+ "user" | "environment" | "left" | "right" | undefined
19
+ ```
@@ -7,7 +7,7 @@ function isRequestedResolution(request, response): boolean;
7
7
  | Parameter | Type |
8
8
  | ------ | ------ |
9
9
  | `request` | \| [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx) \| `undefined` |
10
- | `response` | `MediaTrackSettings` \| `undefined` |
10
+ | `response` | `MediaTrackSettings \| undefined` |
11
11
 
12
12
  ## Returns
13
13
 
@@ -12,7 +12,7 @@ Check if provided request has already been fulfilled
12
12
  | Parameter | Type | Description |
13
13
  | ------ | ------ | ------ |
14
14
  | `request` | [`MediaDeviceRequest`](../interfaces/MediaDeviceRequest.mdx) | A media request constraints |
15
- | `stream` | `MediaStream` \| `undefined` | Current media stream |
15
+ | `stream` | `MediaStream \| undefined` | Current media stream |
16
16
  | `devices` | [`IndexedDevices`](../interfaces/IndexedDevices.mdx) | - |
17
17
 
18
18
  ## Returns
@@ -10,9 +10,9 @@ function isStreamingRequestedDevicesBase(
10
10
  | Parameter | Type |
11
11
  | ------ | ------ |
12
12
  | `request` | [`MediaDeviceRequest`](../interfaces/MediaDeviceRequest.mdx) |
13
- | `tracksOrDevices` | \{ `audio?`: \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack`[]; `video?`: \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack`[]; \} |
14
- | `tracksOrDevices.audio?` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack`[] |
15
- | `tracksOrDevices.video?` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack`[] |
13
+ | `tracksOrDevices` | \{ `audio?`: \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack[]`; `video?`: \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack[]`; \} |
14
+ | `tracksOrDevices.audio?` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack[]` |
15
+ | `tracksOrDevices.video?` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack[]` |
16
16
  | `devices` | [`IndexedDevices`](../interfaces/IndexedDevices.mdx) |
17
17
 
18
18
  ## Returns
@@ -10,7 +10,7 @@ function isStreamingRequestingDevice(
10
10
  | Parameter | Type |
11
11
  | ------ | ------ |
12
12
  | `request` | \| [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx) \| `undefined` |
13
- | `trackOrDevice` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack`[] \| `undefined` |
13
+ | `trackOrDevice` | \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx) \| `MediaStreamTrack[]` \| `undefined` |
14
14
  | `devices` | [`IndexedDevices`](../interfaces/IndexedDevices.mdx) |
15
15
 
16
16
  ## Returns
@@ -30,6 +30,12 @@ Merge base constraints with provided base constraints and another constraints
30
30
 
31
31
  ### Returns
32
32
 
33
- \| `boolean`
34
- \| [`InputConstraintSet`](../interfaces/InputConstraintSet.mdx)
35
- \| `undefined`
33
+ ```ts
34
+ | boolean
35
+ ```
36
+ ```ts
37
+ | InputConstraintSet
38
+ ```
39
+ ```ts
40
+ | undefined
41
+ ```
@@ -21,7 +21,7 @@ function muteStreamTrack(stream?): (mute, mediaType) => void;
21
21
  | Parameter | Type | Default value |
22
22
  | ------ | ------ | ------ |
23
23
  | `mute` | `boolean` | `undefined` |
24
- | `mediaType` | `"audio"` \| `"video"` \| `"all"` | `'all'` |
24
+ | `mediaType` | `"audio" \| "video" \| "all"` | `'all'` |
25
25
 
26
26
  ### Returns
27
27
 
@@ -16,11 +16,15 @@ we will use the `ideal`.
16
16
 
17
17
  | Parameter | Type | Description |
18
18
  | ------ | ------ | ------ |
19
- | `kind` | `"audioinput"` \| `"videoinput"` | - |
19
+ | `kind` | `"audioinput" \| "videoinput"` | - |
20
20
  | `input` | \| [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx) \| `undefined` | The input constraints to be relaxed |
21
21
  | `devices` | [`IndexedDevices`](../interfaces/IndexedDevices.mdx) | The current device list |
22
22
 
23
23
  ## Returns
24
24
 
25
- \| [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx)
26
- \| `undefined`
25
+ ```ts
26
+ | InputDeviceConstraint
27
+ ```
28
+ ```ts
29
+ | undefined
30
+ ```
@@ -12,8 +12,10 @@ try to return the best possible from mediaTrackConstraints.
12
12
  | Parameter | Type |
13
13
  | ------ | ------ |
14
14
  | `constraints?` | [`InputDeviceConstraint`](../type-aliases/InputDeviceConstraint.mdx) |
15
- | `base?` | `boolean` \| `MediaTrackConstraints` |
15
+ | `base?` | `boolean \| MediaTrackConstraints` |
16
16
 
17
17
  ## Returns
18
18
 
19
- `boolean` \| `MediaTrackConstraints` \| `undefined`
19
+ ```ts
20
+ boolean | MediaTrackConstraints | undefined
21
+ ```
@@ -12,8 +12,8 @@ https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/stop#descripti
12
12
 
13
13
  | Parameter | Type | Description |
14
14
  | ------ | ------ | ------ |
15
- | `stream` | `MediaStream` \| `undefined` | `MediaStream` which we mutate |
16
- | `onStopped?` | (`track`) => `void` | callback to be called when the track is stopped |
15
+ | `stream` | `MediaStream \| undefined` | `MediaStream` which we mutate |
16
+ | `onStopped?` | `(track) => void` | callback to be called when the track is stopped |
17
17
 
18
18
  ## Returns
19
19
 
@@ -1,8 +1,8 @@
1
1
  ```ts
2
- function toKey(__namedParameters): string;
2
+ function toKey(__namedParameters): DeviceKey;
3
3
  ```
4
4
 
5
- **`Beta`**
5
+ Convert provided info to key for Map
6
6
 
7
7
  ## Parameters
8
8
 
@@ -12,4 +12,4 @@ function toKey(__namedParameters): string;
12
12
 
13
13
  ## Returns
14
14
 
15
- `string`
15
+ `DeviceKey`
@@ -14,5 +14,9 @@ function toMediaDeviceInfoLike(track):
14
14
 
15
15
  ## Returns
16
16
 
17
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
18
- \| `undefined`
17
+ ```ts
18
+ | MediaDeviceInfoLike
19
+ ```
20
+ ```ts
21
+ | undefined
22
+ ```
@@ -6,8 +6,10 @@ function toMediaDeviceInputKind(track): "audioinput" | "videoinput";
6
6
 
7
7
  | Parameter | Type |
8
8
  | ------ | ------ |
9
- | `track` | `Pick`\<`MediaStreamTrack`, `"kind"`\> |
9
+ | `track` | `Pick<MediaStreamTrack, "kind">` |
10
10
 
11
11
  ## Returns
12
12
 
13
- `"audioinput"` \| `"videoinput"`
13
+ ```ts
14
+ "audioinput" | "videoinput"
15
+ ```
@@ -14,8 +14,8 @@ returned by `getDisplayMedia`.
14
14
 
15
15
  | Property | Type | Overrides |
16
16
  | ------ | ------ | ------ |
17
- | <a id="audio"></a> `audio?` | `boolean` \| `DisplayAudioTrackConstraints` | `DisplayMediaStreamOptions.audio` |
18
- | <a id="video"></a> `video?` | `boolean` \| `DisplayVideoTrackConstraints` | `DisplayMediaStreamOptions.video` |
17
+ | <a id="audio"></a> `audio?` | `boolean \| DisplayAudioTrackConstraints` | `DisplayMediaStreamOptions.audio` |
18
+ | <a id="video"></a> `video?` | `boolean \| DisplayVideoTrackConstraints` | `DisplayMediaStreamOptions.video` |
19
19
  | <a id="selfbrowsersurface"></a> `selfBrowserSurface?` | `ConstrainDOMString` | - |
20
20
  | <a id="systemaudio"></a> `systemAudio?` | `ConstrainDOMString` | - |
21
21
  | <a id="surfaceswitching"></a> `surfaceSwitching?` | `ConstrainDOMString` | - |
@@ -65,8 +65,12 @@ First device of the kind
65
65
 
66
66
  #### Returns
67
67
 
68
- \| [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)
69
- \| `undefined`
68
+ ```ts
69
+ | MediaDeviceInfoLike
70
+ ```
71
+ ```ts
72
+ | undefined
73
+ ```
70
74
 
71
75
  ***
72
76
 
@@ -78,7 +82,9 @@ toJSON(): Record<MediaDeviceKind, MediaDeviceInfoLike[]>;
78
82
 
79
83
  #### Returns
80
84
 
81
- `Record`\<`MediaDeviceKind`, [`MediaDeviceInfoLike`](../type-aliases/MediaDeviceInfoLike.mdx)[]\>
85
+ ```ts
86
+ Record<MediaDeviceKind, MediaDeviceInfoLike[]>
87
+ ```
82
88
 
83
89
  ***
84
90
 
@@ -6,9 +6,8 @@
6
6
 
7
7
  | Property | Type | Description | Inherited from |
8
8
  | ------ | ------ | ------ | ------ |
9
- | <a id="device"></a> `device?` | `DeviceConstraint` \| `ConstraintDeviceParameters` | Same purpose as `deviceId` but it gives more information about the device so that we can have extra tolerance on device selection | - |
9
+ | <a id="device"></a> `device?` | `DeviceConstraint \| ConstraintDeviceParameters` | Same purpose as `deviceId` but it gives more information about the device so that we can have extra tolerance on device selection | - |
10
10
  | <a id="videosegmentation"></a> `videoSegmentation?` | `ConstrainDOMString` | Whether or not using video segmentation, e.g. background blur/replacement, to specify the effects, intended to be applied to the segment. Available effects are `none`, `blur`, `overlay` or `remove` | - |
11
- | <a id="videosegmentationmodel"></a> `videoSegmentationModel?` | `ConstrainDOMString` | Segmentation model to be used for video segmentation, currently only supports `mediapipeSelfie` and `personify` | - |
12
11
  | <a id="denoise"></a> `denoise?` | `ConstrainBoolean` | Whether or not using our own noise suppression | - |
13
12
  | <a id="vad"></a> `vad?` | `ConstrainBoolean` | Voice Activity Detection | - |
14
13
  | <a id="asd"></a> `asd?` | `ConstrainBoolean` | Audio Signal Detection for the purpose of checking if the audio input is hardware muted or unusable | - |
@@ -18,7 +17,7 @@
18
17
  | <a id="foregroundthreshold"></a> `foregroundThreshold?` | `ConstrainDouble` | Erode level for edge smoothing when using video segmentation | - |
19
18
  | <a id="backgroundimageurl"></a> `backgroundImageUrl?` | `ConstrainDOMString` | Image Url that is being used for video overlay effects | - |
20
19
  | <a id="maskcombineratio"></a> `maskCombineRatio?` | `ConstrainDouble` | The ratio to be used for smoothing segmentation mask. How much uncertainty enables temporal blend, [0,1]. Higher = more frame-to-frame blending, more stability but more trailing ghosts. Typical: 0.6–0.85. | - |
21
- | <a id="backgroundthreshold"></a> `backgroundThreshold?` | `ConstrainDouble` | [0,1] Lower mask confidence: all mask pixels <= this are considered definite background. Adjust to make mask edges tighter or more permissive for background inclusion. Example: 0.3 ("mask < 0.3 = sure background"). | - |
20
+ | <a id="backgroundthreshold"></a> `backgroundThreshold?` | `ConstrainDouble` | [0,1] Lower mask confidence: all mask pixels \<= this are considered definite background. Adjust to make mask edges tighter or more permissive for background inclusion. Example: 0.3 ("mask \< 0.3 = sure background"). | - |
22
21
  | <a id="sigmaspace"></a> `sigmaSpace?` | `ConstrainDouble` | Bilateral filter: sigma in pixel space for mask edge snapping. Controls the neighborhood/pixel distance—higher is larger window (5–10 typical). | - |
23
22
  | <a id="sigmarangelo"></a> `sigmaRangeLo?` | `ConstrainDouble` | Bilateral filter: minimum sigma in color/luma (for mask interiors), [0,1]. Controls how little color difference is needed to cross-mask regions away from edge. Lower = sharper edge preservation in mask interiors. Example: 0.2 | - |
24
23
  | <a id="sigmarangehi"></a> `sigmaRangeHi?` | `ConstrainDouble` | Bilateral filter: maximum sigma in color/luma (for mask uncertain zones), [0,1]. Controls how much color similarity is required at uncertain/edge mask locations. Higher = more mask smoothing at edges. Example: 0.8 | - |
@@ -38,15 +37,13 @@
38
37
  | <a id="tilt"></a> `tilt?` | `boolean` | - | - |
39
38
  | <a id="zoom"></a> `zoom?` | `boolean` | - | - |
40
39
  | <a id="contenthint"></a> `contentHint?` | `ConstrainDOMString` | Content Hint for the track to apply | - |
41
- | <a id="volume"></a> `volume?` | `ConstrainNumber` | - | `MediaTrackConstraints.volume` |
42
- | <a id="latency"></a> `latency?` | `ConstrainNumber` | - | `MediaTrackConstraints.latency` |
43
40
  | <a id="aspectratio"></a> `aspectRatio?` | `ConstrainDouble` | - | `MediaTrackConstraints.aspectRatio` |
44
41
  | <a id="autogaincontrol"></a> `autoGainControl?` | `ConstrainBoolean` | - | `MediaTrackConstraints.autoGainControl` |
45
42
  | <a id="backgroundblur"></a> `backgroundBlur?` | `ConstrainBoolean` | - | `MediaTrackConstraints.backgroundBlur` |
46
43
  | <a id="channelcount"></a> `channelCount?` | `ConstrainULong` | - | `MediaTrackConstraints.channelCount` |
47
44
  | <a id="deviceid"></a> `deviceId?` | `ConstrainDOMString` | - | `MediaTrackConstraints.deviceId` |
48
45
  | <a id="displaysurface"></a> `displaySurface?` | `ConstrainDOMString` | - | `MediaTrackConstraints.displaySurface` |
49
- | <a id="echocancellation"></a> `echoCancellation?` | `ConstrainBoolean` | - | `MediaTrackConstraints.echoCancellation` |
46
+ | <a id="echocancellation"></a> `echoCancellation?` | `ConstrainBooleanOrDOMString` | - | `MediaTrackConstraints.echoCancellation` |
50
47
  | <a id="facingmode"></a> `facingMode?` | `ConstrainDOMString` | - | `MediaTrackConstraints.facingMode` |
51
48
  | <a id="framerate"></a> `frameRate?` | `ConstrainDouble` | - | `MediaTrackConstraints.frameRate` |
52
49
  | <a id="groupid"></a> `groupId?` | `ConstrainDOMString` | - | `MediaTrackConstraints.groupId` |
@@ -55,4 +52,4 @@
55
52
  | <a id="samplerate"></a> `sampleRate?` | `ConstrainULong` | - | `MediaTrackConstraints.sampleRate` |
56
53
  | <a id="samplesize"></a> `sampleSize?` | `ConstrainULong` | - | `MediaTrackConstraints.sampleSize` |
57
54
  | <a id="width"></a> `width?` | `ConstrainULong` | - | `MediaTrackConstraints.width` |
58
- | <a id="advanced"></a> `advanced?` | `MediaTrackConstraintSet`[] | - | `MediaTrackConstraints.advanced` |
55
+ | <a id="advanced"></a> `advanced?` | `MediaTrackConstraintSet[]` | - | `MediaTrackConstraints.advanced` |
@@ -6,9 +6,9 @@ MediaControl Interface
6
6
 
7
7
  | Property | Type | Description |
8
8
  | ------ | ------ | ------ |
9
- | <a id="devicechanged"></a> `deviceChanged` | (`fn`) => () => `void` | **`Beta`** Unified interface for subscribing [DeviceChangedChanges](../type-aliases/DeviceChangedChanges.mdx) Event |
10
- | <a id="getdevices"></a> `getDevices` | () => `Promise`\<`MediaDeviceInfo`[]\> | **`Beta`** Future proofing: in case we want to alter the values or type returned by [enumerateDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices) |
9
+ | <a id="devicechanged"></a> `deviceChanged` | `(fn) => () => void` | **`Beta`** Unified interface for subscribing [DeviceChangedChanges](../type-aliases/DeviceChangedChanges.mdx) Event |
10
+ | <a id="getdevices"></a> `getDevices` | `() => Promise<MediaDeviceInfo[]>` | **`Beta`** Future proofing: in case we want to alter the values or type returned by [enumerateDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices) |
11
11
  | <a id="mediaeventtype"></a> `MediaEventType` | *typeof* [`MediaEventType`](../enumerations/MediaEventType.mdx) | **`Beta`** MediaStreamTrack Events **Remarks** See MDN [Events](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack#Events) |
12
- | <a id="getusermedia"></a> `getUserMedia` | (`__namedParameters`) => `Promise`\<`MediaStream`\> | **`Beta`** Get MediaStream with provided [input constraints](MediaDeviceRequest.mdx) |
13
- | <a id="setdefaultconstraints"></a> `setDefaultConstraints` | (`newConstraints`) => `void` | **`Beta`** Set default media stream constraints A [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints) object specifying the types of media to request, along with any requirements for each type. |
14
- | <a id="subscribe"></a> `subscribe` | (`listener`) => () => `void` | **`Beta`** Subscribe media events |
12
+ | <a id="getusermedia"></a> `getUserMedia` | `(__namedParameters) => Promise<MediaStream>` | **`Beta`** Get MediaStream with provided [input constraints](MediaDeviceRequest.mdx) |
13
+ | <a id="setdefaultconstraints"></a> `setDefaultConstraints` | `(newConstraints) => void` | **`Beta`** Set default media stream constraints A [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints) object specifying the types of media to request, along with any requirements for each type. |
14
+ | <a id="subscribe"></a> `subscribe` | `(listener) => () => void` | **`Beta`** Subscribe media events |
@@ -10,4 +10,4 @@ A striped version of MediaDeviceInfo
10
10
 
11
11
  | Name | Type |
12
12
  | ------ | ------ |
13
- | `toJSON?` | `MediaDeviceInfo`\[`"toJSON"`\] |
13
+ | `toJSON?` | `MediaDeviceInfo["toJSON"]` |
@@ -16,6 +16,6 @@ Get MediaStream with MediaDeviceRequest
16
16
 
17
17
  ## Returns
18
18
 
19
- `Promise`\<`MediaStream`\>
19
+ `Promise<MediaStream>`
20
20
 
21
21
  MediaStream
@@ -12,7 +12,7 @@ Subscription media events
12
12
 
13
13
  | Parameter | Type |
14
14
  | ------ | ------ |
15
- | `listener` | (`event`) => `void` |
15
+ | `listener` | `(event) => void` |
16
16
 
17
17
  ## Returns
18
18
 
@@ -213,7 +213,6 @@ export const extractConstrainBoolean = (key) => (constraints) => {
213
213
  return NONE;
214
214
  };
215
215
  export const extractConstrainNumber = (key) => (constraints) => {
216
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- @typescript-eslint and Typescript 5 issue.
217
216
  const constraint = constraints[key];
218
217
  if (constraint === undefined || constraint === null) {
219
218
  return NONE;
package/dist/devices.d.ts CHANGED
@@ -18,12 +18,14 @@ interface ToKeyOptions {
18
18
  kind: string;
19
19
  label: string;
20
20
  }
21
+ export type DeviceKey = string & {
22
+ __type: 'track-key';
23
+ };
21
24
  /**
22
25
  * Convert provided info to key for Map
23
26
  *
24
- * @beta
25
27
  */
26
- export declare const toKey: ({ id, kind, label }: ToKeyOptions) => string;
28
+ export declare const toKey: ({ id, kind, label }: ToKeyOptions) => DeviceKey;
27
29
  export declare const toMediaDeviceInputKind: (track: Pick<MediaStreamTrack, "kind">) => "audioinput" | "videoinput";
28
30
  /**
29
31
  * Future proofing: in case we want to alter the values or type returned
@@ -43,8 +45,8 @@ export declare const toMediaDeviceInputKind: (track: Pick<MediaStreamTrack, "kin
43
45
  * @beta
44
46
  */
45
47
  export declare const getDevices: () => Promise<MediaDeviceInfo[]>;
46
- export declare const toDeviceKey: (device: MediaDeviceInfoLike) => string;
47
- export declare const toDeviceTuple: (device: MediaDeviceInfoLike) => readonly [string, MediaDeviceInfoLike];
48
+ export declare const toDeviceKey: (device: MediaDeviceInfoLike) => DeviceKey;
49
+ export declare const toDeviceTuple: (device: MediaDeviceInfoLike) => readonly [DeviceKey, MediaDeviceInfoLike];
48
50
  export declare const toDevicesMap: (devices: MediaDeviceInfoLike[]) => Map<string, MediaDeviceInfoLike>;
49
51
  export declare const createTrackDevicesChanges: (prevDevices?: MediaDeviceInfoLike[]) => (devices: MediaDeviceInfoLike[]) => {
50
52
  found: MediaDeviceInfoLike[];
package/dist/devices.js CHANGED
@@ -7,7 +7,6 @@ import { DEVICE_ID_SEPARATOR } from './constants';
7
7
  /**
8
8
  * Convert provided info to key for Map
9
9
  *
10
- * @beta
11
10
  */
12
11
  export const toKey = ({ id, kind, label }) => [kind, id, label].join(DEVICE_ID_SEPARATOR);
13
12
  export const toMediaDeviceInputKind = (track) => {
@@ -441,7 +440,6 @@ export const queryPermissionFallback = async (name, everActiveTrack = false, get
441
440
  };
442
441
  export const queryPermission = async (name, everActiveTrack = false, getDevices = () => navigator.mediaDevices.enumerateDevices()) => {
443
442
  try {
444
- // @ts-expect-error -- Typings/dom.d.ts change blocks upgrade to typescript 4.4
445
443
  const { state } = await navigator.permissions.query({ name });
446
444
  // Firefox v133 added permission API but always returns granted but
447
445
  // based on the device label, it is actually not granted, so we need to
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { DeviceChangedChanges, areMultipleFacingModeSupported, areTracksEnabled, createTrackDevicesChanges, deviceChanged, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDevices, getInputDevicePermissionState, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, muteStreamTrack, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind } from './devices';
11
11
  import { compareDevices, createIndexedDevices, findDevice, getDeviceId, isAudioInput, isAudioOutput, isDeviceGranted, isVideoInput, reverseDeviceId } from './utils';
12
- import { applyConstraints, extractConstrainDevice, extractConstraintsWithKeys, findDeviceFromConstraints, getFacingModeFromConstraintString, getValueFromConstrainNumber, isExactDeviceConstraint, mergeConstraints, relaxInputConstraint, resolveMediaDeviceConstraints } from './constraints';
12
+ import { applyConstraints, extractConstrainDevice, extractConstraints, extractConstraintsWithKeys, findDeviceFromConstraints, getFacingModeFromConstraintString, getValueFromConstrainNumber, isExactDeviceConstraint, mergeConstraints, relaxInputConstraint, resolveMediaDeviceConstraints } from './constraints';
13
13
  import { MediaEvent, Events, MediaEventType } from './eventEmitter';
14
14
  import { createStreamTrackEventSubscriptions } from './streams';
15
15
  import { DisplayMediaOptions, FacingMode, IndexedDevices, InputConstraintSet, InputDeviceConstraint, MediaDeviceFailure, MediaDeviceInfoLike, MediaDeviceKinds, MediaDeviceRequest, MediaInput, MediaStreamTrackLike, StreamTrackEventHandlers, Unsubscribe } from './types';
@@ -33,7 +33,7 @@ setDefaultConstraints: (newConstraints: MediaStreamConstraints) => void,
33
33
  */
34
34
  subscribe: (listener: (event: MediaEvent) => void) => () => void;
35
35
  export { getUserMedia, setDefaultConstraints, subscribe };
36
- export { DeviceChangedChanges, DisplayMediaOptions, Events, FacingMode, IndexedDevices, InputConstraintSet, InputDeviceConstraint, MediaDeviceFailure, MediaDeviceInfoLike, MediaDeviceKinds, MediaDeviceRequest, MediaEvent, MediaEventType, MediaInput, MediaStreamTrackLike, StreamTrackEventHandlers, Unsubscribe, applyConstraints, areMultipleFacingModeSupported, areTracksEnabled, compareDevices, createIndexedDevices, createStreamTrackEventSubscriptions, createTrackDevicesChanges, deviceChanged, extractConstrainDevice, extractConstraintsWithKeys, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDevice, findDeviceFromConstraints, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDeviceId, getDevices, getFacingModeFromConstraintString, getInputDevicePermissionState, getValueFromConstrainNumber, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isAudioInput, isAudioOutput, isDeviceGranted, isExactDeviceConstraint, isFacingMode, isIndexedDevices, isInputConstraintSet, isMediaDeviceInfo, isMediaDeviceInfoArray, isMediaStreamTrack, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, isVideoInput, mergeConstraints, muteStreamTrack, relaxInputConstraint, resolveMediaDeviceConstraints, reverseDeviceId, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind, };
36
+ export { DeviceChangedChanges, DisplayMediaOptions, Events, FacingMode, IndexedDevices, InputConstraintSet, InputDeviceConstraint, MediaDeviceFailure, MediaDeviceInfoLike, MediaDeviceKinds, MediaDeviceRequest, MediaEvent, MediaEventType, MediaInput, MediaStreamTrackLike, StreamTrackEventHandlers, Unsubscribe, applyConstraints, areMultipleFacingModeSupported, areTracksEnabled, compareDevices, createIndexedDevices, createStreamTrackEventSubscriptions, createTrackDevicesChanges, deviceChanged, extractConstrainDevice, extractConstraints, extractConstraintsWithKeys, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDevice, findDeviceFromConstraints, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDeviceId, getDevices, getFacingModeFromConstraintString, getInputDevicePermissionState, getValueFromConstrainNumber, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isAudioInput, isAudioOutput, isDeviceGranted, isExactDeviceConstraint, isFacingMode, isIndexedDevices, isInputConstraintSet, isMediaDeviceInfo, isMediaDeviceInfoArray, isMediaStreamTrack, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, isVideoInput, mergeConstraints, muteStreamTrack, relaxInputConstraint, resolveMediaDeviceConstraints, reverseDeviceId, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind, };
37
37
  export * from './constants';
38
38
  export * from './displayMedia';
39
39
  /**
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { areMultipleFacingModeSupported, areTracksEnabled, createTrackDevicesChanges, deviceChanged, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDevices, getInputDevicePermissionState, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, muteStreamTrack, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind, } from './devices';
11
11
  import { compareDevices, createIndexedDevices, findDevice, getDeviceId, isAudioInput, isAudioOutput, isDeviceGranted, isVideoInput, reverseDeviceId, } from './utils';
12
- import { applyConstraints, extractConstrainDevice, extractConstraintsWithKeys, findDeviceFromConstraints, getConstraintsHandlers, getFacingModeFromConstraintString, getValueFromConstrainNumber, isExactDeviceConstraint, mergeConstraints, relaxInputConstraint, resolveMediaDeviceConstraints, } from './constraints';
12
+ import { applyConstraints, extractConstrainDevice, extractConstraints, extractConstraintsWithKeys, findDeviceFromConstraints, getConstraintsHandlers, getFacingModeFromConstraintString, getValueFromConstrainNumber, isExactDeviceConstraint, mergeConstraints, relaxInputConstraint, resolveMediaDeviceConstraints, } from './constraints';
13
13
  import { eventEmitter, MediaEventType } from './eventEmitter';
14
14
  import { handleMediaStream, createStreamTrackEventSubscriptions, } from './streams';
15
15
  import { MediaDeviceFailure, MediaDeviceKinds, } from './types';
@@ -91,6 +91,6 @@ setDefaultConstraints,
91
91
  */
92
92
  subscribe, } = state();
93
93
  export { getUserMedia, setDefaultConstraints, subscribe };
94
- export { MediaDeviceFailure, MediaDeviceKinds, MediaEventType, applyConstraints, areMultipleFacingModeSupported, areTracksEnabled, compareDevices, createIndexedDevices, createStreamTrackEventSubscriptions, createTrackDevicesChanges, deviceChanged, extractConstrainDevice, extractConstraintsWithKeys, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDevice, findDeviceFromConstraints, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDeviceId, getDevices, getFacingModeFromConstraintString, getInputDevicePermissionState, getValueFromConstrainNumber, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isAudioInput, isAudioOutput, isDeviceGranted, isExactDeviceConstraint, isFacingMode, isIndexedDevices, isInputConstraintSet, isMediaDeviceInfo, isMediaDeviceInfoArray, isMediaStreamTrack, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, isVideoInput, mergeConstraints, muteStreamTrack, relaxInputConstraint, resolveMediaDeviceConstraints, reverseDeviceId, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind, };
94
+ export { MediaDeviceFailure, MediaDeviceKinds, MediaEventType, applyConstraints, areMultipleFacingModeSupported, areTracksEnabled, compareDevices, createIndexedDevices, createStreamTrackEventSubscriptions, createTrackDevicesChanges, deviceChanged, extractConstrainDevice, extractConstraints, extractConstraintsWithKeys, findAudioInputDevices, findAudioOutputDevices, findCurrentAudioOutputId, findCurrentVideoInputDeviceIdFromStream, findDevice, findDeviceFromConstraints, findDeviceWithDeviceId, findDevicesByKind, findMediaInputFromMediaStreamTrack, findMediaInputFromStream, findPermissionGrantedDevices, findVideoInputDevices, getDeviceId, getDevices, getFacingModeFromConstraintString, getInputDevicePermissionState, getValueFromConstrainNumber, hasAnyGrantedInput, hasAnyInputs, hasAudioInputs, hasAudioOrVideoInputs, hasChangedInput, hasRequestingDevice, hasVideoInputs, interpretCurrentFacingMode, isAudioInput, isAudioOutput, isDeviceGranted, isExactDeviceConstraint, isFacingMode, isIndexedDevices, isInputConstraintSet, isMediaDeviceInfo, isMediaDeviceInfoArray, isMediaStreamTrack, isRequestedInputDevice, isRequestedInputTrack, isRequestedResolution, isStreamingRequestedDevices, isStreamingRequestedDevicesBase, isStreamingRequestingDevice, isTrackMutedOrEnded, isVideoInput, mergeConstraints, muteStreamTrack, relaxInputConstraint, resolveMediaDeviceConstraints, reverseDeviceId, shouldRequestDevice, stopMediaStream, toKey, toMediaDeviceInfo, toMediaDeviceInfoLike, toMediaDeviceInputKind, };
95
95
  export * from './constants';
96
96
  export * from './displayMedia';
@@ -1,7 +1,8 @@
1
1
  import type { DeviceOrTrack, MediaStreamTrackLike } from './types';
2
+ import { type DeviceKey } from './devices';
2
3
  export declare const createStreamTrackMap: (tracks?: MediaStreamTrackLike[]) => {
3
- add: (track: MediaStreamTrackLike) => Map<string, MediaStreamTrackLike>;
4
- has: (deviceOrTrack: DeviceOrTrack) => boolean | "";
4
+ add: (track: MediaStreamTrackLike) => Map<DeviceKey, MediaStreamTrackLike>;
5
+ has: (deviceOrTrack: DeviceOrTrack) => boolean;
5
6
  clear: () => void;
6
7
  remove: (track: MediaStreamTrackLike) => boolean;
7
8
  size: () => number;
@@ -3,33 +3,81 @@ import { toKey } from './devices';
3
3
  import { isMediaStreamTrack } from './typeGuards';
4
4
  export const createStreamTrackMap = (tracks) => {
5
5
  const streamTrackMap = new Map(tracks?.map(track => [toKey(track), track]));
6
+ const toDeviceIndexKey = (track) => {
7
+ const { deviceId } = track.getSettings();
8
+ return deviceId
9
+ ? `${track.kind}:${deviceId}`
10
+ : undefined;
11
+ };
12
+ const toDeviceQueryKey = (device) => {
13
+ switch (device.kind) {
14
+ case 'audioinput':
15
+ return `audio:${device.deviceId}`;
16
+ case 'videoinput':
17
+ return `video:${device.deviceId}`;
18
+ default:
19
+ return undefined;
20
+ }
21
+ };
22
+ /**
23
+ * Secondary index: `${track.kind}:${deviceId}` → tracks for O(1) device lookups.
24
+ * Uses a Set per key so multiple tracks sharing a deviceId stay findable
25
+ * until every one of them is removed.
26
+ */
27
+ const deviceIndex = new Map();
28
+ const addToDeviceIndex = (track) => {
29
+ const indexKey = toDeviceIndexKey(track);
30
+ if (!indexKey) {
31
+ return;
32
+ }
33
+ const existing = deviceIndex.get(indexKey);
34
+ if (existing) {
35
+ existing.add(track);
36
+ }
37
+ else {
38
+ deviceIndex.set(indexKey, new Set([track]));
39
+ }
40
+ };
41
+ const removeFromDeviceIndex = (track) => {
42
+ const indexKey = toDeviceIndexKey(track);
43
+ if (!indexKey) {
44
+ return;
45
+ }
46
+ const existing = deviceIndex.get(indexKey);
47
+ if (!existing) {
48
+ return;
49
+ }
50
+ existing.delete(track);
51
+ if (existing.size === 0) {
52
+ deviceIndex.delete(indexKey);
53
+ }
54
+ };
55
+ for (const track of streamTrackMap.values()) {
56
+ addToDeviceIndex(track);
57
+ }
6
58
  /**
7
59
  * Find track from the list of track in use.
8
60
  */
9
61
  const findTrack = (device) => {
10
- return [...streamTrackMap]
11
- .map(([_, track]) => track)
12
- .find(track => {
13
- const { kind } = track;
14
- const { deviceId } = track.getSettings();
15
- if (!deviceId) {
16
- return false;
17
- }
18
- return (device.kind.includes(kind) && device.deviceId === deviceId);
19
- });
62
+ const queryKey = toDeviceQueryKey(device);
63
+ if (!queryKey) {
64
+ return undefined;
65
+ }
66
+ const tracks = deviceIndex.get(queryKey);
67
+ return tracks?.values().next().value;
20
68
  };
21
69
  /**
22
- * Construct a `StreamTrackKey` from `DeviceOrTrack`
70
+ * Construct a `DeviceKey` from `DeviceOrTrack`
23
71
  */
24
72
  const toStreamTrackKey = (deviceOrTrack) => {
25
73
  // Unify interfaces
26
74
  const track = isMediaStreamTrack(deviceOrTrack)
27
75
  ? deviceOrTrack
28
76
  : findTrack(deviceOrTrack);
29
- if (!track?.kind || !track.id) {
30
- return '';
31
- }
32
- return toKey(track);
77
+ const kind = track?.kind || 'unknown-kind';
78
+ const id = track?.id || 'unknown-id';
79
+ const label = track?.label || 'unknown-label';
80
+ return toKey({ kind, id, label });
33
81
  };
34
82
  /**
35
83
  * Add the `MediaStreamTrack` to `streamTrackMap`
@@ -37,6 +85,7 @@ export const createStreamTrackMap = (tracks) => {
37
85
  const add = (track) => {
38
86
  const key = toStreamTrackKey(track);
39
87
  if (key) {
88
+ addToDeviceIndex(track);
40
89
  return streamTrackMap.set(key, track);
41
90
  }
42
91
  throw new Error(MediaDeviceFailure.StreamTrackNotFound);
@@ -56,12 +105,14 @@ export const createStreamTrackMap = (tracks) => {
56
105
  track.stop();
57
106
  }
58
107
  streamTrackMap.clear();
108
+ deviceIndex.clear();
59
109
  };
60
110
  /**
61
111
  * Stop the track and remove the track from `streamTrackMap`
62
112
  */
63
113
  const remove = (track) => {
64
114
  const key = toStreamTrackKey(track);
115
+ removeFromDeviceIndex(track);
65
116
  track.stop();
66
117
  return streamTrackMap.delete(key);
67
118
  };
@@ -17,14 +17,14 @@ export declare const isFloat: (t: unknown) => t is number;
17
17
  * Reference https://w3c.github.io/mediacapture-main/#dom-mediatrackconstraintset
18
18
  */
19
19
  export declare const CONSTRAIN_STRING_KEYS: readonly ["facingMode", "resizeMode", "deviceId", "groupId"];
20
- export declare const EXTENDED_CONSTRAIN_STRING_KEYS: readonly ["videoSegmentation", "videoSegmentationModel", "backgroundImageUrl", "contentHint"];
20
+ export declare const EXTENDED_CONSTRAIN_STRING_KEYS: readonly ["videoSegmentation", "backgroundImageUrl", "contentHint"];
21
21
  export type ExtendedConstrainStringKeys = (typeof EXTENDED_CONSTRAIN_STRING_KEYS)[number];
22
22
  export type ConstrainStringKeys = (typeof CONSTRAIN_STRING_KEYS)[number];
23
23
  export declare const CONSTRAIN_U_LONG_KEYS: readonly ["width", "height", "sampleRate", "sampleSize", "channelCount"];
24
24
  export declare const EXTENDED_CONSTRAIN_U_LONG_KEYS: readonly ["backgroundBlurAmount", "edgeBlurAmount", "morphErodeRadiusPx", "morphPass", "morphDilateRadiusPx", "lightWrapBlurAmount", "downSampleFactor"];
25
25
  export type ExtendedConstrainULongKeys = (typeof EXTENDED_CONSTRAIN_U_LONG_KEYS)[number];
26
26
  export type ConstrainULongKeys = (typeof CONSTRAIN_U_LONG_KEYS)[number];
27
- export declare const CONSTRAIN_DOUBLE_KEYS: readonly ["aspectRatio", "frameRate", "latency"];
27
+ export declare const CONSTRAIN_DOUBLE_KEYS: readonly ["aspectRatio", "frameRate"];
28
28
  export declare const EXTENDED_CONSTRAIN_DOUBLE_KEYS: readonly ["foregroundThreshold", "backgroundThreshold", "sigmaSpace", "sigmaRangeLo", "sigmaRangeHi", "maskCombineRatio", "personCenterX", "personCenterY", "lightWrapIntensity", "lightWrapTightness", "lightWrapEdgeBand"];
29
29
  export type ExtendedConstrainDoubleKeys = (typeof EXTENDED_CONSTRAIN_DOUBLE_KEYS)[number];
30
30
  export type ConstrainDoubleKeys = (typeof CONSTRAIN_DOUBLE_KEYS)[number];
@@ -39,7 +39,7 @@ export type ConstrainBooleanKeys = (typeof CONSTRAIN_BOOLEAN_KEYS)[number];
39
39
  /**
40
40
  * The keys from the `MediaTrackConstraintSet`
41
41
  */
42
- export declare const CONSTRAINT_SET_KEYS: readonly ["aspectRatio", "frameRate", "latency", "width", "height", "sampleRate", "sampleSize", "channelCount", "facingMode", "resizeMode", "deviceId", "groupId", "echoCancellation", "autoGainControl", "noiseSuppression", "pan", "tilt", "zoom"];
42
+ export declare const CONSTRAINT_SET_KEYS: readonly ["aspectRatio", "frameRate", "width", "height", "sampleRate", "sampleSize", "channelCount", "facingMode", "resizeMode", "deviceId", "groupId", "echoCancellation", "autoGainControl", "noiseSuppression", "pan", "tilt", "zoom"];
43
43
  export declare const isConstrainStringKeys: (t: unknown) => t is ConstrainStringKeys;
44
44
  export declare const isExtendedConstrainStringKeys: (t: unknown) => t is ExtendedConstrainStringKeys;
45
45
  export declare const isConstrainULongKeys: (t: unknown) => t is ConstrainULongKeys;
@@ -25,7 +25,6 @@ export const CONSTRAIN_STRING_KEYS = [
25
25
  ];
26
26
  export const EXTENDED_CONSTRAIN_STRING_KEYS = [
27
27
  'videoSegmentation',
28
- 'videoSegmentationModel',
29
28
  'backgroundImageUrl',
30
29
  'contentHint',
31
30
  ];
@@ -45,11 +44,7 @@ export const EXTENDED_CONSTRAIN_U_LONG_KEYS = [
45
44
  'lightWrapBlurAmount',
46
45
  'downSampleFactor',
47
46
  ];
48
- export const CONSTRAIN_DOUBLE_KEYS = [
49
- 'aspectRatio',
50
- 'frameRate',
51
- 'latency',
52
- ];
47
+ export const CONSTRAIN_DOUBLE_KEYS = ['aspectRatio', 'frameRate'];
53
48
  export const EXTENDED_CONSTRAIN_DOUBLE_KEYS = [
54
49
  'foregroundThreshold',
55
50
  'backgroundThreshold',
package/dist/types.d.ts CHANGED
@@ -66,11 +66,6 @@ export interface InputConstraintSet extends MediaTrackConstraints {
66
66
  * segment. Available effects are `none`, `blur`, `overlay` or `remove`
67
67
  */
68
68
  videoSegmentation?: ConstrainDOMString;
69
- /**
70
- * Segmentation model to be used for video segmentation, currently only
71
- * supports `mediapipeSelfie` and `personify`
72
- */
73
- videoSegmentationModel?: ConstrainDOMString;
74
69
  /**
75
70
  * Whether or not using our own noise suppression
76
71
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pexip/media-control",
3
- "version": "21.0.0",
3
+ "version": "22.1.0",
4
4
  "homepage": "https://developer.pexip.com",
5
5
  "bugs": "https://gitlab.com/pexip/zoo/issues",
6
6
  "repository": {
@@ -48,22 +48,22 @@
48
48
  "docs": "typedoc"
49
49
  },
50
50
  "dependencies": {
51
- "@pexip/utils": "17.2.0"
51
+ "@pexip/utils": "17.4.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@jest/globals": "^30.2.0",
55
- "@pexip/bundler": "18.2.0",
56
- "@swc/core": "^1.10.12",
54
+ "@jest/globals": "^29.5.12",
55
+ "@pexip/bundler": "18.2.1",
56
+ "@swc/core": "^1.15.33",
57
57
  "@swc/jest": "^0.2.39",
58
58
  "@types/uuid": "^8.3.0",
59
59
  "@types/webrtc": "^0.0.31",
60
60
  "jest": "^29.5.12",
61
61
  "jest-junit": "^16.0.0",
62
62
  "prettier": "^3.2.5",
63
- "typedoc": "^0.28.15",
64
- "typedoc-plugin-markdown": "^4.9.0",
65
- "typescript": "~5.7.3",
66
- "uuid": "^11.0.0"
63
+ "typedoc": "^0.28.18",
64
+ "typedoc-plugin-markdown": "^4.11.0",
65
+ "typescript": "~6.0.2",
66
+ "uuid": "^14.0.0"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"