import type { CaptureOptionsBySource, ToggleSource } from '@livekit/components-core'; import * as React from 'react'; import { getSourceIcon } from '../../assets/icons/util'; import { useTrackToggle } from '../../hooks'; import { TrackPublishOptions } from 'livekit-client'; /** @public */ export interface TrackToggleProps extends Omit, 'onChange'> { source: T; showIcon?: boolean; initialState?: boolean; /** * Function that is called when the enabled state of the toggle changes. * The second function argument `isUserInitiated` is `true` if the change was initiated by a user interaction, such as a click. */ onChange?: (enabled: boolean, isUserInitiated: boolean) => void; captureOptions?: CaptureOptionsBySource; publishOptions?: TrackPublishOptions; onDeviceError?: (error: Error) => void; } /** * With the `TrackToggle` component it is possible to mute and unmute your camera and microphone. * The component uses an html button element under the hood so you can treat it like a button. * * @example * ```tsx * * * * * ``` * @public */ export const TrackToggle: ( props: TrackToggleProps & React.RefAttributes, ) => React.ReactNode = /* @__PURE__ */ React.forwardRef(function TrackToggle< T extends ToggleSource, >({ showIcon, ...props }: TrackToggleProps, ref: React.ForwardedRef) { const { buttonProps, enabled } = useTrackToggle(props); const [isClient, setIsClient] = React.useState(false); React.useEffect(() => { setIsClient(true); }, []); return ( isClient && ( ) ); });