♻️(frontend) simplify the controls component

As we duplicated the code, we don't need anymore to configure
the available controls from the video conference.
This commit is contained in:
lebaudantoine
2024-08-06 15:16:37 +02:00
committed by aleb_the_flash
parent 217b19e42a
commit 8c7aed4b00
2 changed files with 51 additions and 81 deletions

View File

@@ -11,7 +11,6 @@ import {
LeaveIcon, LeaveIcon,
MediaDeviceMenu, MediaDeviceMenu,
TrackToggle, TrackToggle,
useLocalParticipantPermissions,
useMaybeLayoutContext, useMaybeLayoutContext,
usePersistentUserChoices, usePersistentUserChoices,
} from '@livekit/components-react' } from '@livekit/components-react'
@@ -21,6 +20,7 @@ import { mergeProps } from '@/utils/mergeProps.ts'
import { StartMediaButton } from '../components/controls/StartMediaButton' import { StartMediaButton } from '../components/controls/StartMediaButton'
import { useMediaQuery } from '../hooks/useMediaQuery' import { useMediaQuery } from '../hooks/useMediaQuery'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { SettingsButton } from '@/features/settings'
/** @public */ /** @public */
export type ControlBarControls = { export type ControlBarControls = {
@@ -64,7 +64,6 @@ export interface ControlBarProps extends React.HTMLAttributes<HTMLDivElement> {
*/ */
export function ControlBar({ export function ControlBar({
variation, variation,
controls,
saveUserChoices = true, saveUserChoices = true,
onDeviceError, onDeviceError,
...props ...props
@@ -85,22 +84,6 @@ export function ControlBar({
const defaultVariation = isTooLittleSpace ? 'minimal' : 'verbose' const defaultVariation = isTooLittleSpace ? 'minimal' : 'verbose'
variation ??= defaultVariation variation ??= defaultVariation
const visibleControls = { leave: true, ...controls }
const localPermissions = useLocalParticipantPermissions()
if (!localPermissions) {
visibleControls.camera = false
visibleControls.chat = false
visibleControls.microphone = false
visibleControls.screenShare = false
} else {
visibleControls.camera ??= localPermissions.canPublish
visibleControls.microphone ??= localPermissions.canPublish
visibleControls.screenShare ??= localPermissions.canPublish
visibleControls.chat ??= localPermissions.canPublishData && controls?.chat
}
const showIcon = React.useMemo( const showIcon = React.useMemo(
() => variation === 'minimal' || variation === 'verbose', () => variation === 'minimal' || variation === 'verbose',
[variation] [variation]
@@ -144,51 +127,47 @@ export function ControlBar({
return ( return (
<div {...htmlProps}> <div {...htmlProps}>
{visibleControls.microphone && ( <div className="lk-button-group">
<div className="lk-button-group"> <TrackToggle
<TrackToggle source={Track.Source.Microphone}
source={Track.Source.Microphone} showIcon={showIcon}
showIcon={showIcon} onChange={microphoneOnChange}
onChange={microphoneOnChange} onDeviceError={(error) =>
onDeviceError={(error) => onDeviceError?.({ source: Track.Source.Microphone, 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 ?? '')
} }
> />
{showText && t('controls.microphone')}
</TrackToggle>
<div className="lk-button-group-menu">
<MediaDeviceMenu
kind="audioinput"
onActiveDeviceChange={(_kind, deviceId) =>
saveAudioInputDeviceId(deviceId ?? '')
}
/>
</div>
</div> </div>
)} </div>
{visibleControls.camera && ( <div className="lk-button-group">
<div className="lk-button-group"> <TrackToggle
<TrackToggle source={Track.Source.Camera}
source={Track.Source.Camera} showIcon={showIcon}
showIcon={showIcon} onChange={cameraOnChange}
onChange={cameraOnChange} onDeviceError={(error) =>
onDeviceError={(error) => onDeviceError?.({ source: Track.Source.Camera, 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 ?? '')
} }
> />
{showText && t('controls.camera')}
</TrackToggle>
<div className="lk-button-group-menu">
<MediaDeviceMenu
kind="videoinput"
onActiveDeviceChange={(_kind, deviceId) =>
saveVideoInputDeviceId(deviceId ?? '')
}
/>
</div>
</div> </div>
)} </div>
{visibleControls.screenShare && browserSupportsScreenSharing && ( {browserSupportsScreenSharing && (
<TrackToggle <TrackToggle
source={Track.Source.ScreenShare} source={Track.Source.ScreenShare}
captureOptions={{ audio: true, selfBrowserSurface: 'include' }} captureOptions={{ audio: true, selfBrowserSurface: 'include' }}
@@ -206,24 +185,18 @@ export function ControlBar({
)} )}
</TrackToggle> </TrackToggle>
)} )}
{visibleControls.chat && ( <ChatToggle>
<ChatToggle> {showIcon && <ChatIcon />}
{showIcon && <ChatIcon />} {showText && t('controls.chat')}
{showText && t('controls.chat')} </ChatToggle>
</ChatToggle> <SettingsMenuToggle>
)} {showIcon && <GearIcon />}
{visibleControls.settings && ( {showText && t('controls.settings')}
<SettingsMenuToggle> </SettingsMenuToggle>
{showIcon && <GearIcon />} <DisconnectButton>
{showText && t('controls.settings')} {showIcon && <LeaveIcon />}
</SettingsMenuToggle> {showText && t('controls.leave')}
)} </DisconnectButton>
{visibleControls.leave && (
<DisconnectButton>
{showIcon && <LeaveIcon />}
{showText && t('controls.leave')}
</DisconnectButton>
)}
<StartMediaButton /> <StartMediaButton />
</div> </div>
) )

View File

@@ -65,7 +65,6 @@ export function VideoConference({
chatMessageFormatter, chatMessageFormatter,
chatMessageDecoder, chatMessageDecoder,
chatMessageEncoder, chatMessageEncoder,
SettingsComponent,
...props ...props
}: VideoConferenceProps) { }: VideoConferenceProps) {
const [widgetState, setWidgetState] = React.useState<WidgetState>({ const [widgetState, setWidgetState] = React.useState<WidgetState>({
@@ -180,9 +179,7 @@ export function VideoConference({
</FocusLayoutContainer> </FocusLayoutContainer>
</div> </div>
)} )}
<ControlBar <ControlBar />
controls={{ chat: true, settings: !!SettingsComponent }}
/>
</div> </div>
<Chat <Chat
style={{ display: widgetState.showChat ? 'grid' : 'none' }} style={{ display: widgetState.showChat ? 'grid' : 'none' }}