import React, { useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { IReduxState } from '../../../app/types'; import { IconPlay, IconStop } from '../../../base/icons/svg'; import { getLocalParticipant } from '../../../base/participants/functions'; import { setSharedMusicStatus } from '../../actions'; import { PLAYBACK_STATUSES, SOURCE_TYPES } from '../../constants'; import { isSharingStatus } from '../../functions'; import SharedMusicPlayer from './SharedMusicPlayer'; interface IProps { /** * The participant ID (music URL). */ participantId: string; } /** * Component that renders a shared music tile with the actual video player. * This is displayed in the filmstrip thumbnail for shared music. * * @param {IProps} props - The component props. * @returns {React.ReactElement | null} */ const SharedMusicTile: React.FC = ({ participantId }) => { const dispatch = useDispatch(); const { musicUrl, ownerId, status, sourceType, time, title } = useSelector( (state: IReduxState) => state['features/shared-music'] ); const localParticipant = useSelector((state: IReduxState) => getLocalParticipant(state)); const isOwner = ownerId === localParticipant?.id; const isMusicShared = isSharingStatus(status ?? ''); const isPlaying = status === PLAYBACK_STATUSES.PLAYING; const isYouTube = sourceType === SOURCE_TYPES.YOUTUBE; const handlePlayPause = useCallback((e: React.MouseEvent) => { e.stopPropagation(); // Prevent thumbnail click from pinning if (!isOwner || !musicUrl) { return; // Only owner can control playback, and musicUrl must exist } const newStatus = isPlaying ? PLAYBACK_STATUSES.PAUSED : PLAYBACK_STATUSES.PLAYING; dispatch(setSharedMusicStatus({ musicUrl, status: newStatus, time: time ?? 0, ownerId, sourceType })); }, [ dispatch, isOwner, isPlaying, musicUrl, ownerId, sourceType, time ]); if (!isMusicShared || participantId !== musicUrl) { return null; } return (
{/* Render the actual player for YouTube videos */} {isYouTube ? (
) : ( /* For audio-only, show a background with controls */
)} {/* Overlay with title and controls for non-owners */}
{/* Title */}
{title || 'Shared Music'}
{/* Play/Pause button (owner only, shown when YouTube controls are hidden) */} {isOwner && !isYouTube && ( )} {/* Status indicator for non-owners when not YouTube */} {!isOwner && !isYouTube && (
{isPlaying ? 'Playing' : 'Paused'}
)}
); }; export default SharedMusicTile;