채팅 소리 기본 크기를 게임 소리의 80%로 올리고(60%는 너무 안 들린다는 의견), 관리자 사이트 설정에 "채팅 소리 크기"(게임 소리의 0~200%, 정수, 기본 80%)를 추가. 0%면 채팅 소리 없음. 각자의 소리 크기(0~100)는 그대로 곱해짐. 저장하면 /api/config와 방 정보(RoomView.chatSound)로 열린 방에도 바로 적용. 설정 화면에 저장 없이 그 값으로 울려 보는 "들어 보기" 버튼. feedback.test.ts·admin.test.ts·admin.e2e.ts에 확인 추가, docs/14-admin.md 표에 항목 추가
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,7 @@ class FakeCtx {
|
||||
// The real settings store needs a page (document); only the sound settings matter here.
|
||||
let settings = { sound: true, volume: 100 };
|
||||
mock.module('../store/session', () => ({ useSession: { getState: () => ({ settings }) } }));
|
||||
const { CHAT_LEVEL, GAME_LEVEL, chatSound, sounds } = await import('./feedback');
|
||||
const { GAME_LEVEL, chatLevel, chatSound, setChatSound, sounds } = await import('./feedback');
|
||||
|
||||
const setVolume = (volume: number, sound = true) => {
|
||||
settings = { sound, volume };
|
||||
@@ -67,19 +67,19 @@ beforeEach(() => {
|
||||
notes = [];
|
||||
});
|
||||
|
||||
test('chat sound is 60% of the game sounds', () => {
|
||||
test('chat sound is 80% of the game sounds by default', () => {
|
||||
expect(GAME_LEVEL).toBe(0.15);
|
||||
expect(CHAT_LEVEL).toBeCloseTo(GAME_LEVEL * 0.6, 10);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10);
|
||||
setVolume(100);
|
||||
sounds.myTurn(); // a typical game sound at the usual level
|
||||
const game = Math.max(...notes.map((n) => n.peak));
|
||||
notes = [];
|
||||
chatSound();
|
||||
// Notes playing at the same moment add up; the loudest moment of the chat sound is 60% of a game sound.
|
||||
// Notes playing at the same moment add up; the loudest moment of the chat sound is 80% of a game sound.
|
||||
const byStart = new Map<number, number>();
|
||||
for (const n of notes) byStart.set(n.start, (byStart.get(n.start) ?? 0) + n.peak);
|
||||
const loudest = Math.max(...byStart.values());
|
||||
expect(loudest).toBeCloseTo(game * 0.6, 6);
|
||||
expect(loudest).toBeCloseTo(game * 0.8, 6);
|
||||
// One bubble ("뽁") gliding up from a low start.
|
||||
expect(notes.map((n) => n.freq)).toEqual([380]);
|
||||
expect(notes.map((n) => n.to)).toEqual([1150]);
|
||||
@@ -110,3 +110,28 @@ test('lines arriving in a burst share one sound', async () => {
|
||||
chatSound();
|
||||
expect(notes.length).toBe(one * 2);
|
||||
});
|
||||
|
||||
test('admin chat sound setting: 0~200% of a game sound, 0 is silent, preview does not change it', async () => {
|
||||
setVolume(100);
|
||||
for (const [pct, want] of [[200, 2], [150, 1.5], [999, 2], [-5, 0]] as const) {
|
||||
setChatSound(pct);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * want, 10);
|
||||
}
|
||||
setChatSound(0);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
notes = [];
|
||||
chatSound();
|
||||
expect(notes).toEqual([]);
|
||||
setChatSound(200);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
chatSound();
|
||||
expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 2, 6);
|
||||
// Previewing another value in the admin page plays it once and leaves the setting alone.
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
notes = [];
|
||||
chatSound(50);
|
||||
expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 0.5, 6);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 2, 10);
|
||||
setChatSound(undefined); // missing from an old server → the default 80%
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* directly for something of their own.
|
||||
*/
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { CHAT_SOUND_DEFAULT, clampChatSound } from '@bg/shared/lite';
|
||||
import { useSession } from '../store/session';
|
||||
|
||||
let ctx: AudioContext | null = null;
|
||||
@@ -190,21 +191,30 @@ export const sounds = {
|
||||
|
||||
/** The usual level of a game sound at volume 100 (`tone`'s default). */
|
||||
export const GAME_LEVEL = 0.15;
|
||||
/** Chat sound: 60% of the game sounds (it follows the same volume setting); 90% hit the ears too hard. */
|
||||
export const CHAT_LEVEL = GAME_LEVEL * 0.6;
|
||||
/** Chat sound in % of a game sound (admin setting `chatSound`, 0~200, default 80); it also follows the volume setting. */
|
||||
let chatPercent = CHAT_SOUND_DEFAULT;
|
||||
/** Sets the chat sound percent from /api/config or the room view (out-of-range values are clamped). */
|
||||
export function setChatSound(x: unknown): void {
|
||||
chatPercent = clampChatSound(x);
|
||||
}
|
||||
/** Peak level of the chat sound at volume 100 (`percent`: the admin setting unless previewing another value). */
|
||||
export const chatLevel = (percent = chatPercent): number => (GAME_LEVEL * clampChatSound(percent)) / 100;
|
||||
let lastChatAt = -Infinity;
|
||||
|
||||
/**
|
||||
* Chat "뽁": one water-drop bubble like a messenger, a sine gliding up fast from low (about 0.08 s).
|
||||
* Kept apart from the UI/game sounds, which are steady notes (click, good, myTurn …), so it is not mistaken for one;
|
||||
* it also starts lower and is shorter and softer than the game "pop" (700→1400 Hz).
|
||||
* It peaks at CHAT_LEVEL and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound.
|
||||
* It peaks at `chatLevel()` (none at 0%) and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound.
|
||||
* `percent` previews another level (admin settings) without changing the setting.
|
||||
*/
|
||||
export function chatSound(): void {
|
||||
export function chatSound(percent?: number): void {
|
||||
const level = chatLevel(percent);
|
||||
if (level <= 0) return;
|
||||
const now = performance.now();
|
||||
if (now - lastChatAt < 80) return;
|
||||
lastChatAt = now;
|
||||
tone(380, 80, 'sine', CHAT_LEVEL, 0, { attack: 12, slideTo: 1150 });
|
||||
tone(380, 80, 'sine', level, 0, { attack: 12, slideTo: 1150 });
|
||||
}
|
||||
|
||||
/** Plays the chat sound whenever `lastKey` (the newest live chat line) changes after the first render. */
|
||||
|
||||
@@ -67,7 +67,7 @@ export interface RoomPreview {
|
||||
|
||||
export const api = {
|
||||
config: () =>
|
||||
call<{ discord: boolean; catalog: (CatalogEntry & { notice?: string })[]; siteName: string; announcement: string; maintenance: boolean; gameSpeed?: number }>('GET', '/api/config'),
|
||||
call<{ discord: boolean; catalog: (CatalogEntry & { notice?: string })[]; siteName: string; announcement: string; maintenance: boolean; gameSpeed?: number; chatSound?: number }>('GET', '/api/config'),
|
||||
me: () => call<MeResponse>('GET', '/api/me'),
|
||||
guest: (nickname: string) => call<{ me: PublicUser }>('POST', '/api/auth/guest', { nickname }),
|
||||
updateMe: (patch: { nickname?: string; useAvatar?: boolean; settings?: Settings }) => call<{ me: PublicUser }>('PATCH', '/api/me', patch),
|
||||
|
||||
@@ -7,6 +7,7 @@ import { PROTOCOL, type GameResultView, type PublicUser, type RoomView, type Ser
|
||||
import { toast } from '../store/toast';
|
||||
import { markOutdated, noteServerBuild } from '../lib/update';
|
||||
import { setGameSpeed } from '../lib/motion';
|
||||
import { setChatSound } from '../lib/feedback';
|
||||
|
||||
export type ConnStatus = 'idle' | 'connecting' | 'open' | 'reconnecting' | 'replaced' | 'offline';
|
||||
|
||||
@@ -285,6 +286,7 @@ class GameSocket {
|
||||
case 'room':
|
||||
if (m.seq >= st.roomSeq || m.room.code !== st.room?.code) {
|
||||
if (m.room.gameSpeed !== undefined) setGameSpeed(m.room.gameSpeed);
|
||||
if (m.room.chatSound !== undefined) setChatSound(m.room.chatSound);
|
||||
useRoom.setState({ room: m.room, roomSeq: m.seq, joinError: null });
|
||||
if (m.room.status === 'playing' && st.result) useRoom.setState({ result: null });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** 관리자 사이트 (docs/14-admin.md). Downloaded only when /admin is opened. */
|
||||
import { useCallback, useEffect, useState, type ReactNode } from 'react';
|
||||
import { NavLink, Route, Routes, useNavigate, useParams } from 'react-router';
|
||||
import { formatRoomCode, GAME_SPEED_MAX, GAME_SPEED_MIN, type MyGameSummary } from '@bg/shared/lite';
|
||||
import { CHAT_SOUND_DEFAULT, CHAT_SOUND_MAX, CHAT_SOUND_MIN, formatRoomCode, GAME_SPEED_MAX, GAME_SPEED_MIN, type MyGameSummary } from '@bg/shared/lite';
|
||||
import { ConfirmSheet, Sheet } from '../../components/ui';
|
||||
import { apiCall, discordLoginUrl, type Role } from '../../net/api';
|
||||
import { useSession } from '../../store/session';
|
||||
@@ -10,6 +10,7 @@ import { SchemaForm, type JsonSchema } from './SchemaForm';
|
||||
import { gameName } from '../../components/GameNotice';
|
||||
import { RecordCell, record, recordText, resultLabel, sumStats } from '../../components/PlayerCard';
|
||||
import type { GameStat } from '../../net/api';
|
||||
import { chatSound } from '../../lib/feedback';
|
||||
|
||||
const a = {
|
||||
get: <T,>(p: string) => apiCall<T>('GET', `/api/admin${p}`),
|
||||
@@ -445,6 +446,43 @@ function Site() {
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
<section className="card stack">
|
||||
<div className="stack" style={{ gap: 6 }}>
|
||||
<strong id="chat-sound-label">
|
||||
채팅 소리 크기 <span className="muted small">(게임 소리의 {CHAT_SOUND_MIN}~{CHAT_SOUND_MAX}%, 기본 {CHAT_SOUND_DEFAULT}%)</span>
|
||||
</strong>
|
||||
<p className="muted small" style={{ margin: 0 }}>
|
||||
새 채팅이 올 때 나는 "뽁" 소리의 크기예요. 100%면 게임 소리와 같고, 0%면 채팅 소리가 안 나요. 각자 정한 소리 크기도 그대로 곱해져요. 저장하면 열린 방에도 바로 적용돼요.
|
||||
</p>
|
||||
<div className="row" style={{ gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<input
|
||||
type="range"
|
||||
min={CHAT_SOUND_MIN}
|
||||
max={CHAT_SOUND_MAX}
|
||||
step={5}
|
||||
value={s.chatSound}
|
||||
aria-labelledby="chat-sound-label"
|
||||
style={{ accentColor: 'var(--primary)', flex: '1 1 160px' }}
|
||||
onChange={(e) => setS({ ...s, chatSound: Number(e.target.value) })}
|
||||
/>
|
||||
<input
|
||||
className="input"
|
||||
type="number"
|
||||
min={CHAT_SOUND_MIN}
|
||||
max={CHAT_SOUND_MAX}
|
||||
step={1}
|
||||
value={s.chatSound}
|
||||
aria-label="채팅 소리 크기(%)"
|
||||
style={{ width: 90 }}
|
||||
onChange={(e) => setS({ ...s, chatSound: Number(e.target.value) })}
|
||||
/>
|
||||
<span className="muted small">%</span>
|
||||
<button type="button" className="btn btn-ghost btn-sm" onClick={() => chatSound(s.chatSound)}>
|
||||
들어 보기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section className="card stack">
|
||||
{num('maxRoomsPerUser', '사용자당 동시에 만들 수 있는 방', 1, 50)}
|
||||
{num('maxRooms', '서버 전체 방 수 제한', 10, 20000)}
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { CatalogEntry, PublicUser } from '@bg/shared/lite';
|
||||
import { api, type Settings } from '../net/api';
|
||||
import { socket } from '../net/socket';
|
||||
import { setGameSpeed } from '../lib/motion';
|
||||
import { setChatSound } from '../lib/feedback';
|
||||
|
||||
const LS_KEY = 'bg.settings';
|
||||
|
||||
@@ -76,7 +77,7 @@ export const useSession = create<SessionState>((set, get) => ({
|
||||
hasDiscordAvatar: false,
|
||||
async refresh() {
|
||||
const [cfg, me] = await Promise.all([
|
||||
api.config().catch(() => ({ discord: false, catalog: [] as CatalogEntry[], siteName: '같이 놀자 보드게임', announcement: '', maintenance: false, gameSpeed: 1 })),
|
||||
api.config().catch(() => ({ discord: false, catalog: [] as CatalogEntry[], siteName: '같이 놀자 보드게임', announcement: '', maintenance: false, gameSpeed: 1, chatSound: undefined })),
|
||||
api.me().catch(() => ({ me: null }) as Awaited<ReturnType<typeof api.me>>),
|
||||
]);
|
||||
const settings = { ...get().settings, ...withoutDeviceOnly(me.settings ?? {}) };
|
||||
@@ -84,6 +85,7 @@ export const useSession = create<SessionState>((set, get) => ({
|
||||
localStorage.setItem(LS_KEY, JSON.stringify(settings));
|
||||
document.title = cfg.siteName;
|
||||
setGameSpeed(cfg.gameSpeed);
|
||||
setChatSound(cfg.chatSound);
|
||||
set({
|
||||
loaded: true,
|
||||
me: me.me,
|
||||
|
||||
Reference in New Issue
Block a user