Skip to content

Commit

Permalink
remove unused device management helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 9, 2023
1 parent c514410 commit aebc917
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 137 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/devices/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { vi } from 'vitest';
import { CallingState, CallState } from '../../store';
import { OwnCapability } from '../../gen/coordinator';
import { Call } from '../../Call';
import { BehaviorSubject, Subject } from 'rxjs';
import { Subject } from 'rxjs';

export const mockVideoDevices = [
{
Expand Down
137 changes: 1 addition & 136 deletions packages/client/src/devices/devices.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
combineLatest,
concatMap,
debounceTime,
filter,
from,
map,
merge,
Observable,
pairwise,
shareReplay,
} from 'rxjs';
import { getLogger } from '../logger';
Expand Down Expand Up @@ -61,8 +58,7 @@ const getDevices = (
/**
* [Tells if the browser supports audio output change on 'audio' elements](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId).
*
* @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.
*/
* */
export const checkIfAudioOutputChangeSupported = () => {
if (typeof document === 'undefined') return false;
const element = document.createElement('audio');
Expand Down Expand Up @@ -269,137 +265,6 @@ export const deviceIds$ =
)()
: undefined;

export const watchForDisconnectedDevice = (
kind: MediaDeviceKind,
deviceId$: Observable<string | undefined>,
) => {
let devices$;
switch (kind) {
case 'audioinput':
devices$ = getAudioDevices();
break;
case 'videoinput':
devices$ = getVideoDevices();
break;
case 'audiooutput':
devices$ = getAudioOutputDevices();
break;
}
return combineLatest([devices$, deviceId$]).pipe(
filter(
([devices, deviceId]) =>
!!deviceId && !devices.find((d) => d.deviceId === deviceId),
),
map(() => true),
);
};

/**
* Notifies the subscriber if a given 'audioinput' device is disconnected
*
* @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.
* @param deviceId$ an Observable that specifies which device to watch for
* @returns
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForDisconnectedAudioDevice = (
deviceId$: Observable<string | undefined>,
) => {
return watchForDisconnectedDevice('audioinput', deviceId$);
};

/**
* Notifies the subscriber if a given 'videoinput' device is disconnected
*
* @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.
* @param deviceId$ an Observable that specifies which device to watch for
* @returns
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForDisconnectedVideoDevice = (
deviceId$: Observable<string | undefined>,
) => {
return watchForDisconnectedDevice('videoinput', deviceId$);
};

/**
* Notifies the subscriber if a given 'audiooutput' device is disconnected
*
* @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.
* @param deviceId$ an Observable that specifies which device to watch for
* @returns
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForDisconnectedAudioOutputDevice = (
deviceId$: Observable<string | undefined>,
) => {
return watchForDisconnectedDevice('audiooutput', deviceId$);
};

const watchForAddedDefaultDevice = (kind: MediaDeviceKind) => {
let devices$;
switch (kind) {
case 'audioinput':
devices$ = getAudioDevices();
break;
case 'videoinput':
devices$ = getVideoDevices();
break;
case 'audiooutput':
devices$ = getAudioOutputDevices();
break;
default:
throw new Error('Unknown MediaDeviceKind', kind);
}

return devices$.pipe(
pairwise(),
filter(([prev, current]) => {
const prevDefault = prev.find((device) => device.deviceId === 'default');
const currentDefault = current.find(
(device) => device.deviceId === 'default',
);
return !!(
current.length > prev.length &&
prevDefault &&
currentDefault &&
prevDefault.groupId !== currentDefault.groupId
);
}),
map(() => true),
);
};

/**
* Notifies the subscriber about newly added default audio input device.
* @returns Observable<boolean>
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForAddedDefaultAudioDevice = () =>
watchForAddedDefaultDevice('audioinput');

/**
* Notifies the subscriber about newly added default audio output device.
* @returns Observable<boolean>
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForAddedDefaultAudioOutputDevice = () =>
watchForAddedDefaultDevice('audiooutput');

/**
* Notifies the subscriber about newly added default video input device.
* @returns Observable<boolean>
*
* @deprecated use the [new device API](https://getstream.io/video/docs/javascript/guides/camera-and-microphone/)
*/
export const watchForAddedDefaultVideoDevice = () =>
watchForAddedDefaultDevice('videoinput');

/**
* Deactivates MediaStream (stops and removes tracks) to be later garbage collected
*
Expand Down

0 comments on commit aebc917

Please sign in to comment.