@pexip/media-control 17.2.0 → 17.4.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.
@@ -0,0 +1,265 @@
1
+ /**
2
+ * A striped version of MediaDeviceInfo
3
+ *
4
+ * @beta
5
+ */
6
+ export type MediaDeviceInfoLike = Omit<MediaDeviceInfo, 'toJSON'> & {
7
+ settings?: MediaTrackSettings;
8
+ toJSON?: MediaDeviceInfo['toJSON'];
9
+ };
10
+ export type DeviceConstraint = MediaDeviceInfoLike | MediaDeviceInfoLike[];
11
+ export interface NormalizedConstraintDeviceParameters {
12
+ exact?: MediaDeviceInfoLike[];
13
+ ideal?: MediaDeviceInfoLike[];
14
+ }
15
+ export interface ConstraintDeviceParameters {
16
+ exact?: DeviceConstraint;
17
+ ideal?: DeviceConstraint;
18
+ }
19
+ export interface InputConstraintSet extends MediaTrackConstraints {
20
+ /**
21
+ * Same purpose as `deviceId` but it gives more information about the device
22
+ * so that we can have extra tolerance on device selection
23
+ */
24
+ device?: DeviceConstraint | ConstraintDeviceParameters;
25
+ /**
26
+ * Whether or not using video segmentation, e.g. background
27
+ * blur/replacement, to specify the effects, intended to be applied to the
28
+ * segment. Available effects are `none`, `blur`, `overlay` or `remove`
29
+ */
30
+ videoSegmentation?: ConstrainDOMString;
31
+ /**
32
+ * Segmentation model to be used for video segmentation, currently only
33
+ * supports `mediapipeSelfie` and `personify`
34
+ */
35
+ videoSegmentationModel?: ConstrainDOMString;
36
+ /**
37
+ * Whether or not using our own noise suppression
38
+ */
39
+ denoise?: ConstrainBoolean;
40
+ /**
41
+ * Voice Activity Detection
42
+ */
43
+ vad?: ConstrainBoolean;
44
+ /**
45
+ * Audio Signal Detection for the purpose of checking if the audio input is
46
+ * hardware muted or unusable
47
+ */
48
+ asd?: ConstrainBoolean;
49
+ /**
50
+ * Audio Signal Detection for the purpose of checking if the audio input is
51
+ * hardware muted or unusable
52
+ */
53
+ mixWithAdditionalMedia?: ConstrainBoolean;
54
+ /**
55
+ * Flip the video horizontally
56
+ */
57
+ flipHorizontal?: ConstrainBoolean;
58
+ /**
59
+ * Blur size/level parameter when using video segmentation with `blur`
60
+ * effects
61
+ */
62
+ backgroundBlurAmount?: ConstrainULong;
63
+ /**
64
+ * Blur amount applied to the segmented person's edge
65
+ */
66
+ edgeBlurAmount?: ConstrainULong;
67
+ /**
68
+ * Erode level for edge smoothing when using video segmentation
69
+ */
70
+ foregroundThreshold?: ConstrainDouble;
71
+ /**
72
+ * Image Url that is being used for video overlay effects
73
+ */
74
+ bgImageUrl?: ConstrainDOMString;
75
+ /**
76
+ * Image Url that is being used for video overlay effects
77
+ */
78
+ resizeMode?: ConstrainDOMString;
79
+ /**
80
+ * Current pan, tilt and zoom level for a PTZ controllable camera on web
81
+ */
82
+ pan?: boolean;
83
+ tilt?: boolean;
84
+ zoom?: boolean;
85
+ /**
86
+ * Content Hint for the track to apply
87
+ */
88
+ contentHint?: ConstrainDOMString;
89
+ }
90
+ export type InputDeviceConstraint = DeviceConstraint | InputConstraintSet | boolean;
91
+ /**
92
+ * The request constraints that applies to `getMediaStream`
93
+ *
94
+ * @beta
95
+ */
96
+ export interface MediaDeviceRequest {
97
+ /**
98
+ * Either a Boolean (which indicates whether or not an audio track is
99
+ * requested) or a {@link MediaDeviceInfoLike} object providing a hint for the
100
+ * audio track included in the returned MediaStream
101
+ */
102
+ audio?: InputDeviceConstraint;
103
+ /**
104
+ * Either a Boolean (which indicates whether or not an video track is
105
+ * requested) or a {@link MediaDeviceInfoLike} object providing a hint for the
106
+ * video track included in the returned MediaStream
107
+ */
108
+ video?: InputDeviceConstraint;
109
+ }
110
+ export interface DeviceIdConstraints {
111
+ deviceId: ConstrainDOMString;
112
+ }
113
+ export interface MediaConstraintRequirement extends MediaDeviceRequest {
114
+ defaultConstraints: MediaStreamConstraints;
115
+ }
116
+ /**
117
+ * an enum of MediaDeviceKind which can be reused
118
+ *
119
+ * @beta
120
+ */
121
+ export declare enum MediaDeviceKinds {
122
+ /** audio input */
123
+ AUDIOINPUT = "audioinput",
124
+ /** audio output */
125
+ AUDIOOUTPUT = "audiooutput",
126
+ /** video input */
127
+ VIDEOINPUT = "videoinput"
128
+ }
129
+ /**
130
+ * MediaTrackConstraints.facingMode
131
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode}
132
+ */
133
+ export declare const FACING_MODE: readonly ["user", "environment", "left", "right"];
134
+ export type FacingMode = (typeof FACING_MODE)[number];
135
+ /**
136
+ * An enum of failure events for media device
137
+ *
138
+ * @beta
139
+ */
140
+ export declare enum MediaDeviceFailure {
141
+ /**
142
+ * some problem (not user or permissions) occurred which prevented the device
143
+ * from being used.
144
+ */
145
+ AbortError = "AbortError",
146
+ /**
147
+ * Custom error for when selected audio and video device is not found
148
+ */
149
+ AudioAndVideoDeviceNotFoundError = "AudioAndVideoDeviceNotFoundError",
150
+ /**
151
+ * Custom error for selected audio device not found
152
+ */
153
+ AudioInputDeviceNotFoundError = "AudioInputDeviceNotFoundError",
154
+ /**
155
+ * Custom missing constraints error
156
+ */
157
+ MissingConstraintsError = "MissingConstraintsError",
158
+ /**
159
+ * user has blocked access
160
+ */
161
+ NotAllowedError = "NotAllowedError",
162
+ /**
163
+ * the media tracks doesn't match the constraints
164
+ */
165
+ NotFoundError = "NotFoundError",
166
+ /**
167
+ * hardware failure after user granted access
168
+ */
169
+ NotReadableError = "NotReadableError",
170
+ /**
171
+ * no devices met the criteria for the constraints
172
+ */
173
+ OverconstrainedError = "OverconstrainedError",
174
+ /**
175
+ * user has blocked access old chrome
176
+ */
177
+ PermissionDeniedError = "PermissionDeniedError",
178
+ /**
179
+ * User media support disabled by agent
180
+ */
181
+ SecurityError = "SecurityError",
182
+ /**
183
+ * when hardware in use old chrome win os
184
+ */
185
+ TrackStartError = "TrackStartError",
186
+ /**
187
+ * GetUserMedia invalid constraints error
188
+ */
189
+ TypeError = "TypeError",
190
+ /**
191
+ * Custom error for selected video device not found
192
+ */
193
+ VideoInputDeviceNotFoundError = "VideoInputDeviceNotFoundError",
194
+ /**
195
+ * action or function is not supported by the current platform
196
+ */
197
+ NotSupportedError = "NotSupportedError",
198
+ /**
199
+ * Canvas capture is not supported
200
+ */
201
+ StreamTrackNotFound = "StreamTrackNotFound"
202
+ }
203
+ /**
204
+ * Lesser strict type of `MediaStreamTrack`
205
+ *
206
+ * @beta
207
+ */
208
+ export type MediaStreamTrackLike = Pick<MediaStreamTrack, 'id' | 'kind' | 'label' | 'getSettings' | 'stop'>;
209
+ /**
210
+ * Union types of MediaDeviceInfoLike and MediaStreamTrackLike
211
+ */
212
+ export type DeviceOrTrack = MediaDeviceInfoLike | MediaStreamTrackLike;
213
+ /**
214
+ * Holds user media input devices
215
+ *
216
+ * @beta
217
+ */
218
+ export interface MediaInput {
219
+ audioInput?: MediaDeviceInfoLike;
220
+ videoInput?: MediaDeviceInfoLike;
221
+ }
222
+ export type Unsubscribe = () => void;
223
+ export type TrackEventCallback = (track: MediaStreamTrack) => void;
224
+ /**
225
+ * An object contains the event handlers
226
+ */
227
+ export interface StreamTrackEventHandlers {
228
+ ended?: TrackEventCallback;
229
+ mute?: TrackEventCallback;
230
+ unmute?: TrackEventCallback;
231
+ }
232
+ export interface InputDevicePermission {
233
+ audio: PermissionState;
234
+ video: PermissionState;
235
+ }
236
+ interface DisplayVideoTrackConstraint extends MediaTrackConstraintSet {
237
+ displaySurface?: ConstrainDOMString;
238
+ cursor?: ConstrainDOMString;
239
+ }
240
+ interface DisplayAudioTrackConstraint extends MediaTrackConstraintSet {
241
+ restrictOwnAudio?: ConstrainBoolean;
242
+ suppressLocalAudioPlayback?: ConstrainBoolean;
243
+ }
244
+ interface DisplayVideoTrackConstraints extends DisplayVideoTrackConstraint {
245
+ advanced?: DisplayVideoTrackConstraint[];
246
+ }
247
+ interface DisplayAudioTrackConstraints extends DisplayAudioTrackConstraint {
248
+ advanced?: DisplayAudioTrackConstraint[];
249
+ }
250
+ /**
251
+ * The `DisplayMediaStreamOptions` dictionary is used to instruct the user agent
252
+ * what sort of `MediaStreamTracks` may be included in the `MediaStream`
253
+ * returned by `getDisplayMedia`.
254
+ *
255
+ * @see {@link https://w3c.github.io/mediacapture-screen-share/#displaymediastreamoptions}
256
+ */
257
+ export interface DisplayMediaOptions extends DisplayMediaStreamOptions {
258
+ audio?: boolean | DisplayAudioTrackConstraints;
259
+ video?: boolean | DisplayVideoTrackConstraints;
260
+ selfBrowserSurface?: ConstrainDOMString;
261
+ systemAudio?: ConstrainDOMString;
262
+ surfaceSwitching?: ConstrainDOMString;
263
+ monitorTypeSurfaces?: ConstrainDOMString;
264
+ }
265
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * an enum of MediaDeviceKind which can be reused
3
+ *
4
+ * @beta
5
+ */
6
+ export var MediaDeviceKinds;
7
+ (function (MediaDeviceKinds) {
8
+ /** audio input */
9
+ MediaDeviceKinds["AUDIOINPUT"] = "audioinput";
10
+ /** audio output */
11
+ MediaDeviceKinds["AUDIOOUTPUT"] = "audiooutput";
12
+ /** video input */
13
+ MediaDeviceKinds["VIDEOINPUT"] = "videoinput";
14
+ })(MediaDeviceKinds || (MediaDeviceKinds = {}));
15
+ /**
16
+ * MediaTrackConstraints.facingMode
17
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode}
18
+ */
19
+ export const FACING_MODE = ['user', 'environment', 'left', 'right'];
20
+ /**
21
+ * An enum of failure events for media device
22
+ *
23
+ * @beta
24
+ */
25
+ export var MediaDeviceFailure;
26
+ (function (MediaDeviceFailure) {
27
+ /**
28
+ * some problem (not user or permissions) occurred which prevented the device
29
+ * from being used.
30
+ */
31
+ MediaDeviceFailure["AbortError"] = "AbortError";
32
+ /**
33
+ * Custom error for when selected audio and video device is not found
34
+ */
35
+ MediaDeviceFailure["AudioAndVideoDeviceNotFoundError"] = "AudioAndVideoDeviceNotFoundError";
36
+ /**
37
+ * Custom error for selected audio device not found
38
+ */
39
+ MediaDeviceFailure["AudioInputDeviceNotFoundError"] = "AudioInputDeviceNotFoundError";
40
+ /**
41
+ * Custom missing constraints error
42
+ */
43
+ MediaDeviceFailure["MissingConstraintsError"] = "MissingConstraintsError";
44
+ /**
45
+ * user has blocked access
46
+ */
47
+ MediaDeviceFailure["NotAllowedError"] = "NotAllowedError";
48
+ /**
49
+ * the media tracks doesn't match the constraints
50
+ */
51
+ MediaDeviceFailure["NotFoundError"] = "NotFoundError";
52
+ /**
53
+ * hardware failure after user granted access
54
+ */
55
+ MediaDeviceFailure["NotReadableError"] = "NotReadableError";
56
+ /**
57
+ * no devices met the criteria for the constraints
58
+ */
59
+ MediaDeviceFailure["OverconstrainedError"] = "OverconstrainedError";
60
+ /**
61
+ * user has blocked access old chrome
62
+ */
63
+ MediaDeviceFailure["PermissionDeniedError"] = "PermissionDeniedError";
64
+ /**
65
+ * User media support disabled by agent
66
+ */
67
+ MediaDeviceFailure["SecurityError"] = "SecurityError";
68
+ /**
69
+ * when hardware in use old chrome win os
70
+ */
71
+ MediaDeviceFailure["TrackStartError"] = "TrackStartError";
72
+ /**
73
+ * GetUserMedia invalid constraints error
74
+ */
75
+ MediaDeviceFailure["TypeError"] = "TypeError";
76
+ /**
77
+ * Custom error for selected video device not found
78
+ */
79
+ MediaDeviceFailure["VideoInputDeviceNotFoundError"] = "VideoInputDeviceNotFoundError";
80
+ /**
81
+ * action or function is not supported by the current platform
82
+ */
83
+ MediaDeviceFailure["NotSupportedError"] = "NotSupportedError";
84
+ /**
85
+ * Canvas capture is not supported
86
+ */
87
+ MediaDeviceFailure["StreamTrackNotFound"] = "StreamTrackNotFound";
88
+ })(MediaDeviceFailure || (MediaDeviceFailure = {}));
@@ -0,0 +1,37 @@
1
+ import type { MediaDeviceInfoLike } from './types';
2
+ import { MediaDeviceKinds } from './types';
3
+ export declare const isSameDeviceKind: (kind: MediaDeviceKinds) => (device: MediaDeviceInfoLike) => boolean;
4
+ export declare const isAudioInput: (device: MediaDeviceInfoLike) => boolean;
5
+ export declare const isVideoInput: (device: MediaDeviceInfoLike) => boolean;
6
+ export declare const isAudioOutput: (device: MediaDeviceInfoLike) => boolean;
7
+ /**
8
+ * Check if provided device is a permission-granted device by inspecting the
9
+ * device label
10
+ *
11
+ * @param device - The device to check
12
+ *
13
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/label#value}
14
+ **/
15
+ export declare const isDeviceGranted: (device: MediaDeviceInfoLike) => boolean;
16
+ export declare const not: <T = void>(fn: (arg: T) => boolean) => (arg: T) => boolean;
17
+ /**
18
+ * Compare 2 devices to see if they are the same by `deviceId` or `label` as
19
+ * a fallback
20
+ *
21
+ * @beta
22
+ */
23
+ export declare const compareDevices: (deviceInfo: MediaDeviceInfoLike, key?: Exclude<keyof MediaDeviceInfoLike, 'kind' | 'settings'>) => (anotherDeviceInfo: MediaDeviceInfoLike) => boolean;
24
+ /**
25
+ * Lookup the the `device` from `devices` list
26
+ *
27
+ * @remarks
28
+ * When we cannot find the device by `deviceId`, we compare the label as last
29
+ * resort, and return the first one.
30
+ *
31
+ * @param deviceToFind - Provide a device info to be used for the searching
32
+ * @param useFallback - Whether to use `label` as a fallback when there is no
33
+ * match from using `deviceId`
34
+ *
35
+ * @beta
36
+ */
37
+ export declare const findDevice: (deviceToFind: MediaDeviceInfoLike, useFallback?: boolean) => (devices: readonly MediaDeviceInfoLike[]) => MediaDeviceInfoLike | undefined;
package/dist/utils.js ADDED
@@ -0,0 +1,47 @@
1
+ import { MediaDeviceKinds } from './types';
2
+ export const isSameDeviceKind = (kind) => (device) => device.kind === kind;
3
+ export const isAudioInput = isSameDeviceKind(MediaDeviceKinds.AUDIOINPUT);
4
+ export const isVideoInput = isSameDeviceKind(MediaDeviceKinds.VIDEOINPUT);
5
+ export const isAudioOutput = isSameDeviceKind(MediaDeviceKinds.AUDIOOUTPUT);
6
+ /**
7
+ * Check if provided device is a permission-granted device by inspecting the
8
+ * device label
9
+ *
10
+ * @param device - The device to check
11
+ *
12
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/label#value}
13
+ **/
14
+ export const isDeviceGranted = (device) => Boolean(device.label);
15
+ export const not = (fn) => (arg) => !fn(arg);
16
+ /**
17
+ * Compare 2 devices to see if they are the same by `deviceId` or `label` as
18
+ * a fallback
19
+ *
20
+ * @beta
21
+ */
22
+ export const compareDevices = (deviceInfo, key = 'deviceId') => (anotherDeviceInfo) => deviceInfo.kind === anotherDeviceInfo.kind &&
23
+ deviceInfo[key] === anotherDeviceInfo[key];
24
+ /**
25
+ * Lookup the the `device` from `devices` list
26
+ *
27
+ * @remarks
28
+ * When we cannot find the device by `deviceId`, we compare the label as last
29
+ * resort, and return the first one.
30
+ *
31
+ * @param deviceToFind - Provide a device info to be used for the searching
32
+ * @param useFallback - Whether to use `label` as a fallback when there is no
33
+ * match from using `deviceId`
34
+ *
35
+ * @beta
36
+ */
37
+ export const findDevice = (deviceToFind, useFallback = true) => (devices) => {
38
+ const compareIDTo = compareDevices(deviceToFind);
39
+ const found = devices.find((device) => compareIDTo(device));
40
+ if (found || !useFallback) {
41
+ return found;
42
+ }
43
+ // Fallback to use label for the comparison
44
+ // and return the first matched, otherwise `undefined`
45
+ const compareLabelTo = compareDevices(deviceToFind, 'label');
46
+ return devices.find((device) => compareLabelTo(device));
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pexip/media-control",
3
- "version": "17.2.0",
3
+ "version": "17.4.0",
4
4
  "homepage": "https://gitlab.com/pexip/zoo",
5
5
  "bugs": "https://gitlab.com/pexip/zoo/issues",
6
6
  "repository": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "license": "Apache-2.0",
12
12
  "author": "Pexip <pexip@pexip.com>",
13
- "module": "dist/index.mjs",
13
+ "module": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "files": [
16
16
  "dist"
@@ -26,18 +26,18 @@
26
26
  "typecheck": "yarn tsc --noEmit -p tsconfig.build.json"
27
27
  },
28
28
  "dependencies": {
29
- "@pexip/utils": "16.8.0"
29
+ "@pexip/utils": "16.10.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@jest/globals": "^29.5.0",
33
- "@pexip/bundler": "16.4.1",
32
+ "@jest/globals": "^29.7.0",
33
+ "@pexip/bundler": "16.6.0",
34
34
  "@types/core-js": "^2.5.3",
35
35
  "@types/prettier": "^2.0.2",
36
36
  "@types/uuid": "^8.3.0",
37
37
  "@types/webrtc": "^0.0.31",
38
38
  "core-js": "^3.6.5",
39
- "prettier": "^3.0.3",
40
- "typescript": "~5.0.0",
39
+ "prettier": "^3.2.5",
40
+ "typescript": "~5.3.0",
41
41
  "uuid": "^9.0.0"
42
42
  },
43
43
  "publishConfig": {