Skip to content

Commit

Permalink
fix: Align with server by removing drawing broadcast feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaksj329 committed Nov 28, 2024
1 parent 31dea0a commit d398629
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
6 changes: 0 additions & 6 deletions client/src/components/canvas/GameCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ const GameCanvas = ({ role, maxPixels = 100000, currentRound, roomStatus }: Game

void gameSocketHandlers.submittedDrawing(allDrawingData);
},
onDrawingTimeEnded: (response) => {
if (!response.drawing) return;

resetCanvas();
applyDrawing(response.drawing);
},
});

const COLORS = COLORS_INFO.map((color) => ({
Expand Down
16 changes: 3 additions & 13 deletions client/src/hooks/socket/useDrawingSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// 특정 기능(드로잉)에 집중된 이벤트 핸들링
import { useCallback, useEffect } from 'react';
import { useParams } from 'react-router-dom';
import type { DrawSubmitResponse, DrawUpdateResponse } from '@troublepainter/core';
import type { DrawUpdateResponse } from '@troublepainter/core';
import { useGameSocketStore } from '@/stores/socket/gameSocket.store';
import { SocketNamespace } from '@/stores/socket/socket.config';
import { useSocketStore } from '@/stores/socket/socket.store';

interface UseDrawingSocketProps {
onDrawUpdate: (response: DrawUpdateResponse) => void;
onDrawingTimeEnded: (response: DrawSubmitResponse) => void;
onSubmitRequest: () => void;
}

Expand Down Expand Up @@ -56,7 +55,7 @@ interface UseDrawingSocketProps {
*
* @category Hooks
*/
export const useDrawingSocket = ({ onDrawUpdate, onDrawingTimeEnded, onSubmitRequest }: UseDrawingSocketProps) => {
export const useDrawingSocket = ({ onDrawUpdate, onSubmitRequest }: UseDrawingSocketProps) => {
const { roomId } = useParams<{ roomId: string }>();
const { sockets, connected, actions: socketActions } = useSocketStore();
const { currentPlayerId } = useGameSocketStore();
Expand All @@ -76,13 +75,6 @@ export const useDrawingSocket = ({ onDrawUpdate, onDrawingTimeEnded, onSubmitReq
onSubmitRequest();
}, [onSubmitRequest]);

const handleDrawingTimeEnded = useCallback(
(response: DrawSubmitResponse) => {
onDrawingTimeEnded(response);
},
[onDrawingTimeEnded],
);

useEffect(() => {
if (!roomId || !currentPlayerId) return;

Expand All @@ -108,14 +100,12 @@ export const useDrawingSocket = ({ onDrawUpdate, onDrawingTimeEnded, onSubmitReq

// game 네임스페이스 이벤트
gameSocket.on('submitDrawing', handleSubmitDrawing);
gameSocket.on('drawingTimeEnded', handleDrawingTimeEnded);

return () => {
drawingSocket.off('drawUpdated', handleDrawUpdate);
gameSocket.off('submitDrawing', handleSubmitDrawing);
gameSocket.off('drawingTimeEnded', handleDrawingTimeEnded);
};
}, [sockets.drawing, sockets.game, handleDrawUpdate, handleSubmitDrawing, handleDrawingTimeEnded]);
}, [sockets.drawing, sockets.game, handleDrawUpdate, handleSubmitDrawing]);

return {
isConnected: connected.drawing,
Expand Down
5 changes: 2 additions & 3 deletions core/types/socket.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ export interface DrawUpdateResponse {
drawingData: CRDTMessage;
}

export interface DrawSubmitResponse {
export interface DrawTimeEndedResponse {
roomStatus: any;
drawing: CRDTMessage;
}

// Socket.IO 이벤트 타입 정의
Expand Down Expand Up @@ -201,7 +200,7 @@ export type DrawingServerEvents = {
drawTimeUpdated: (response: RoundTimeUpdateResponse) => void;
drawUpdated: (response: DrawUpdateResponse) => void;
submitDrawing: () => void;
drawingTimeEnded: (response: DrawSubmitResponse) => void;
drawingTimeEnded: (response: DrawTimeEndedResponse) => void;
error: (error: SocketError) => void;
};
// 드로잉 클라이언트 이벤트 타입 정의
Expand Down

0 comments on commit d398629

Please sign in to comment.