feat: soundboard, account menu, and call timer
OpenSSF Scorecard / Scorecard analysis (push) Waiting to run
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

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:
2026-08-31 13:45:18 -03:00
parent ef5545465d
commit f5451e1b14
22 changed files with 5026 additions and 11 deletions
@@ -0,0 +1,38 @@
import { useEffect, useState } from 'react';
interface CallTimerProps {
startedAt: number;
className?: string;
}
function format(elapsedMs: number): string {
const total = Math.max(0, Math.floor(elapsedMs / 1000));
const hours = Math.floor(total / 3600);
const minutes = Math.floor((total % 3600) / 60);
const seconds = total % 60;
const pad = (n: number) => String(n).padStart(2, '0');
return hours > 0 ? `${hours}:${pad(minutes)}:${pad(seconds)}` : `${minutes}:${pad(seconds)}`;
}
/**
* How long the current call has been running.
*
* `startedAt` comes from the server, so everyone sees the same figure and a
* late joiner sees the call's age rather than their own. The server destroys an
* empty room, so the next call starts from zero on its own.
*/
export function CallTimer({ startedAt, className = '' }: CallTimerProps) {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
// Aligned to the next whole second so the digits do not visibly stutter.
const timeout = setTimeout(() => setNow(Date.now()), 1000 - (Date.now() % 1000));
return () => clearTimeout(timeout);
}, [now]);
return (
<span className={`tabular-nums ${className}`} title={new Date(startedAt).toLocaleTimeString()}>
{format(now - startedAt)}
</span>
);
}
@@ -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>
);
}
@@ -1,5 +1,6 @@
import React, { useCallback, useMemo } from 'react';
import { useVoiceStore } from '../../stores/voiceStore';
import { CallTimer } from './CallTimer';
import { useSpaceStore } from '../../stores/spaceStore';
import { useAuthStore } from '../../stores/authStore';
import { useContextMenuStore, type ContextMenuItem } from '../../stores/contextMenuStore';
@@ -33,6 +34,9 @@ interface VoiceChannelProps {
/** Wrapper component for the volume slider so it can use hooks (useState). */
export function VoiceChannel({ channelId, channelName, onClick, locked, canManage, onSettingsClick, voiceUserHandlers, dropZone }: VoiceChannelProps) {
// Present only while someone is in the channel; the server drops the room
// when it empties, which is what makes the next call start from zero.
const callStartedAt = useVoiceStore((s) => s.voiceRoomStarts.get(channelId));
const serverVoiceUsers = useVoiceStore((s) => s.voiceUsers.get(channelId)) ?? EMPTY_VOICE_USERS;
const currentVoiceChannel = useVoiceStore((s) => s.currentVoiceChannelId);
const participants = useVoiceStore((s) => s.participants);
@@ -141,6 +145,12 @@ export function VoiceChannel({ channelId, channelName, onClick, locked, canManag
</svg>
)}
<span className="truncate text-[15px] font-medium flex-1 text-left">{channelName}</span>
{callStartedAt !== undefined && (
<CallTimer
startedAt={callStartedAt}
className="flex-shrink-0 text-[11px] text-txt-tertiary font-medium"
/>
)}
{canManage && (
<svg
width="16"
@@ -7,6 +7,7 @@ import { getActiveRoom } from '../../hooks/useLiveKit';
import { wsSend } from '../../hooks/useWebSocket';
import { ScreenShareSettingsPopover } from './ScreenShareSettingsPopover';
import { ConnectionInfoPopover } from './ConnectionInfoPopover';
import { SoundboardPopover } from './SoundboardPopover';
import { startScreenShare, stopScreenShare } from '../../utils/screenShare';
import { hasPermissionBit, PermissionBits } from '../../utils/permissions';
import { broadcastVoiceStatus } from '../../utils/voice';
@@ -22,6 +23,7 @@ export function VoiceControls() {
const currentVoiceChannelName = useVoiceStore((s) => s.currentVoiceChannelName);
const setCurrentChannel = useChatStore((s) => s.setCurrentChannel);
const navigate = useNavigate();
const [showSoundboard, setShowSoundboard] = useState(false);
const isCameraOn = useVoiceStore((s) => s.isCameraOn);
const isScreenSharing = useVoiceStore((s) => s.isScreenSharing);
const rnnoiseEnabled = useVoiceStore((s) => s.rnnoiseEnabled);
@@ -119,6 +121,19 @@ export function VoiceControls() {
return (
<>
{/* Zero-height anchor: the component returns a fragment, so without a
positioned ancestor the popover would resolve against whatever
happened to be relative further up the sidebar. */}
<div className="relative">
{showSoundboard && currentVoiceSpaceId && (
<SoundboardPopover
spaceId={currentVoiceSpaceId}
canManage={hasPermissionBit(channelPerms, PermissionBits.MANAGE_SPACE)}
onClose={() => setShowSoundboard(false)}
/>
)}
</div>
{/* Row 1: Signal icon + status text + disconnect */}
<div className="relative flex items-center gap-2 px-3 pt-3 pb-1">
<button
@@ -216,6 +231,23 @@ export function VoiceControls() {
</button>
)}
{/* Soundboard — space calls only: clips belong to a space. */}
{currentVoiceSpaceId && (
<button
onClick={() => setShowSoundboard((v) => !v)}
className={`${btnBase} ${
showSoundboard
? 'bg-surface-base text-accent-primary hover:bg-surface-channel'
: btnDefaultStyle
}`}
title="Soundboard"
>
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6Z" />
</svg>
</button>
)}
{/* Video Quality */}
<button
ref={qualityBtnRef}