2025-02-15 15:22:07 -08:00
|
|
|
import React, { HTMLAttributes } from 'react';
|
|
|
|
|
import classNames from 'classnames';
|
2025-05-12 20:27:09 -07:00
|
|
|
import { FaPlay, FaPause, FaStepForward, FaStepBackward, FaVolumeUp, FaDesktop, FaStop } from 'react-icons/fa';
|
2025-06-24 12:50:15 -07:00
|
|
|
import { Features } from '../api/player';
|
2025-02-15 15:22:07 -08:00
|
|
|
|
|
|
|
|
interface NowPlayingProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
|
|
songName: string;
|
|
|
|
|
fileName: string;
|
|
|
|
|
isPlaying: boolean;
|
2025-05-12 20:27:09 -07:00
|
|
|
isIdle: boolean;
|
2025-02-15 21:16:04 -08:00
|
|
|
volume: number;
|
2025-02-15 15:22:07 -08:00
|
|
|
onPlayPause: () => void;
|
2025-05-12 20:27:09 -07:00
|
|
|
onStop: () => void;
|
2025-02-15 16:28:47 -08:00
|
|
|
onSkip: () => void;
|
|
|
|
|
onPrevious: () => void;
|
2025-05-12 20:27:09 -07:00
|
|
|
|
|
|
|
|
onScreenShare: () => void;
|
|
|
|
|
isScreenSharingSupported: boolean;
|
|
|
|
|
isScreenSharing: boolean;
|
|
|
|
|
|
2025-02-15 21:16:04 -08:00
|
|
|
// Sent when the volume setting actually changes value
|
|
|
|
|
onVolumeSettingChange: (volume: number) => void;
|
|
|
|
|
|
|
|
|
|
// Sent when the volume is about to start changing
|
|
|
|
|
onVolumeWillChange: (volume: number) => void;
|
|
|
|
|
|
|
|
|
|
// Sent when the volume has changed
|
|
|
|
|
onVolumeDidChange: (volume: number) => void;
|
2025-06-24 12:50:15 -07:00
|
|
|
|
|
|
|
|
features: Features | null;
|
|
|
|
|
|
|
|
|
|
audioEnabled: boolean;
|
|
|
|
|
onAudioEnabledChange: (enabled: boolean) => void;
|
2025-02-15 15:22:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NowPlaying: React.FC<NowPlayingProps> = (props) => {
|
2025-05-12 20:27:09 -07:00
|
|
|
const titleArea = props.isScreenSharing ? (
|
|
|
|
|
<div className="flex flex-row items-center gap-2 text-white text-center justify-center">
|
|
|
|
|
<FaDesktop size={24} />
|
|
|
|
|
<div className="text-lg font-bold truncate">Screen Sharing</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className={classNames(props.isIdle ? 'opacity-50' : 'opacity-100')}>
|
|
|
|
|
<div className="text-lg font-bold truncate">{props.songName}</div>
|
|
|
|
|
<div className="text-sm truncate">{props.fileName}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-15 15:22:07 -08:00
|
|
|
return (
|
2025-02-15 22:15:59 -08:00
|
|
|
<div className={classNames(props.className, 'bg-black/50 h-fit p-5')}>
|
2025-02-15 15:22:07 -08:00
|
|
|
<div className="flex flex-col w-full gap-2">
|
2025-05-12 20:27:09 -07:00
|
|
|
<div className="flex flex-col w-full h-full bg-black/50 rounded-lg p-5 gap-4">
|
|
|
|
|
<div className="flex-grow min-w-0 w-full text-white text-left">
|
|
|
|
|
{titleArea}
|
2025-02-15 15:22:07 -08:00
|
|
|
</div>
|
2025-05-12 20:27:09 -07:00
|
|
|
<div className="flex flex-row items-center gap-4 w-full">
|
|
|
|
|
<div className="flex items-center gap-2 text-white w-full max-w-[250px]">
|
2025-02-15 21:16:04 -08:00
|
|
|
<FaVolumeUp size={20} />
|
|
|
|
|
<input
|
|
|
|
|
type="range"
|
|
|
|
|
min="0"
|
|
|
|
|
max="100"
|
|
|
|
|
value={props.volume}
|
|
|
|
|
onMouseDown={() => props.onVolumeWillChange(props.volume)}
|
|
|
|
|
onMouseUp={() => props.onVolumeDidChange(props.volume)}
|
|
|
|
|
onChange={(e) => props.onVolumeSettingChange(Number(e.target.value))}
|
2025-05-12 20:27:09 -07:00
|
|
|
className="fancy-slider h-2 w-full"
|
2025-02-15 21:16:04 -08:00
|
|
|
/>
|
|
|
|
|
</div>
|
2025-05-12 20:27:09 -07:00
|
|
|
|
|
|
|
|
<div className="flex-grow"></div>
|
2025-02-15 21:16:04 -08:00
|
|
|
|
2025-02-15 16:28:47 -08:00
|
|
|
<button className="text-white hover:text-violet-300 transition-colors" onClick={props.onPrevious}>
|
2025-02-15 15:22:07 -08:00
|
|
|
<FaStepBackward size={24} />
|
|
|
|
|
</button>
|
2025-02-15 21:16:04 -08:00
|
|
|
|
2025-02-15 15:22:07 -08:00
|
|
|
<button className="text-white hover:text-violet-300 transition-colors" onClick={props.onPlayPause}>
|
2025-05-12 20:27:09 -07:00
|
|
|
{(props.isPlaying && !props.isIdle) ? <FaPause size={24} /> : <FaPlay size={24} />}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<button className="text-white hover:text-violet-300 transition-colors" onClick={props.onStop}>
|
|
|
|
|
<FaStop size={24} className={props.isIdle ? 'opacity-25' : 'opacity-100'} />
|
2025-02-15 15:22:07 -08:00
|
|
|
</button>
|
2025-02-15 21:16:04 -08:00
|
|
|
|
2025-02-15 16:28:47 -08:00
|
|
|
<button className="text-white hover:text-violet-300 transition-colors" onClick={props.onSkip}>
|
2025-02-15 15:22:07 -08:00
|
|
|
<FaStepForward size={24} />
|
|
|
|
|
</button>
|
2025-05-12 20:27:09 -07:00
|
|
|
|
2025-06-24 12:50:15 -07:00
|
|
|
{(props.isScreenSharingSupported && props.features?.screenshare) && (
|
2025-05-12 20:27:09 -07:00
|
|
|
<button
|
|
|
|
|
className={classNames("text-white hover:text-violet-300 transition-colors rounded-full p-2", props.isScreenSharing ? ' bg-violet-800' : '')}
|
|
|
|
|
onClick={props.onScreenShare}
|
|
|
|
|
title="Share your screen"
|
|
|
|
|
>
|
|
|
|
|
<FaDesktop size={24} />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2025-02-15 15:22:07 -08:00
|
|
|
</div>
|
2025-06-24 12:50:15 -07:00
|
|
|
|
|
|
|
|
{props.features?.browserPlayback && (
|
|
|
|
|
<div>
|
|
|
|
|
<label className="flex items-center gap-2 text-white text-sm cursor-pointer">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={props.audioEnabled}
|
|
|
|
|
onChange={(e) => props.onAudioEnabledChange(e.target.checked)}
|
|
|
|
|
className="w-4 h-4 text-violet-600 bg-gray-100 border-gray-300 rounded focus:ring-violet-500 focus:ring-2"
|
|
|
|
|
/>
|
|
|
|
|
Enable audio playback in browser
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-02-15 15:22:07 -08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default NowPlaying;
|