Skip to content

armgit / meet

Public Imported from GitHub
0

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

🚸(frontend) simplify audio and video select inputs

lebaudantoine5e74fce6e276
diff --git a/src/frontend/src/features/rooms/components/Join.tsx b/src/frontend/src/features/rooms/components/Join.tsx
index 0657ec97..575be7b7 100644
--- a/src/frontend/src/features/rooms/components/Join.tsx
+++ b/src/frontend/src/features/rooms/components/Join.tsx
@@ -16,8 +16,8 @@ export const Join = ({
<PreJoin
persistUserChoices
onSubmit={onSubmit}
- micLabel={t('join.micLabel')}
- camLabel={t('join.camlabel')}
+ micLabel={t('join.audioinput.label')}
+ camLabel={t('join.videoinput.label')}
joinLabel={t('join.joinLabel')}
userLabel={t('join.userLabel')}
/>
diff --git a/src/frontend/src/features/rooms/livekit/components/controls/SelectToggleDevice.tsx b/src/frontend/src/features/rooms/livekit/components/controls/SelectToggleDevice.tsx
new file mode 100644
index 00000000..99a1ff71
--- /dev/null
+++ b/src/frontend/src/features/rooms/livekit/components/controls/SelectToggleDevice.tsx
@@ -0,0 +1,120 @@
+import { useTranslation } from 'react-i18next'
+import {
+ useMediaDeviceSelect,
+ useTrackToggle,
+ UseTrackToggleProps,
+} from '@livekit/components-react'
+import { HStack } from '@/styled-system/jsx'
+import { Button, Menu, MenuList, ToggleButton } from '@/primitives'
+import {
+ RemixiconComponentType,
+ RiArrowDownSLine,
+ RiMicLine,
+ RiMicOffLine,
+ RiVideoOffLine,
+ RiVideoOnLine,
+} from '@remixicon/react'
+import { Track } from 'livekit-client'
+import React from 'react'
+
+export type ToggleSource = Exclude<
+ Track.Source,
+ Track.Source.ScreenShareAudio | Track.Source.Unknown
+>
+
+type SelectToggleSource = Exclude<ToggleSource, Track.Source.ScreenShare>
+
+type SelectToggleDeviceConfig = {
+ kind: MediaDeviceKind
+ iconOn: RemixiconComponentType
+ iconOff: RemixiconComponentType
+}
+
+type SelectToggleDeviceConfigMap = {
+ [key in SelectToggleSource]: SelectToggleDeviceConfig
+}
+
+const selectToggleDeviceConfig: SelectToggleDeviceConfigMap = {
+ [Track.Source.Microphone]: {
+ kind: 'audioinput',
+ iconOn: RiMicLine,
+ iconOff: RiMicOffLine,
+ },
+ [Track.Source.Camera]: {
+ kind: 'videoinput',
+ iconOn: RiVideoOnLine,
+ iconOff: RiVideoOffLine,
+ },
+}
+
+type SelectToggleDeviceProps<T extends ToggleSource> =
+ UseTrackToggleProps<T> & {
+ onActiveDeviceChange: (deviceId: string) => void
+ source: SelectToggleSource
+ }
+
+export const SelectToggleDevice = <T extends ToggleSource>({
+ onActiveDeviceChange,
+ ...props
+}: SelectToggleDeviceProps<T>) => {
+ const config = selectToggleDeviceConfig[props.source]
+ if (!config) {
+ throw new Error('Invalid source')
+ }
+
+ const { t } = useTranslation('rooms', { keyPrefix: 'join' })
+ const { buttonProps, enabled } = useTrackToggle(props)
+
+ const { kind, iconOn, iconOff } = config
+
+ const { devices, activeDeviceId, setActiveMediaDevice } =
+ useMediaDeviceSelect({ kind })
+
+ const toggleLabel = t(enabled ? 'disable' : 'enable', {
+ keyPrefix: `join.${kind}`,
+ })
+
+ const selectLabel = t('choose', { keyPrefix: `join.${kind}` })
+ const Icon = enabled ? iconOn : iconOff
+
+ return (
+ <HStack gap={0}>
+ <ToggleButton
+ isSelected={enabled}
+ variant={enabled ? undefined : 'danger'}
+ toggledStyles={false}
+ onPress={(e) =>
+ buttonProps.onClick?.(
+ e as unknown as React.MouseEvent<HTMLButtonElement>
+ )
+ }
+ aria-label={toggleLabel}
+ tooltip={toggleLabel}
+ groupPosition="left"
+ >
+ <Icon />
+ </ToggleButton>
+ <Menu>
+ <Button
+ tooltip={selectLabel}
+ aria-label={selectLabel}
+ groupPosition="right"
+ square
+ >
+ <RiArrowDownSLine />
+ </Button>
+ <MenuList
+ items={devices.map((d) => ({
+ value: d.deviceId,
+ label: d.label,
+ }))}
+ selectedItem={activeDeviceId}
+ onAction={(value) => {
+ setActiveMediaDevice(value as string)
+ onActiveDeviceChange(value as string)
+ }}
+ />
+ </Menu>
+ </HStack>
+ )
+}
diff --git a/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx b/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx
index 6fe0b89d..c60eb1dc 100644
--- a/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx
+++ b/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx
@@ -6,7 +6,6 @@ import { supportsScreenSharing } from '@livekit/components-core'
import {
DisconnectButton,
LeaveIcon,
- MediaDeviceMenu,
TrackToggle,
useMaybeLayoutContext,
usePersistentUserChoices,
@@ -20,6 +19,7 @@ import { OptionsButton } from '../components/controls/Options/OptionsButton'
import { ParticipantsToggle } from '@/features/rooms/livekit/components/controls/Participants/ParticipantsToggle'
import { ChatToggle } from '@/features/rooms/livekit/components/controls/ChatToggle'
import { HandToggle } from '@/features/rooms/livekit/components/controls/HandToggle'
+import { SelectToggleDevice } from '@/features/rooms/livekit/components/controls/SelectToggleDevice'
/** @public */
export type ControlBarControls = {
@@ -126,46 +126,26 @@ export function ControlBar({
return (
<div {...htmlProps}>
- <div className="lk-button-group">
- <TrackToggle
- source={Track.Source.Microphone}
- showIcon={showIcon}
- onChange={microphoneOnChange}
- onDeviceError={(error) =>
- onDeviceError?.({ source: Track.Source.Microphone, error })
- }
- >
- {showText && t('controls.microphone')}
- </TrackToggle>
- <div className="lk-button-group-menu">
- <MediaDeviceMenu
- kind="audioinput"
- onActiveDeviceChange={(_kind, deviceId) =>
- saveAudioInputDeviceId(deviceId ?? '')
- }
- />
- </div>
- </div>
- <div className="lk-button-group">
- <TrackToggle
- source={Track.Source.Camera}
- showIcon={showIcon}
- onChange={cameraOnChange}
- onDeviceError={(error) =>
- onDeviceError?.({ source: Track.Source.Camera, error })
- }
- >
- {showText && t('controls.camera')}
- </TrackToggle>
- <div className="lk-button-group-menu">
- <MediaDeviceMenu
- kind="videoinput"
- onActiveDeviceChange={(_kind, deviceId) =>
- saveVideoInputDeviceId(deviceId ?? '')
- }
- />
- </div>
- </div>
+ <SelectToggleDevice
+ source={Track.Source.Microphone}
+ onChange={microphoneOnChange}
+ onDeviceError={(error) =>
+ onDeviceError?.({ source: Track.Source.Microphone, error })
+ }
+ onActiveDeviceChange={(deviceId) =>
+ saveAudioInputDeviceId(deviceId ?? '')
+ }
+ />
+ <SelectToggleDevice
+ source={Track.Source.Camera}
+ onChange={cameraOnChange}
+ onDeviceError={(error) =>
+ onDeviceError?.({ source: Track.Source.Camera, error })
+ }
+ onActiveDeviceChange={(deviceId) =>
+ saveVideoInputDeviceId(deviceId ?? '')
+ }
+ />
{browserSupportsScreenSharing && (
<TrackToggle
source={Track.Source.ScreenShare}
diff --git a/src/frontend/src/locales/de/rooms.json b/src/frontend/src/locales/de/rooms.json
index 004c0548..0c5680ab 100644
--- a/src/frontend/src/locales/de/rooms.json
+++ b/src/frontend/src/locales/de/rooms.json
@@ -4,11 +4,27 @@
"heading": ""
},
"join": {
- "camlabel": "",
+ "videoinput": {
+ "choose": "",
+ "disable": "",
+ "enable": "",
+ "label": "",
+ "placeholder": ""
+ },
+ "audioinput": {
+ "choose": "",
+ "disable": "",
+ "enable": "",
+ "label": ""
+ },
"heading": "",
"joinLabel": "",
- "micLabel": "",
- "userLabel": ""
+ "joinMeeting": "",
+ "toggleOff": "",
+ "toggleOn": "",
+ "userLabel": "",
+ "usernameHint": "",
+ "usernameLabel": ""
},
"leaveRoomPrompt": "",
"shareDialog": {
diff --git a/src/frontend/src/locales/en/rooms.json b/src/frontend/src/locales/en/rooms.json
index 20cf0602..935429c1 100644
--- a/src/frontend/src/locales/en/rooms.json
+++ b/src/frontend/src/locales/en/rooms.json
@@ -4,11 +4,27 @@
"heading": "Help us improve Meet"
},
"join": {
- "camlabel": "Camera",
- "heading": "Join the meeting",
+ "videoinput": {
+ "choose": "Select camera",
+ "disable": "Disable camera",
+ "enable": "Enable camera",
+ "label": "Camera",
+ "placeholder": "Enable camera to see the preview"
+ },
+ "audioinput": {
+ "choose": "Select microphone",
+ "disable": "Disable microphone",
+ "enable": "Enable microphone",
+ "label": "Microphone"
+ },
+ "heading": "Verify your settings",
"joinLabel": "Join",
- "micLabel": "Microphone",
- "userLabel": "Your name"
+ "joinMeeting": "Join meeting",
+ "toggleOff": "Click to turn off",
+ "toggleOn": "Click to turn on",
+ "userLabel": "",
+ "usernameHint": "Shown to other participants",
+ "usernameLabel": "Your name"
},
"leaveRoomPrompt": "This will make you leave the meeting.",
"shareDialog": {
diff --git a/src/frontend/src/locales/fr/rooms.json b/src/frontend/src/locales/fr/rooms.json
index 862da214..94b54b98 100644
--- a/src/frontend/src/locales/fr/rooms.json
+++ b/src/frontend/src/locales/fr/rooms.json
@@ -4,11 +4,27 @@
"heading": "Aidez-nous à améliorer Meet"
},
"join": {
- "camlabel": "Webcam",
- "heading": "Rejoindre la réunion",
+ "videoinput": {
+ "choose": "Choisir la webcam",
+ "disable": "Désactiver la webcam",
+ "enable": "Activer la webcam",
+ "label": "Webcam",
+ "placeholder": "Activez la webcam pour prévisualiser l'affichage"
+ },
+ "audioinput": {
+ "choose": "Choisir le micro",
+ "disable": "Désactiver le micro",
+ "enable": "Activer le micro",
+ "label": "Microphone"
+ },
+ "heading": "Vérifiez vos paramètres",
"joinLabel": "Rejoindre",
- "micLabel": "Micro",
- "userLabel": "Votre nom"
+ "joinMeeting": "Rejoindre la réjoindre",
+ "toggleOff": "Cliquez pour désactiver",
+ "toggleOn": "Cliquez pour activer",
+ "userLabel": "",
+ "usernameHint": "Affiché aux autres participants",
+ "usernameLabel": "Votre nom"
},
"leaveRoomPrompt": "Revenir à l'accueil vous fera quitter la réunion.",
"shareDialog": {
diff --git a/src/frontend/src/primitives/MenuList.tsx b/src/frontend/src/primitives/MenuList.tsx
index 11e4001f..dc05503a 100644
--- a/src/frontend/src/primitives/MenuList.tsx
+++ b/src/frontend/src/primitives/MenuList.tsx
@@ -26,7 +26,7 @@ export const MenuList = <T extends string | number = string>({
const label = typeof item === 'string' ? item : item.label
return (
<MenuItem
- className={menuItemRecipe()}
+ className={menuItemRecipe({ extraPadding: true })}
key={value}
id={value as string}
onAction={() => {