import * as React from 'react'; import { mergeProps } from '../../utils'; import { getSourceIcon } from '../../assets/icons/util'; import { useTrackMutedIndicator } from '../../hooks'; import type { TrackReferenceOrPlaceholder } from '@livekit/components-core'; /** @public */ export interface TrackMutedIndicatorProps extends React.HTMLAttributes { trackRef: TrackReferenceOrPlaceholder; show?: 'always' | 'muted' | 'unmuted'; } /** * The `TrackMutedIndicator` shows whether the participant's camera or microphone is muted or not. * By default, a muted/unmuted icon is displayed for a camera, microphone, and screen sharing track. * * @example * ```tsx * * ``` * @public */ export const TrackMutedIndicator: ( props: TrackMutedIndicatorProps & React.RefAttributes, ) => React.ReactNode = /* @__PURE__ */ React.forwardRef( function TrackMutedIndicator( { trackRef, show = 'always', ...props }: TrackMutedIndicatorProps, ref, ) { const { className, isMuted } = useTrackMutedIndicator(trackRef); const showIndicator = show === 'always' || (show === 'muted' && isMuted) || (show === 'unmuted' && !isMuted); const htmlProps = React.useMemo( () => mergeProps(props, { className, }), [className, props], ); if (!showIndicator) { return null; } return (
{props.children ?? getSourceIcon(trackRef.source, !isMuted)}
); }, );