Files
joke-app/apps/web/src/components/VolumeControl.tsx
EJClaw f620faf70b 채팅 연속 입력 전부 전송(짧은 연타 허용 + 보내기 대기열), 사람도 '입력 중' 표시, 오른쪽 위 소리 크기(0~100, 기본 50)
- 서버 방 채팅: 0.5초 고정 간격 대신 토큰 버킷(4줄 연속, 초당 2줄) — 도배는 여전히 막음
- 웹: useChatOutbox(방 채팅·마피아·라이어 게임)로 빠르게 친 줄도 순서대로 전송
- typing 메시지(방 채팅 / 게임 공개 채팅만, 마피아 밤 채널은 보내지 않음), BotActivity에 사람 표시
- VolumeControl: 사이트 머리글·방 막대 오른쪽 위, 설정 페이지에도 슬라이더
- e2e/chat.e2e.ts: 연타 7줄, 입력 중, 소리 크기

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 04:14:19 +09:00

85 lines
3.3 KiB
TypeScript

/**
* Site volume (top right of the site header and the room bar): a speaker button that opens a 0~100 slider.
* Default 50 (the sounds play at half their old level). 0 or "소리 끄기" mutes everything. This device only.
*/
import { useEffect, useRef, useState } from 'react';
import { sfx } from '../lib/feedback';
import { useSession } from '../store/session';
export function volumeIcon(sound: boolean, volume: number): string {
if (!sound || volume <= 0) return '🔇';
return volume < 34 ? '🔈' : volume < 67 ? '🔉' : '🔊';
}
export function VolumeControl({ className = 'theme-toggle', label }: { className?: string; label?: boolean }) {
const sound = useSession((s) => s.settings.sound);
const volume = useSession((s) => s.settings.volume);
const updateSettings = useSession((s) => s.updateSettings);
const [open, setOpen] = useState(false);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!open) return;
const onDown = (e: PointerEvent) => !ref.current?.contains(e.target as Node) && setOpen(false);
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false);
document.addEventListener('pointerdown', onDown);
document.addEventListener('keydown', onKey);
return () => {
document.removeEventListener('pointerdown', onDown);
document.removeEventListener('keydown', onKey);
};
}, [open]);
const shown = sound ? volume : 0;
const icon = volumeIcon(sound, volume);
return (
<div className="volume-control" ref={ref}>
<button
type="button"
className={className}
aria-label={`소리 크기 ${shown}`}
title={`소리 크기 ${shown}`}
aria-haspopup="dialog"
aria-expanded={open}
onClick={() => setOpen((o) => !o)}
>
{label ? (
<>
<span className="rb-ico">{icon}</span>
<span className="rb-lbl">{shown}</span>
</>
) : (
<span aria-hidden>{icon}</span>
)}
</button>
{open && (
<div className="volume-pop" role="dialog" aria-label="소리 크기">
<div className="row" style={{ justifyContent: 'space-between', flexWrap: 'nowrap', gap: 8 }}>
<strong>소리 크기</strong>
<output className="volume-num" aria-live="polite">
{shown}
</output>
</div>
<input
type="range"
min={0}
max={100}
step={5}
value={shown}
aria-label="소리 크기 (0~100)"
onChange={(e) => updateSettings({ volume: Number(e.target.value), sound: Number(e.target.value) > 0 })}
onPointerUp={() => sfx.good()}
onKeyUp={() => sfx.click()}
/>
<div className="row" style={{ justifyContent: 'space-between', flexWrap: 'nowrap', gap: 8 }}>
<button type="button" className="btn btn-ghost btn-sm" onClick={() => updateSettings(sound && volume > 0 ? { sound: false } : { sound: true, volume: volume > 0 ? volume : 50 })}>
{sound && volume > 0 ? '🔇 끄기' : '🔊 켜기'}
</button>
<button type="button" className="btn btn-ghost btn-sm" onClick={() => (updateSettings({ sound: true, volume: 50 }), sfx.good())}>
기본(50)
</button>
</div>
</div>
)}
</div>
);
}