혼자인 대기실에서 브라우저 뒤로가기(홈)로 나가면 빈 방이 10분 동안 남던 문제: 다른 사람이 없고 게임 전이면 detach를 나가기로 처리해 방을 바로 닫음. 방 안 📖 규칙도 팝업으로(규칙 페이지로 넘어가며 방을 떠나지 않게), e2e/room-back.e2e.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,12 +93,51 @@ describe('idle guests', () => {
|
||||
});
|
||||
|
||||
describe('leaving the room page', () => {
|
||||
test('detach keeps the seat but the room no longer counts the connection', async () => {
|
||||
test('alone with no game running (뒤로가기 from the lobby): leaving the page leaves the room and it closes at once', async () => {
|
||||
const s = start();
|
||||
const g = await guest(s.base, '혼자');
|
||||
const c = await connect(s, g);
|
||||
const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: c.cookie, body: JSON.stringify({ gameId: 'omok' }) });
|
||||
c.send({ t: 'join', code: r.body.code, as: 'player' });
|
||||
await c.waitFor((m) => m.t === 'room');
|
||||
expect(s.rooms.get(r.body.code)).toBeDefined();
|
||||
c.send({ t: 'detach' });
|
||||
for (let i = 0; i < 50 && s.rooms.get(r.body.code); i++) await sleep(10);
|
||||
expect(s.rooms.get(r.body.code)).toBeUndefined();
|
||||
expect(s.rooms.activeRoomFor(g.id)).toBeNull();
|
||||
// The same socket is fine afterwards.
|
||||
c.send({ t: 'ping', ts: 1 });
|
||||
await c.waitFor((m) => m.t === 'pong');
|
||||
});
|
||||
|
||||
test('someone else is in the lobby: leaving the page keeps my seat (I can come back)', async () => {
|
||||
const s = start();
|
||||
const a = await guest(s.base, '방장');
|
||||
const b = await guest(s.base, '친구');
|
||||
const ca = await connect(s, a);
|
||||
const cb = await connect(s, b);
|
||||
const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: ca.cookie, body: JSON.stringify({ gameId: 'omok' }) });
|
||||
ca.send({ t: 'join', code: r.body.code, as: 'player' });
|
||||
await ca.waitFor((m) => m.t === 'room');
|
||||
cb.send({ t: 'join', code: r.body.code, as: 'player' });
|
||||
await cb.waitFor((m) => m.t === 'room');
|
||||
const room = s.rooms.get(r.body.code)!;
|
||||
ca.send({ t: 'detach' });
|
||||
for (let i = 0; i < 50 && room.conns.size > 1; i++) await sleep(10);
|
||||
expect(room.conns.size).toBe(1);
|
||||
expect(room.seatOf(a.id)).toBeGreaterThanOrEqual(0);
|
||||
expect(s.rooms.get(r.body.code)).toBe(room);
|
||||
});
|
||||
|
||||
test('detach during a game keeps the seat but the room no longer counts the connection', async () => {
|
||||
const s = start();
|
||||
const g = await guest(s.base, '홈으로');
|
||||
const c = await connect(s, g);
|
||||
const code = await practiceRoom(s, c);
|
||||
const room = s.rooms.get(code)!;
|
||||
c.send({ t: 'start' });
|
||||
for (let i = 0; i < 50 && room.status !== 'playing'; i++) await sleep(10);
|
||||
expect(room.status).toBe('playing');
|
||||
expect(room.conns.size).toBe(1);
|
||||
c.send({ t: 'detach' });
|
||||
for (let i = 0; i < 50 && room.conns.size; i++) await sleep(10);
|
||||
|
||||
@@ -546,6 +546,9 @@ export class Room {
|
||||
const u = conn.userId;
|
||||
if (this.conns.get(u) !== conn) return;
|
||||
if (this.spectators.has(u)) return this.disconnect(conn);
|
||||
// Alone in the lobby: nobody to come back to, so leaving the page (뒤로가기, 홈) leaves the room and the empty room
|
||||
// closes now instead of lingering (2026-10-14). A game (running, or its result: 다시 보기 comes back) keeps the seat.
|
||||
if (this.status === 'lobby' && this.conns.size === 1 && !this.seatedIds().some((x) => x !== u && !isBotId(x) && !this.leftDuringGame.has(x))) return this.leave(u);
|
||||
this.conns.delete(u);
|
||||
this.detached.set(u, conn);
|
||||
if (this.conns.size === 0) this.becameEmpty('disconnect');
|
||||
|
||||
@@ -98,6 +98,8 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
// 설정 opens as a popup over the room: going to /me would unmount the room and detach from it.
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const closeSettings = useCallback(() => setSettingsOpen(false), []);
|
||||
// 규칙 too: going to /rules would leave the room page (and, alone in a lobby, the room itself).
|
||||
const [rulesOpen, setRulesOpen] = useState(false);
|
||||
// [한 판 더] takes me back to this room's lobby after game N (kept per tab so a reload stays there).
|
||||
const lobbyKey = `bg:lobby:${code}`;
|
||||
const [lobbyAfter, setLobbyAfter] = useState<number | null>(() => Number(sessionStorage.getItem(lobbyKey)) || null);
|
||||
@@ -217,7 +219,7 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
</span>
|
||||
)}
|
||||
<VolumeControl className="btn btn-ghost btn-sm rb-btn" label />
|
||||
<button className="btn btn-ghost btn-sm rb-btn" onClick={() => nav(`/rules/${room.gameId}`)} aria-label="규칙 보기">
|
||||
<button className="btn btn-ghost btn-sm rb-btn" onClick={() => setRulesOpen(true)} aria-haspopup="dialog" aria-label="규칙 보기">
|
||||
<span className="rb-ico">📖</span>
|
||||
<span className="rb-lbl">규칙</span>
|
||||
</button>
|
||||
@@ -247,6 +249,16 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
</Sheet>
|
||||
)}
|
||||
{settingsOpen && <SettingsPopup onClose={closeSettings} />}
|
||||
{rulesOpen && (
|
||||
<Sheet onClose={() => setRulesOpen(false)} label={`${gameName(room.gameId)} 규칙`}>
|
||||
<h2>{gameName(room.gameId)} 규칙</h2>
|
||||
<GameNotice gameId={room.gameId} />
|
||||
{ui ? <ui.Rules options={room.options} /> : <p className="muted">불러오는 중…</p>}
|
||||
<button type="button" className="btn btn-secondary btn-block" onClick={() => setRulesOpen(false)}>
|
||||
닫기
|
||||
</button>
|
||||
</Sheet>
|
||||
)}
|
||||
{leaveAsk && (
|
||||
<ConfirmSheet
|
||||
title="방에서 나갈까요?"
|
||||
|
||||
Reference in New Issue
Block a user