채팅 연속 입력 전부 전송(짧은 연타 허용 + 보내기 대기열), 사람도 '입력 중' 표시, 오른쪽 위 소리 크기(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>
This commit is contained in:
@@ -1,18 +1,30 @@
|
||||
import type { RoomView } from '@bg/shared/lite';
|
||||
import { useRoom } from '../net/socket';
|
||||
|
||||
/**
|
||||
* What the computers are doing right now (docs/06 §12.1): "🤖 컴퓨터 1 생각 중…", "💬 컴퓨터 2 입력 중…".
|
||||
* What the computers are doing right now (docs/06 §12.1): "🤖 컴퓨터 1 생각 중…", "💬 컴퓨터 2 입력 중…", and people
|
||||
* typing ("💬 고양이 입력 중…", `ch`: the room chat or the game's own public chat).
|
||||
* Not announced to screen readers: the chat line or the move that follows is.
|
||||
*/
|
||||
export function BotActivity({ room, only }: { room: RoomView; only?: 'typing' }) {
|
||||
export function BotActivity({ room, only, ch }: { room: RoomView; only?: 'typing'; ch?: 'room' | 'game' }) {
|
||||
const typing = useRoom((s) => s.typing);
|
||||
const me = useRoom((s) => s.me?.id);
|
||||
const entries = Object.entries(room.botActivity ?? {}).filter(([, a]) => !only || a === only);
|
||||
if (!entries.length) return null;
|
||||
const name = (id: string) => room.seats.find((s) => s?.user.id === id)?.user.nickname ?? '컴퓨터';
|
||||
const people = ch ? Object.entries(typing).filter(([id, t]) => t.ch === ch && id !== me) : [];
|
||||
if (!entries.length && !people.length) return null;
|
||||
const name = (id: string, fallback: string) =>
|
||||
room.seats.find((s) => s?.user.id === id)?.user.nickname ?? room.spectators.find((u) => u.id === id)?.nickname ?? fallback;
|
||||
return (
|
||||
<div className="bot-activity small" aria-hidden>
|
||||
{entries.map(([id, a]) => (
|
||||
<span key={id} data-activity={a}>
|
||||
{a === 'typing' ? '💬' : '🤖'} {name(id)} {a === 'typing' ? '입력 중' : '생각 중'}
|
||||
{a === 'typing' ? '💬' : '🤖'} {name(id, '컴퓨터')} {a === 'typing' ? '입력 중' : '생각 중'}
|
||||
<span className="bot-dots" />
|
||||
</span>
|
||||
))}
|
||||
{people.map(([id]) => (
|
||||
<span key={id} data-activity="typing" data-person>
|
||||
💬 {name(id, '누군가')} 입력 중
|
||||
<span className="bot-dots" />
|
||||
</span>
|
||||
))}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { CHAT_MAX, EMOTE_LABEL, EMOTES, type PublicUser, type RoomView } from '@bg/shared/lite';
|
||||
import { create } from 'zustand';
|
||||
import { socket, useRoom } from '../net/socket';
|
||||
import { useChatOutbox, useTypingSignal } from '../lib/chat-input';
|
||||
import { useStickToBottom } from '../lib/useStickToBottom';
|
||||
import { BotActivity } from './BotActivity';
|
||||
import { ChatMessage, sameRun } from './ChatMessage';
|
||||
@@ -15,6 +16,8 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
const [text, setText] = useState('');
|
||||
const { ref: listRef, pin } = useStickToBottom<HTMLDivElement>();
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const send = useChatOutbox((t) => socket.send({ t: 'chat', text: t }), 550);
|
||||
const typing = useTypingSignal('room', room.chatEnabled);
|
||||
const lastId = chat.at(-1)?.id ?? 0;
|
||||
useEffect(() => {
|
||||
useChatSeen.setState({ seen: lastId });
|
||||
@@ -49,7 +52,7 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<BotActivity room={room} only="typing" />
|
||||
<BotActivity room={room} only="typing" ch="room" />
|
||||
<div className="emote-row">
|
||||
{EMOTES.map((id) => (
|
||||
<button key={id} type="button" onClick={() => socket.send({ t: 'emote', id })}>
|
||||
@@ -63,8 +66,9 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
style={{ flexWrap: 'nowrap' }}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (text.trim()) socket.send({ t: 'chat', text: text.trim().slice(0, CHAT_MAX) });
|
||||
if (text.trim()) send(text.trim().slice(0, CHAT_MAX));
|
||||
setText('');
|
||||
typing.stop();
|
||||
pin();
|
||||
}}
|
||||
>
|
||||
@@ -73,7 +77,11 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
className="input"
|
||||
style={{ flex: 1, minHeight: 44 }}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onChange={(e) => {
|
||||
setText(e.target.value);
|
||||
typing.onText(e.target.value);
|
||||
}}
|
||||
onBlur={typing.stop}
|
||||
onKeyDown={(e) => e.key === 'Escape' && (e.currentTarget as HTMLInputElement).blur()}
|
||||
maxLength={CHAT_MAX}
|
||||
placeholder="메시지 입력 (Enter)"
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/** PC top menu (docs/07-ui-ux.md §3.2): 로고·메뉴, 오른쪽에 테마 버튼과 로그인/계정 메뉴. */
|
||||
/** PC top menu (docs/07-ui-ux.md §3.2): 로고·메뉴, 오른쪽에 소리 크기·테마 버튼과 로그인/계정 메뉴. */
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Link, NavLink, useNavigate } from 'react-router';
|
||||
import { api } from '../net/api';
|
||||
import { useSession } from '../store/session';
|
||||
import { Avatar, ConfirmSheet } from './ui';
|
||||
import { VolumeControl } from './VolumeControl';
|
||||
|
||||
export function SiteHeader() {
|
||||
const { me, siteName, role } = useSession();
|
||||
@@ -21,7 +22,10 @@ export function SiteHeader() {
|
||||
<NavLink to="/games">게임 목록</NavLink>
|
||||
{role !== 'user' && <NavLink to="/admin">관리자</NavLink>}
|
||||
</nav>
|
||||
<ThemeToggle />
|
||||
<div className="header-tools">
|
||||
<VolumeControl />
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
{me ? (
|
||||
<AccountMenu />
|
||||
) : (
|
||||
|
||||
84
apps/web/src/components/VolumeControl.tsx
Normal file
84
apps/web/src/components/VolumeControl.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user