|
@@ -5,6 +5,7 @@ import { ISettingsState } from '../settings/reducer';
|
5
|
5
|
import { setNewAudioOutputDevice } from '../sounds/functions.web';
|
6
|
6
|
import { parseURLParams } from '../util/parseURLParams';
|
7
|
7
|
|
|
8
|
+import { DEVICE_LABEL_PREFIXES_TO_IGNORE } from './constants';
|
8
|
9
|
import logger from './logger';
|
9
|
10
|
import { IDevicesState } from './types';
|
10
|
11
|
|
|
@@ -176,6 +177,74 @@ export function filterAudioDevices(devices: MediaDeviceInfo[]) {
|
176
|
177
|
return devices.filter(device => device.kind === 'audioinput');
|
177
|
178
|
}
|
178
|
179
|
|
|
180
|
+/**
|
|
181
|
+ * Filters the devices that start with one of the prefixes from DEVICE_LABEL_PREFIXES_TO_IGNORE.
|
|
182
|
+ *
|
|
183
|
+ * @param {MediaDeviceInfo[]} devices - The devices to be filtered.
|
|
184
|
+ * @returns {MediaDeviceInfo[]} - The filtered devices.
|
|
185
|
+ */
|
|
186
|
+export function filterIgnoredDevices(devices: MediaDeviceInfo[] = []) {
|
|
187
|
+ const ignoredDevices: MediaDeviceInfo[] = [];
|
|
188
|
+ const filteredDevices = devices.filter(device => {
|
|
189
|
+ if (!device.label) {
|
|
190
|
+ return true;
|
|
191
|
+ }
|
|
192
|
+
|
|
193
|
+ if (DEVICE_LABEL_PREFIXES_TO_IGNORE.find(prefix => device.label?.startsWith(prefix))) {
|
|
194
|
+ ignoredDevices.push(device);
|
|
195
|
+
|
|
196
|
+ return false;
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ return true;
|
|
200
|
+ });
|
|
201
|
+
|
|
202
|
+ return {
|
|
203
|
+ filteredDevices,
|
|
204
|
+ ignoredDevices
|
|
205
|
+ };
|
|
206
|
+}
|
|
207
|
+
|
|
208
|
+/**
|
|
209
|
+ * Check if the passed device arrays are different.
|
|
210
|
+ *
|
|
211
|
+ * @param {MediaDeviceInfo[]} devices1 - Array with devices to be compared.
|
|
212
|
+ * @param {MediaDeviceInfo[]} devices2 - Array with devices to be compared.
|
|
213
|
+ * @returns {boolean} - True if the device arrays are different and false otherwise.
|
|
214
|
+*/
|
|
215
|
+export function areDevicesDifferent(devices1: MediaDeviceInfo[] = [], devices2: MediaDeviceInfo[] = []) {
|
|
216
|
+ if (devices1.length !== devices2.length) {
|
|
217
|
+ return true;
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ for (let i = 0; i < devices1.length; i++) {
|
|
221
|
+ const device1 = devices1[i];
|
|
222
|
+ const found = devices2.find(({ deviceId, groupId, kind, label }) =>
|
|
223
|
+ device1.deviceId === deviceId
|
|
224
|
+ && device1.groupId === groupId
|
|
225
|
+ && device1.kind === kind
|
|
226
|
+ && device1.label === label
|
|
227
|
+ );
|
|
228
|
+
|
|
229
|
+ if (!found) {
|
|
230
|
+ return true;
|
|
231
|
+ }
|
|
232
|
+ }
|
|
233
|
+
|
|
234
|
+ return false;
|
|
235
|
+}
|
|
236
|
+
|
|
237
|
+/**
|
|
238
|
+ * Flattens the availableDevices from redux.
|
|
239
|
+ *
|
|
240
|
+ * @param {IDevicesState.availableDevices} devices - The available devices from redux.
|
|
241
|
+ * @returns {MediaDeviceInfo[]} - The flattened array of devices.
|
|
242
|
+ */
|
|
243
|
+export function flattenAvailableDevices(
|
|
244
|
+ { audioInput = [], audioOutput = [], videoInput = [] }: IDevicesState['availableDevices']) {
|
|
245
|
+ return audioInput.concat(audioOutput).concat(videoInput);
|
|
246
|
+}
|
|
247
|
+
|
179
|
248
|
/**
|
180
|
249
|
* We want to strip any device details that are not very user friendly, like usb ids put in brackets at the end.
|
181
|
250
|
*
|
|
@@ -240,6 +309,35 @@ export function getVideoDeviceIds(state: IReduxState) {
|
240
|
309
|
return state['features/base/devices'].availableDevices.videoInput?.map(({ deviceId }) => deviceId);
|
241
|
310
|
}
|
242
|
311
|
|
|
312
|
+/**
|
|
313
|
+ * Converts an array of device info objects into string.
|
|
314
|
+ *
|
|
315
|
+ * @param {MediaDeviceInfo[]} devices - The devices.
|
|
316
|
+ * @returns {string}
|
|
317
|
+ */
|
|
318
|
+function devicesToStr(devices?: MediaDeviceInfo[]) {
|
|
319
|
+ return devices?.map(device => `\t\t${device.label}[${device.deviceId}]`).join('\n');
|
|
320
|
+}
|
|
321
|
+
|
|
322
|
+/**
|
|
323
|
+ * Logs an array of devices.
|
|
324
|
+ *
|
|
325
|
+ * @param {MediaDeviceInfo[]} devices - The array of devices.
|
|
326
|
+ * @param {string} title - The title that will be printed in the log.
|
|
327
|
+ * @returns {void}
|
|
328
|
+ */
|
|
329
|
+export function logDevices(devices: MediaDeviceInfo[], title = '') {
|
|
330
|
+ const deviceList = groupDevicesByKind(devices);
|
|
331
|
+ const audioInputs = devicesToStr(deviceList.audioInput);
|
|
332
|
+ const audioOutputs = devicesToStr(deviceList.audioOutput);
|
|
333
|
+ const videoInputs = devicesToStr(deviceList.videoInput);
|
|
334
|
+
|
|
335
|
+ logger.debug(`${title}:\n`
|
|
336
|
+ + `audioInput:\n${audioInputs}\n`
|
|
337
|
+ + `audioOutput:\n${audioOutputs}\n`
|
|
338
|
+ + `videoInput:\n${videoInputs}`);
|
|
339
|
+}
|
|
340
|
+
|
243
|
341
|
/**
|
244
|
342
|
* Set device id of the audio output device which is currently in use.
|
245
|
343
|
* Empty string stands for default device.
|