Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

✨(frontend) add an audio gauge to the microphone select menu

lebaudantoineb780d2845ab7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8144b79b..c6fd47c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to
### Added
- 📈(frontend) capture media diagnostics on media errors
+- ✨(frontend) add an audio gauge to the microphone select menu
### Changed
diff --git a/src/frontend/src/features/rooms/components/Join.tsx b/src/frontend/src/features/rooms/components/Join.tsx
index 3d83c767..f7ee31d6 100644
--- a/src/frontend/src/features/rooms/components/Join.tsx
+++ b/src/frontend/src/features/rooms/components/Join.tsx
@@ -729,6 +729,7 @@ export const Join = ({
<SelectDevice
kind="audioinput"
id={audioDeviceId}
+ track={audioTrack}
onSubmit={async (id) => {
try {
saveAudioInputDeviceId(id)
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioDevicesControl.tsx b/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioDevicesControl.tsx
index b6b52815..914760c8 100644
--- a/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioDevicesControl.tsx
+++ b/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioDevicesControl.tsx
@@ -1,8 +1,12 @@
import { useTranslation } from 'react-i18next'
-import { useTrackToggle, UseTrackToggleProps } from '@livekit/components-react'
+import {
+ useLocalParticipant,
+ useTrackToggle,
+ UseTrackToggleProps,
+} from '@livekit/components-react'
import { Button, Popover } from '@/primitives'
import { RiArrowUpSLine } from '@remixicon/react'
-import { Track } from 'livekit-client'
+import { LocalAudioTrack, Track } from 'livekit-client'
import { ToggleDevice } from './ToggleDevice'
import { css } from '@/styled-system/css'
@@ -51,6 +55,12 @@ export const AudioDevicesControl = ({
...props,
})
+ const { microphoneTrack } = useLocalParticipant()
+ const localAudioTrack =
+ microphoneTrack?.track instanceof LocalAudioTrack
+ ? microphoneTrack.track
+ : undefined
+
const kind = 'audioinput'
const cannotUseDevice = useCannotUseDevice(kind)
const selectLabel = t(`settings.${SettingsDialogExtendedKey.AUDIO}`)
@@ -111,6 +121,7 @@ export const AudioDevicesControl = ({
context="room"
kind={kind}
id={audioDeviceId}
+ track={localAudioTrack}
onSubmit={saveAudioInputDeviceId}
/>
</div>
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioLevelGauge.tsx b/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioLevelGauge.tsx
new file mode 100644
index 00000000..b3da87a7
--- /dev/null
+++ b/src/frontend/src/features/rooms/livekit/components/controls/Device/AudioLevelGauge.tsx
@@ -0,0 +1,154 @@
+import { useEffect, useState } from 'react'
+import { LocalAudioTrack, TrackEvent } from 'livekit-client'
+import { useTrackVolume } from '@livekit/components-react'
+import { useTranslation } from 'react-i18next'
+import { RiMicLine, RiMicOffLine } from '@remixicon/react'
+import { styled } from '@/styled-system/jsx'
+import { Text } from '@/primitives'
+
+const StyledContainer = styled('div', {
+ base: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: '0.75rem',
+ padding: '0.75rem 0.25rem',
+ marginTop: '0.5rem',
+ borderTop: '1px solid',
+ minHeight: '2.5rem',
+ },
+ variants: {
+ theme: {
+ light: {
+ borderColor: 'gray.200',
+ color: 'greyscale.600',
+ },
+ dark: {
+ borderColor: 'primaryDark.300',
+ color: 'rgba(255 255 255 / 0.7)',
+ },
+ },
+ },
+})
+
+const StyledGaugeContainer = styled('div', {
+ base: {
+ flexGrow: 1,
+ height: '0.375rem',
+ borderRadius: '0.1875rem',
+ overflow: 'hidden',
+ },
+ variants: {
+ theme: {
+ light: {
+ backgroundColor: 'greyscale.250',
+ },
+ dark: {
+ backgroundColor: 'rgba(255 255 255 / 0.25)',
+ },
+ },
+ },
+})
+
+const StyledGauge = styled('div', {
+ base: {
+ width: '100%',
+ height: '100%',
+ borderRadius: 'inherit',
+ transformOrigin: 'left center',
+ transform: 'scaleX(0)',
+ transition: 'transform 0.06s linear',
+ },
+ variants: {
+ theme: {
+ light: {
+ backgroundColor: 'primary.500',
+ },
+ dark: {
+ backgroundColor: 'primaryDark.800',
+ },
+ },
+ },
+})
+
+type Theme = 'light' | 'dark'
+
+type AudioLevelGaugeProps = {
+ track?: LocalAudioTrack
+ variant?: Theme
+}
+
+const useIsTrackMuted = (track?: LocalAudioTrack) => {
+ const [isMuted, setIsMuted] = useState(() => track?.isMuted ?? true)
+
+ useEffect(() => {
+ if (!track) {
+ setIsMuted(true)
+ return
+ }
+ setIsMuted(track.isMuted)
+ const onMuted = () => setIsMuted(true)
+ const onUnmuted = () => setIsMuted(false)
+ track.on(TrackEvent.Muted, onMuted)
+ track.on(TrackEvent.Unmuted, onUnmuted)
+ return () => {
+ track.off(TrackEvent.Muted, onMuted)
+ track.off(TrackEvent.Unmuted, onUnmuted)
+ }
+ }, [track])
+
+ return isMuted
+}
+
+const LevelBar = ({
+ track,
+ theme,
+}: {
+ track: LocalAudioTrack
+ theme: Theme
+}) => {
+ const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
+ const volume = useTrackVolume(track, {
+ fftSize: 256,
+ smoothingTimeConstant: 0.7,
+ })
+ const level = Math.min(1, volume)
+
+ return (
+ <>
+ <RiMicLine size={18} aria-hidden="true" />
+ <StyledGaugeContainer
+ theme={theme}
+ role="img"
+ aria-label={t('audioinput.level')}
+ >
+ <StyledGauge theme={theme} style={{ transform: `scaleX(${level})` }} />
+ </StyledGaugeContainer>
+ </>
+ )
+}
+
+export const AudioLevelGauge = ({
+ track,
+ variant = 'light',
+}: AudioLevelGaugeProps) => {
+ const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
+ const isMuted = useIsTrackMuted(track)
+ const showMutedHint = !track || isMuted
+
+ return (
+ <StyledContainer theme={variant}>
+ {showMutedHint ? (
+ <>
+ <RiMicOffLine size={18} aria-hidden="true" />
+ <Text variant="bodyXsMedium">{t('audioinput.muteTest')}</Text>
+ </>
+ ) : (
+ <LevelBar
+ key={track.mediaStreamTrack?.id}
+ track={track}
+ theme={variant}
+ />
+ )}
+ </StyledContainer>
+ )
+}
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/Device/SelectDevice.tsx b/src/frontend/src/features/rooms/livekit/components/controls/Device/SelectDevice.tsx
index 37517b3b..b1b2a672 100644
--- a/src/frontend/src/features/rooms/livekit/components/controls/Device/SelectDevice.tsx
+++ b/src/frontend/src/features/rooms/livekit/components/controls/Device/SelectDevice.tsx
@@ -5,6 +5,8 @@ import { Select, SelectProps } from '@/primitives/Select'
import type { Placement } from '@react-types/overlays'
import { useCannotUseDevice } from '../../../hooks/useCannotUseDevice'
import { useDeviceIcons } from '@/features/rooms/livekit/hooks/useDeviceIcons'
+import type { LocalAudioTrack } from 'livekit-client'
+import { AudioLevelGauge } from './AudioLevelGauge'
type DeviceItems = Array<{ value: string; label: string }>
@@ -18,6 +20,7 @@ type SelectDeviceProps = {
onSubmit?: (id: string) => void
kind: MediaDeviceKind
context?: 'join' | 'room'
+ track?: LocalAudioTrack
}
type SelectDevicePermissionsProps<T> = SelectDeviceProps &
@@ -28,6 +31,7 @@ const SelectDevicePermissions = <T extends string | number>({
kind,
onSubmit,
iconComponent,
+ track,
...props
}: SelectDevicePermissionsProps<T>) => {
const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
@@ -74,6 +78,11 @@ const SelectDevicePermissions = <T extends string | number>({
await setActiveMediaDevice(key as string)
onSubmit?.(key as string)
}}
+ menuFooter={
+ kind === 'audioinput' ? (
+ <AudioLevelGauge track={track} variant={props.variant} />
+ ) : undefined
+ }
{...props}
/>
)
@@ -84,6 +93,7 @@ export const SelectDevice = ({
onSubmit,
kind,
context = 'join',
+ track,
}: SelectDeviceProps) => {
const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
@@ -116,6 +126,7 @@ export const SelectDevice = ({
id={id}
onSubmit={onSubmit}
kind={kind}
+ track={track}
iconComponent={deviceIcons.select}
{...contextProps}
/>
diff --git a/src/frontend/src/locales/de/rooms.json b/src/frontend/src/locales/de/rooms.json
index 73a137bc..2d27256f 100644
--- a/src/frontend/src/locales/de/rooms.json
+++ b/src/frontend/src/locales/de/rooms.json
@@ -29,6 +29,8 @@
},
"audioinput": {
"choose": "Mikrofon auswählen",
+ "level": "Mikrofon-Eingangspegel",
+ "muteTest": "Aktivieren Sie Ihr Mikrofon, um es zu testen",
"permissionsNeeded": "Mikrofon auswählen – Berechtigung erforderlich",
"disable": "Mikrofon deaktivieren",
"enable": "Mikrofon aktivieren",
diff --git a/src/frontend/src/locales/en/rooms.json b/src/frontend/src/locales/en/rooms.json
index 62b34e25..21a13865 100644
--- a/src/frontend/src/locales/en/rooms.json
+++ b/src/frontend/src/locales/en/rooms.json
@@ -29,6 +29,8 @@
},
"audioinput": {
"choose": "Select microphone",
+ "level": "Microphone input level",
+ "muteTest": "Turn on your microphone to test it",
"permissionsNeeded": "Select microphone - permission needed",
"disable": "Disable microphone",
"enable": "Enable microphone",
diff --git a/src/frontend/src/locales/fr/rooms.json b/src/frontend/src/locales/fr/rooms.json
index 8621cb1d..00519708 100644
--- a/src/frontend/src/locales/fr/rooms.json
+++ b/src/frontend/src/locales/fr/rooms.json
@@ -29,6 +29,8 @@
},
"audioinput": {
"choose": "Choisir le micro",
+ "level": "Niveau d'entrée du micro",
+ "muteTest": "Activez votre micro pour le tester",
"permissionsNeeded": "Choisir le micro - autorisations nécessaires",
"disable": "Désactiver le micro",
"enable": "Activer le micro",
diff --git a/src/frontend/src/locales/nl/rooms.json b/src/frontend/src/locales/nl/rooms.json
index ec5afc04..744d7384 100644
--- a/src/frontend/src/locales/nl/rooms.json
+++ b/src/frontend/src/locales/nl/rooms.json
@@ -29,6 +29,8 @@
},
"audioinput": {
"choose": "Selecteer microfoon",
+ "level": "Microfoon-ingangsniveau",
+ "muteTest": "Zet je microfoon aan om deze te testen",
"permissionsNeeded": "Selecteer microfoon - Toestemming vereist",
"disable": "Microfoon dempen",
"enable": "Microfoon dempen opheffen",
diff --git a/src/frontend/src/primitives/Select.tsx b/src/frontend/src/primitives/Select.tsx
index db8b2a5e..b97e0045 100644
--- a/src/frontend/src/primitives/Select.tsx
+++ b/src/frontend/src/primitives/Select.tsx
@@ -99,6 +99,7 @@ export type SelectProps<T> = Omit<
errors?: ReactNode
placement?: Placement
variant?: 'light' | 'dark'
+ menuFooter?: ReactNode
}
export const Select = <T extends string | number>({
@@ -108,56 +109,62 @@ export const Select = <T extends string | number>({
errors,
placement,
variant = 'light',
+ menuFooter,
...props
}: SelectProps<T>) => {
const IconComponent = iconComponent
const { t } = useTranslation('global')
return (
<RACSelect {...props}>
- {label}
- <StyledButton variant={variant}>
- {!!IconComponent && (
- <StyledIcon>
- <IconComponent size={18} />
- </StyledIcon>
- )}
- <StyledSelectValue />
- <RiArrowDropDownLine
- aria-hidden="true"
- className={css({ flexShrink: 0 })}
- />
- </StyledButton>
- <StyledPopover placement={placement}>
- <Box size="sm" type="popover" variant={variant}>
- <ListBox>
- {items.map((item) => (
- <ListBoxItem
- className={
- menuRecipe({
- extraPadding: true,
- variant: variant,
- }).item
- }
- id={item.value}
- key={item.value}
- textValue={
- typeof item.label === 'string' ? item.label : undefined
- }
- >
- {({ isSelected }) => (
- <>
- {item.label}
- {isSelected && (
- <VisuallyHidden>, {t('selected')}</VisuallyHidden>
+ {({ isOpen }) => (
+ <>
+ {label}
+ <StyledButton variant={variant}>
+ {!!IconComponent && (
+ <StyledIcon>
+ <IconComponent size={18} />
+ </StyledIcon>
+ )}
+ <StyledSelectValue />
+ <RiArrowDropDownLine
+ aria-hidden="true"
+ className={css({ flexShrink: 0 })}
+ />
+ </StyledButton>
+ <StyledPopover placement={placement}>
+ <Box size="sm" type="popover" variant={variant}>
+ <ListBox>
+ {items.map((item) => (
+ <ListBoxItem
+ className={
+ menuRecipe({
+ extraPadding: true,
+ variant: variant,
+ }).item
+ }
+ id={item.value}
+ key={item.value}
+ textValue={
+ typeof item.label === 'string' ? item.label : undefined
+ }
+ >
+ {({ isSelected }) => (
+ <>
+ {item.label}
+ {isSelected && (
+ <VisuallyHidden>, {t('selected')}</VisuallyHidden>
+ )}
+ </>
)}
- </>
- )}
- </ListBoxItem>
- ))}
- </ListBox>
- </Box>
- </StyledPopover>
- {errors}
+ </ListBoxItem>
+ ))}
+ </ListBox>
+ {isOpen && menuFooter}
+ </Box>
+ </StyledPopover>
+ {errors}
+ </>
+ )}
</RACSelect>
)
}