@stream-io/video-client 0.4.5 → 0.4.6

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.
@@ -1,13 +1,10 @@
1
1
  import {
2
- combineLatest,
3
2
  concatMap,
4
3
  debounceTime,
5
- filter,
6
4
  from,
7
5
  map,
8
6
  merge,
9
7
  Observable,
10
- pairwise,
11
8
  shareReplay,
12
9
  } from 'rxjs';
13
10
  import { getLogger } from '../logger';
@@ -61,8 +58,7 @@ const getDevices = (
61
58
  /**
62
59
  * [Tells if the browser supports audio output change on 'audio' elements](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId).
63
60
  *
64
- * @angular It's recommended to use the [`DeviceManagerService`](./DeviceManagerService.md) for a higher level API, use this low-level method only if the `DeviceManagerService` doesn't suit your requirements.
65
- */
61
+ * */
66
62
  export const checkIfAudioOutputChangeSupported = () => {
67
63
  if (typeof document === 'undefined') return false;
68
64
  const element = document.createElement('audio');
@@ -258,124 +254,16 @@ export const getScreenShareStream = async (
258
254
  }
259
255
  };
260
256
 
261
- const watchForDisconnectedDevice = (
262
- kind: MediaDeviceKind,
263
- deviceId$: Observable<string | undefined>,
264
- ) => {
265
- let devices$;
266
- switch (kind) {
267
- case 'audioinput':
268
- devices$ = getAudioDevices();
269
- break;
270
- case 'videoinput':
271
- devices$ = getVideoDevices();
272
- break;
273
- case 'audiooutput':
274
- devices$ = getAudioOutputDevices();
275
- break;
276
- }
277
- return combineLatest([devices$, deviceId$]).pipe(
278
- filter(
279
- ([devices, deviceId]) =>
280
- !!deviceId && !devices.find((d) => d.deviceId === deviceId),
281
- ),
282
- map(() => true),
283
- );
284
- };
285
-
286
- /**
287
- * Notifies the subscriber if a given 'audioinput' device is disconnected
288
- *
289
- * @angular It's recommended to use the [`DeviceManagerService`](./DeviceManagerService.md) for a higher level API, use this low-level method only if the `DeviceManagerService` doesn't suit your requirements.
290
- * @param deviceId$ an Observable that specifies which device to watch for
291
- * @returns
292
- */
293
- export const watchForDisconnectedAudioDevice = (
294
- deviceId$: Observable<string | undefined>,
295
- ) => {
296
- return watchForDisconnectedDevice('audioinput', deviceId$);
297
- };
298
-
299
- /**
300
- * Notifies the subscriber if a given 'videoinput' device is disconnected
301
- *
302
- * @angular It's recommended to use the [`DeviceManagerService`](./DeviceManagerService.md) for a higher level API, use this low-level method only if the `DeviceManagerService` doesn't suit your requirements.
303
- * @param deviceId$ an Observable that specifies which device to watch for
304
- * @returns
305
- */
306
- export const watchForDisconnectedVideoDevice = (
307
- deviceId$: Observable<string | undefined>,
308
- ) => {
309
- return watchForDisconnectedDevice('videoinput', deviceId$);
310
- };
311
-
312
- /**
313
- * Notifies the subscriber if a given 'audiooutput' device is disconnected
314
- *
315
- * @angular It's recommended to use the [`DeviceManagerService`](./DeviceManagerService.md) for a higher level API, use this low-level method only if the `DeviceManagerService` doesn't suit your requirements.
316
- * @param deviceId$ an Observable that specifies which device to watch for
317
- * @returns
318
- */
319
- export const watchForDisconnectedAudioOutputDevice = (
320
- deviceId$: Observable<string | undefined>,
321
- ) => {
322
- return watchForDisconnectedDevice('audiooutput', deviceId$);
323
- };
324
-
325
- const watchForAddedDefaultDevice = (kind: MediaDeviceKind) => {
326
- let devices$;
327
- switch (kind) {
328
- case 'audioinput':
329
- devices$ = getAudioDevices();
330
- break;
331
- case 'videoinput':
332
- devices$ = getVideoDevices();
333
- break;
334
- case 'audiooutput':
335
- devices$ = getAudioOutputDevices();
336
- break;
337
- default:
338
- throw new Error('Unknown MediaDeviceKind', kind);
339
- }
340
-
341
- return devices$.pipe(
342
- pairwise(),
343
- filter(([prev, current]) => {
344
- const prevDefault = prev.find((device) => device.deviceId === 'default');
345
- const currentDefault = current.find(
346
- (device) => device.deviceId === 'default',
347
- );
348
- return !!(
349
- current.length > prev.length &&
350
- prevDefault &&
351
- currentDefault &&
352
- prevDefault.groupId !== currentDefault.groupId
353
- );
354
- }),
355
- map(() => true),
356
- );
357
- };
358
-
359
- /**
360
- * Notifies the subscriber about newly added default audio input device.
361
- * @returns Observable<boolean>
362
- */
363
- export const watchForAddedDefaultAudioDevice = () =>
364
- watchForAddedDefaultDevice('audioinput');
365
-
366
- /**
367
- * Notifies the subscriber about newly added default audio output device.
368
- * @returns Observable<boolean>
369
- */
370
- export const watchForAddedDefaultAudioOutputDevice = () =>
371
- watchForAddedDefaultDevice('audiooutput');
372
-
373
- /**
374
- * Notifies the subscriber about newly added default video input device.
375
- * @returns Observable<boolean>
376
- */
377
- export const watchForAddedDefaultVideoDevice = () =>
378
- watchForAddedDefaultDevice('videoinput');
257
+ export const deviceIds$ =
258
+ typeof navigator !== 'undefined' &&
259
+ typeof navigator.mediaDevices !== 'undefined'
260
+ ? memoizedObservable(() =>
261
+ merge(
262
+ from(navigator.mediaDevices.enumerateDevices()),
263
+ getDeviceChangeObserver(),
264
+ ).pipe(shareReplay(1)),
265
+ )()
266
+ : undefined;
379
267
 
380
268
  /**
381
269
  * Deactivates MediaStream (stops and removes tracks) to be later garbage collected