'use client'; import * as React from 'react'; import { LocalAudioTrack, Track } from 'livekit-client'; import { useMaybeLayoutContext, useLocalParticipant, MediaDeviceMenu, TrackToggle, } from '@livekit/components-react'; import styles from '../styles/SettingsMenu.module.css'; /** * @alpha */ export interface SettingsMenuProps extends React.HTMLAttributes {} /** * @alpha */ export function SettingsMenu(props: SettingsMenuProps) { const layoutContext = useMaybeLayoutContext(); const settings = React.useMemo(() => { return { media: { camera: true, microphone: true, label: 'Media Devices', speaker: false }, effects: { label: 'Effects' }, }; }, []); const tabs = React.useMemo( () => Object.keys(settings) as Array, [settings], ); const { microphoneTrack } = useLocalParticipant(); const [activeTab, setActiveTab] = React.useState(tabs[0]); const [isNoiseFilterEnabled, setIsNoiseFilterEnabled] = React.useState(true); React.useEffect(() => { const micPublication = microphoneTrack; if (micPublication && micPublication.track instanceof LocalAudioTrack) { const currentProcessor = micPublication.track.getProcessor(); if (currentProcessor && !isNoiseFilterEnabled) { micPublication.track.stopProcessor(); } else if (!currentProcessor && isNoiseFilterEnabled) { import('@livekit/krisp-noise-filter') .then(({ KrispNoiseFilter, isKrispNoiseFilterSupported }) => { if (!isKrispNoiseFilterSupported()) { console.error('Enhanced noise filter is not supported for this browser'); setIsNoiseFilterEnabled(false); return; } micPublication?.track // @ts-ignore ?.setProcessor(KrispNoiseFilter()) .then(() => console.log('successfully set noise filter')); }) .catch((e) => console.error('Failed to load noise filter', e)); } } }, [isNoiseFilterEnabled, microphoneTrack]); return (
{tabs.map( (tab) => settings[tab] && ( ), )}
{activeTab === 'media' && ( <> {settings.media && settings.media.camera && ( <>

Camera

Camera
)} {settings.media && settings.media.microphone && ( <>

Microphone

Microphone
)} {settings.media && settings.media.speaker && ( <>

Speaker & Headphones

)} )} {activeTab === 'effects' && ( <>

Audio

setIsNoiseFilterEnabled(ev.target.checked)} checked={isNoiseFilterEnabled} >
)}
); }