Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show selected audio device indicator in header for mweb #2053

Merged
merged 12 commits into from
Oct 31, 2023
1 change: 1 addition & 0 deletions packages/react-icons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export { default as BarIcon } from './BarIcon';
export { default as BatteryFullIcon } from './BatteryFullIcon';
export { default as BatteryPowerIcon } from './BatteryPowerIcon';
export { default as BillIcon } from './BillIcon';
export { default as BluetoothIcon } from './BluetoothIcon';
export { default as BoltIcon } from './BoltIcon';
export { default as BookIcon } from './BookIcon';
export { default as BookmarkIcon } from './BookmarkIcon';
Expand Down
39 changes: 33 additions & 6 deletions packages/roomkit-react/src/Prebuilt/components/Header/common.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useMedia } from 'react-use';
import {
DeviceType,
selectIsLocalVideoEnabled,
Expand All @@ -8,12 +9,20 @@ import {
useHMSActions,
useHMSStore,
} from '@100mslive/react-sdk';
import { CameraFlipIcon, CheckIcon, CrossIcon, SpeakerIcon } from '@100mslive/react-icons';
import {
BluetoothIcon,
CameraFlipIcon,
CheckIcon,
CrossIcon,
HeadphonesIcon,
SpeakerIcon,
} from '@100mslive/react-icons';
import { HorizontalDivider } from '../../../Divider';
import { Label } from '../../../Label';
import { Box, Flex } from '../../../Layout';
import { Sheet } from '../../../Sheet';
import { Text } from '../../../Text';
import { config as cssConfig } from '../../../Theme';
import IconButton from '../../IconButton';
import { ToastManager } from '../Toast/ToastManager';

Expand Down Expand Up @@ -52,23 +61,43 @@ export const CamaraFlipActions = () => {
export const AudioOutputActions = () => {
const { allDevices, selectedDeviceIDs, updateDevice } = useDevices();
const { audioOutput } = allDevices;
const isMobile = useMedia(cssConfig.media.md);
// don't show speaker selector where the API is not supported, and use
// a generic word("Audio") for Mic. In some cases(Chrome Android for e.g.) this changes both mic and speaker keeping them in sync.
const shouldShowAudioOutput = 'setSinkId' in HTMLMediaElement.prototype;

/**
* Chromium browsers return an audioOutput with empty label when no permissions are given
*/
const audioOutputFiltered = audioOutput?.filter(item => !!item.label) ?? [];
const audioOutputLabel = audioOutput?.filter(item => item.deviceId === selectedDeviceIDs.audioOutput);
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved

if (!shouldShowAudioOutput || !audioOutputFiltered?.length > 0) {
return null;
}
let AudioOutputIcon = <SpeakerIcon />;
if (
audioOutputLabel &&
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
audioOutputLabel.length > 0 &&
audioOutputLabel[0].label.toLowerCase().includes('bluetooth')
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
) {
AudioOutputIcon = <BluetoothIcon />;
} else if (
audioOutputLabel &&
audioOutputLabel.length > 0 &&
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved
audioOutputLabel[0].label.toLowerCase().includes('headphone')
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
) {
AudioOutputIcon = <HeadphonesIcon />;
}
return (
<AudioOutputSelectionSheet
outputDevices={audioOutput}
outputSelected={selectedDeviceIDs.outputDevices}
outputSelected={selectedDeviceIDs.audioOutput}
onChange={async deviceId => {
try {
if (window.__hms && isMobile) {
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved
// refresh device as `devicechange` listener won't work in mobile device
await window.__hms.actions.refreshDevices();
}
await updateDevice({
deviceId,
deviceType: DeviceType.audioOutput,
Expand All @@ -82,9 +111,7 @@ export const AudioOutputActions = () => {
}}
>
<Box>
<IconButton>
<SpeakerIcon />
</IconButton>
<IconButton>{AudioOutputIcon} </IconButton>
</Box>
</AudioOutputSelectionSheet>
);
Expand Down
Loading