♻️(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,7 +127,6 @@ 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}
@@ -165,8 +147,6 @@ export function ControlBar({
/> />
</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}
@@ -187,8 +167,7 @@ export function ControlBar({
/> />
</div> </div>
</div> </div>
)} {browserSupportsScreenSharing && (
{visibleControls.screenShare && 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>
)}
{visibleControls.settings && (
<SettingsMenuToggle> <SettingsMenuToggle>
{showIcon && <GearIcon />} {showIcon && <GearIcon />}
{showText && t('controls.settings')} {showText && t('controls.settings')}
</SettingsMenuToggle> </SettingsMenuToggle>
)}
{visibleControls.leave && (
<DisconnectButton> <DisconnectButton>
{showIcon && <LeaveIcon />} {showIcon && <LeaveIcon />}
{showText && t('controls.leave')} {showText && t('controls.leave')}
</DisconnectButton> </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' }}