feat: soundboard, account menu, and call timer
CI / Build & test (Node 20) (push) Canceled after 0s
CI / Build & test (Node 24) (push) Canceled after 0s
CI / Build & test (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
Security / Secret scan (gitleaks) (push) Canceled after 0s
Security / Dependency scan (OSV-Scanner) (push) Canceled after 0s
Security / IaC/config scan (Trivy) (push) Canceled after 0s
Security / License compliance scan (Trivy) (push) Canceled after 0s
OpenSSF Scorecard / Scorecard analysis (push) Canceled after 0s
CI / Build & test (Node 20) (push) Canceled after 0s
CI / Build & test (Node 24) (push) Canceled after 0s
CI / Build & test (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
Security / Secret scan (gitleaks) (push) Canceled after 0s
Security / Dependency scan (OSV-Scanner) (push) Canceled after 0s
Security / IaC/config scan (Trivy) (push) Canceled after 0s
Security / License compliance scan (Trivy) (push) Canceled after 0s
OpenSSF Scorecard / Scorecard analysis (push) Canceled after 0s
Soundboard: the trigger travels over the WebSocket and every client in the call plays the clip locally, instead of mixing it into the presser's microphone or publishing a LiveKit track. No upstream bandwidth, no media stack changes, and the clip is not degraded by voice processing. Fan-out uses a new sendToRoomParticipants rather than sendToRoom: the latter broadcasts a space room to the whole space, which is right for the presence the sidebar shows and wrong for anything audible. The cooldown is enforced server-side — a client-side one only slows down people not trying to abuse it, and a soundboard is the easiest thing here to turn into a weapon. Playing is open to anyone in the call; deciding what the buttons are needs MANAGE_SPACE. Account menu: the name in the user bar had cursor-pointer and no handler, so the interface was already promising a click that did nothing. Offers profile, status and copy-id — not the Clips or account switching the reference design shows, which would be dead UI here. Call timer: startedAt comes from the server, so a late joiner sees the call's age rather than their own arrival. Empty space rooms are destroyed already, which is what makes the next call start from zero — no reset logic needed.
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { api, type SoundboardSound } from '../../api/client';
|
||||
import { wsSend } from '../../hooks/useWebSocket';
|
||||
import { useTransferStore } from '../../stores/transferStore';
|
||||
import { waitForTransferAttachment } from '../../utils/waitForTransfer';
|
||||
import { useT } from '../../i18n';
|
||||
|
||||
interface SoundboardPopoverProps {
|
||||
spaceId: string;
|
||||
canManage: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
/** Clips are short gags; anything larger is a music file in disguise. */
|
||||
const MAX_SOUND_BYTES = 1024 * 1024;
|
||||
|
||||
export function SoundboardPopover({ spaceId, canManage, onClose }: SoundboardPopoverProps) {
|
||||
const t = useT();
|
||||
const [sounds, setSounds] = useState<SoundboardSound[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
api.soundboard.list(spaceId)
|
||||
.then(({ sounds: list }) => { if (!cancelled) setSounds(list); })
|
||||
.catch(() => { /* an empty board is the honest fallback */ });
|
||||
return () => { cancelled = true; };
|
||||
}, [spaceId]);
|
||||
|
||||
useEffect(() => {
|
||||
const handlePointer = (e: MouseEvent | TouchEvent) => {
|
||||
if (!panelRef.current?.contains(e.target as Node)) onClose();
|
||||
};
|
||||
const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
||||
document.addEventListener('mousedown', handlePointer);
|
||||
document.addEventListener('touchstart', handlePointer);
|
||||
document.addEventListener('keydown', handleKey);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handlePointer);
|
||||
document.removeEventListener('touchstart', handlePointer);
|
||||
document.removeEventListener('keydown', handleKey);
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
// Fire and forget: the server echoes the clip back to everyone in the call,
|
||||
// this client included, so the presser hears exactly what the others hear —
|
||||
// including the server's refusal when the cooldown is still running.
|
||||
const play = (soundId: string) => wsSend({ type: 'soundboard_play', soundId });
|
||||
|
||||
const handleFile = async (file: File) => {
|
||||
setError('');
|
||||
if (file.size > MAX_SOUND_BYTES) {
|
||||
setError(t('soundboard.tooLarge'));
|
||||
return;
|
||||
}
|
||||
const name = window.prompt(t('soundboard.namePrompt'), file.name.replace(/\.[^.]+$/, ''));
|
||||
if (!name) return;
|
||||
|
||||
setUploading(true);
|
||||
try {
|
||||
const tid = await useTransferStore.getState().startUpload(file, { tray: false });
|
||||
const { filename } = await waitForTransferAttachment(tid);
|
||||
const created = await api.soundboard.add(spaceId, name, filename);
|
||||
setSounds((prev) => [...prev, created]);
|
||||
} catch {
|
||||
setError(t('soundboard.tooLarge'));
|
||||
} finally {
|
||||
setUploading(false);
|
||||
if (fileRef.current) fileRef.current.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemove = async (soundId: string) => {
|
||||
const previous = sounds;
|
||||
setSounds((prev) => prev.filter((s) => s.id !== soundId));
|
||||
try {
|
||||
await api.soundboard.remove(soundId);
|
||||
} catch {
|
||||
setSounds(previous);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={panelRef}
|
||||
className="absolute bottom-full left-2 right-2 mb-2 z-[200] glass rounded-xl overflow-hidden p-3 shadow-xl"
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-[12px] font-semibold uppercase tracking-wider text-txt-tertiary">
|
||||
{t('soundboard.title')}
|
||||
</span>
|
||||
{canManage && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileRef.current?.click()}
|
||||
disabled={uploading}
|
||||
className="text-[11px] text-accent-primary hover:underline disabled:opacity-50"
|
||||
>
|
||||
{uploading ? t('soundboard.adding') : t('soundboard.add')}
|
||||
</button>
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="audio/*"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) void handleFile(file);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error && <div className="text-[11px] text-txt-danger mb-2">{error}</div>}
|
||||
|
||||
{sounds.length === 0 ? (
|
||||
<p className="text-[12px] text-txt-tertiary py-2">{t('soundboard.empty')}</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 gap-1.5 max-h-[220px] overflow-y-auto scrollbar-thin">
|
||||
{sounds.map((sound) => (
|
||||
<div key={sound.id} className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => play(sound.id)}
|
||||
className="w-full px-2 py-2.5 rounded-lg bg-surface-elevated text-txt-secondary hover:text-txt-primary hover:brightness-125 transition-all text-[11px] font-medium truncate"
|
||||
title={sound.name}
|
||||
>
|
||||
{sound.name}
|
||||
</button>
|
||||
{canManage && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void handleRemove(sound.id)}
|
||||
title={t('soundboard.remove')}
|
||||
aria-label={t('soundboard.remove')}
|
||||
className="absolute -top-1 -right-1 w-4 h-4 rounded-full bg-accent-rose text-white text-[10px] leading-none opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user