채팅 연속 입력 전부 전송(짧은 연타 허용 + 보내기 대기열), 사람도 '입력 중' 표시, 오른쪽 위 소리 크기(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:
@@ -34,6 +34,8 @@ interface RoomStore {
|
||||
result: GameResultView | null;
|
||||
chat: ChatLine[];
|
||||
emotes: { id: number; from: string; emote: string }[];
|
||||
/** People typing right now: user id → where and until when (ms, local clock). */
|
||||
typing: Record<string, { ch: 'room' | 'game'; until: number }>;
|
||||
pending: number | null;
|
||||
slow: boolean;
|
||||
rttMs: number | null;
|
||||
@@ -42,6 +44,14 @@ interface RoomStore {
|
||||
kicked: boolean;
|
||||
}
|
||||
|
||||
/** A "입력 중" signal lasts this long unless renewed (the typer renews it every couple of seconds). */
|
||||
const TYPING_MS = 5000;
|
||||
const withoutTyping = (t: RoomStore['typing'], id: string | undefined): RoomStore['typing'] => {
|
||||
if (!id || !(id in t)) return t;
|
||||
const { [id]: _gone, ...rest } = t;
|
||||
return rest;
|
||||
};
|
||||
|
||||
export const useRoom = create<RoomStore>(() => ({
|
||||
status: 'idle',
|
||||
me: null,
|
||||
@@ -52,6 +62,7 @@ export const useRoom = create<RoomStore>(() => ({
|
||||
result: null,
|
||||
chat: [],
|
||||
emotes: [],
|
||||
typing: {},
|
||||
pending: null,
|
||||
slow: false,
|
||||
rttMs: null,
|
||||
@@ -208,7 +219,7 @@ class GameSocket {
|
||||
join(code: string, as: 'player' | 'spectator' = 'player'): void {
|
||||
const cur = useRoom.getState();
|
||||
if (cur.code !== code) {
|
||||
useRoom.setState({ code, room: null, roomSeq: -1, game: null, result: null, chat: [], joinError: null, kicked: false, pending: null });
|
||||
useRoom.setState({ code, room: null, roomSeq: -1, game: null, result: null, chat: [], typing: {}, joinError: null, kicked: false, pending: null });
|
||||
}
|
||||
this.start();
|
||||
this.send({ t: 'join', code, as });
|
||||
@@ -216,14 +227,14 @@ class GameSocket {
|
||||
|
||||
leave(): void {
|
||||
this.send({ t: 'leave' });
|
||||
useRoom.setState({ code: null, room: null, roomSeq: -1, game: null, result: null, chat: [], pending: null });
|
||||
useRoom.setState({ code: null, room: null, roomSeq: -1, game: null, result: null, chat: [], typing: {}, pending: null });
|
||||
}
|
||||
|
||||
/** Left the room page (홈, 규칙…) without leaving: the seat stays, but the room no longer counts us as there. */
|
||||
detach(code: string): void {
|
||||
if (useRoom.getState().code !== code) return;
|
||||
this.send({ t: 'detach' });
|
||||
useRoom.setState({ code: null, room: null, roomSeq: -1, game: null, result: null, chat: [], pending: null });
|
||||
useRoom.setState({ code: null, room: null, roomSeq: -1, game: null, result: null, chat: [], typing: {}, pending: null });
|
||||
}
|
||||
|
||||
/** Sends a game action; returns false when not connected. */
|
||||
@@ -290,7 +301,17 @@ class GameSocket {
|
||||
useRoom.setState({ result: m.result });
|
||||
break;
|
||||
case 'chat':
|
||||
useRoom.setState({ chat: [...st.chat, { id: this.chatId++, from: m.from, text: m.text, at: m.at }].slice(-100) });
|
||||
useRoom.setState({ chat: [...st.chat, { id: this.chatId++, from: m.from, text: m.text, at: m.at }].slice(-100), typing: withoutTyping(st.typing, m.from?.id) });
|
||||
break;
|
||||
case 'typing':
|
||||
if (m.on) {
|
||||
const until = Date.now() + TYPING_MS;
|
||||
useRoom.setState({ typing: { ...st.typing, [m.from]: { ch: m.ch, until } } });
|
||||
setTimeout(() => {
|
||||
const cur = useRoom.getState().typing[m.from];
|
||||
if (cur && cur.until <= Date.now()) useRoom.setState((s) => ({ typing: withoutTyping(s.typing, m.from) }));
|
||||
}, TYPING_MS + 50);
|
||||
} else useRoom.setState({ typing: withoutTyping(st.typing, m.from) });
|
||||
break;
|
||||
case 'emote': {
|
||||
const id = this.chatId++;
|
||||
|
||||
Reference in New Issue
Block a user