Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/domains/freetalk/components/ChatRoomModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const ChatRoomModal = ({open, onClose, room, onLeave}) => {
connect: wsConnect,
disconnect: wsDisconnect,
sendMessage: wsSendMessage,
startGame: wsStartGame,
stopGame: wsStopGame,
clearError: wsClearError,
setMessages,
} = useChatWebSocket(room?.id, currentUserId)
Expand Down Expand Up @@ -516,6 +518,8 @@ const ChatRoomModal = ({open, onClose, room, onLeave}) => {
roomId={room?.id}
onGameMessage={handleGameMessage}
initialGameStatus={gameStatus}
onStartGame={wsStartGame}
onStopGame={wsStopGame}
/>
</Box>
)}
Expand Down
70 changes: 39 additions & 31 deletions src/domains/freetalk/components/GameModePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {DESIGN_TOKENS} from '../../../theme/theme'
const CANVAS_WIDTH = 340
const CANVAS_HEIGHT = 200

const GameModePanel = ({roomId, onGameMessage, initialGameStatus}) => {
const GameModePanel = ({roomId, onGameMessage, initialGameStatus, onStartGame, onStopGame}) => {
const theme = useTheme()
const isDark = theme.palette.mode === 'dark'
const {user} = useAuth()
Expand Down Expand Up @@ -91,39 +91,47 @@ const GameModePanel = ({roomId, onGameMessage, initialGameStatus}) => {
return () => clearInterval(interval)
}, [isGameActive, gameState.roundStartTime, gameState.roundTimeLimit])

// 게임 시작
const handleStartGame = async () => {
setLoading(true)
try {
const response = await gameService.start(roomId)
const data = response.data || response
setGameState(data)
onGameMessage?.({
type: 'game_start',
content: `🎮 게임 시작! 총 ${data.totalRounds}라운드\n출제자: ${data.currentDrawerId}`,
})
} catch (err) {
console.error('Failed to start game:', err)
} finally {
setLoading(false)
// 게임 시작 - WebSocket을 통해 /start 명령어 전송 (서버에서 인원 검증)
const handleStartGame = () => {
if (onStartGame) {
// WebSocket으로 /start 명령어 전송 (채팅창에서 /start 입력과 동일)
onStartGame()
} else {
// fallback: REST API 사용 (WebSocket 미연결 시)
setLoading(true)
gameService.start(roomId)
.then(response => {
const data = response.data || response
setGameState(data)
onGameMessage?.({
type: 'game_start',
content: `🎮 게임 시작! 총 ${data.totalRounds}라운드\n출제자: ${data.currentDrawerId}`,
})
})
.catch(err => console.error('Failed to start game:', err))
.finally(() => setLoading(false))
}
}

// 게임 종료
const handleStopGame = async () => {
setLoading(true)
try {
const response = await gameService.stop(roomId)
const data = response.data || response
setGameState(prev => ({...prev, gameStatus: GAME_STATUS.NONE}))
onGameMessage?.({
type: 'game_end',
content: `🎮 게임 종료!\n${data.message}`,
})
} catch (err) {
console.error('Failed to stop game:', err)
} finally {
setLoading(false)
// 게임 종료 - WebSocket을 통해 /stop 명령어 전송
const handleStopGame = () => {
if (onStopGame) {
// WebSocket으로 /stop 명령어 전송 (채팅창에서 /stop 입력과 동일)
onStopGame()
} else {
// fallback: REST API 사용 (WebSocket 미연결 시)
setLoading(true)
gameService.stop(roomId)
.then(response => {
const data = response.data || response
setGameState(prev => ({...prev, gameStatus: GAME_STATUS.NONE}))
onGameMessage?.({
type: 'game_end',
content: `🎮 게임 종료!\n${data.message}`,
})
})
.catch(err => console.error('Failed to stop game:', err))
.finally(() => setLoading(false))
}
}

Expand Down