// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { Modal } from './Modal'; import { LocalizerType } from '../types/Util'; import { AudioDevice, CallingDeviceType, ChangeIODevicePayloadType, MediaDeviceSettings, } from '../types/Calling'; import { Theme } from '../util/theme'; export type Props = MediaDeviceSettings & { changeIODevice: (payload: ChangeIODevicePayloadType) => void; i18n: LocalizerType; toggleSettings: () => void; }; function localizeDefault(i18n: LocalizerType, deviceLabel: string): string { return deviceLabel.toLowerCase().startsWith('default') ? deviceLabel.replace( /default/i, i18n('callingDeviceSelection__select--default') ) : deviceLabel; } function renderAudioOptions( devices: Array, i18n: LocalizerType, selectedDevice: AudioDevice | undefined ): JSX.Element { if (!devices.length) { return ( ); } return ( <> {devices.map((device: AudioDevice) => { const isSelected = selectedDevice && selectedDevice.index === device.index; return ( ); })} ); } function renderVideoOptions( devices: Array, i18n: LocalizerType, selectedCamera: string | undefined ): JSX.Element { if (!devices.length) { return ( ); } return ( <> {devices.map((device: MediaDeviceInfo) => { const isSelected = selectedCamera === device.deviceId; return ( ); })} ); } function createAudioChangeHandler( devices: Array, changeIODevice: (payload: ChangeIODevicePayloadType) => void, type: CallingDeviceType.SPEAKER | CallingDeviceType.MICROPHONE ) { return (ev: React.FormEvent): void => { changeIODevice({ type, selectedDevice: devices[Number(ev.currentTarget.value)], }); }; } function createCameraChangeHandler( changeIODevice: (payload: ChangeIODevicePayloadType) => void ) { return (ev: React.FormEvent): void => { changeIODevice({ type: CallingDeviceType.CAMERA, selectedDevice: String(ev.currentTarget.value), }); }; } export const CallingDeviceSelection = ({ availableCameras, availableMicrophones, availableSpeakers, changeIODevice, i18n, selectedCamera, selectedMicrophone, selectedSpeaker, toggleSettings, }: Props): JSX.Element => { const selectedMicrophoneIndex = selectedMicrophone ? selectedMicrophone.index : undefined; const selectedSpeakerIndex = selectedSpeaker ? selectedSpeaker.index : undefined; return (

{i18n('callingDeviceSelection__settings')}

); };