Skip to content

Commit

Permalink
[๐Ÿ›fix]: ingameSubscription ์ธ๊ฒŒ์ž„์›น์†Œ์ผ“ํ›…์œผ๋กœ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
yejinleee committed Apr 18, 2024
1 parent 1fb265a commit 0f93377
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/pages/GamePage/GamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const GamePage = () => {
const navigate = useNavigate();

const { roomId, setRoomInfo, roomInfo } = useRoomInfoStore();
const { publishGameRoom, stompClient, ingameSubscription } =
useWebsocket(roomId);
const { publishGameRoom, stompClient } = useWebsocket(roomId);

const { gameRoomRes, isRoomWsError, didAdminStart, allMembers } =
useGameWaitingRoomStore();
Expand Down Expand Up @@ -109,7 +108,6 @@ const GamePage = () => {
<IngameWebsocketLayer
userId={userId}
stompClient={stompClient}
ingameSubscription={ingameSubscription}
/>
);
};
Expand Down
6 changes: 2 additions & 4 deletions src/pages/GamePage/IngameWebsocketLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, StompSubscription } from '@stomp/stompjs';
import { Client } from '@stomp/stompjs';
import React, { MutableRefObject, Suspense, useEffect } from 'react';
import Spinner from '@/common/Spinner/Spinner';
import useIngameStore from '@/store/useIngameStore';
Expand All @@ -11,7 +11,6 @@ import useIngameWebsocket from './hooks/useIngameWebsocket';
interface IngameWebsocketLayerProps {
userId: number;
stompClient: MutableRefObject<Client | undefined>;
ingameSubscription: MutableRefObject<StompSubscription | undefined>;
}

const GameCode = React.lazy(() => import('./GameCode/GameCode'));
Expand All @@ -22,14 +21,13 @@ const GameSentence = React.lazy(() => import('./GameSentence/GameSentence'));
const IngameWebsocketLayer = ({
userId,
stompClient,
ingameSubscription,
}: IngameWebsocketLayerProps) => {
const { roomId, roomInfo } = useRoomInfoStore();
const { ingameRoomRes, isIngameWsError, isRoundWaiting, setIsRoundWaiting } =
useIngameStore();

const { onIngameConnected, handleConnectIngame, publishIngame } =
useIngameWebsocket({ roomId, stompClient, ingameSubscription });
useIngameWebsocket({ roomId, stompClient });
useEffect(() => {
onIngameConnected(); // ์ธ๊ฒŒ์ž„ ์—”๋“œํฌ์ธํŠธ ๊ตฌ๋…
handleConnectIngame(roomId); // ํ•ด๋‹น ์ธ๊ฒŒ์ž„ ์—ฐ๊ฒฐ ๋ฐœํ–‰
Expand Down
11 changes: 4 additions & 7 deletions src/pages/GamePage/hooks/useIngameWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client, StompSubscription } from '@stomp/stompjs';
import { MutableRefObject } from 'react';
import { MutableRefObject, useRef } from 'react';
import useGameWaitingRoomStore from '@/store/useGameWaitingRoomStore';
import useIngameStore from '@/store/useIngameStore';
import { checkIsEmptyObj } from '@/utils/checkIsEmptyObj';
Expand All @@ -9,13 +9,10 @@ import { PayloadType } from '../types/websocketType';
interface I_useIngame {
roomId: number;
stompClient: MutableRefObject<Client | undefined>;
ingameSubscription: MutableRefObject<StompSubscription | undefined>;
}
const useIngameWebsocket = ({
roomId,
stompClient,
ingameSubscription,
}: I_useIngame) => {
const useIngameWebsocket = ({ roomId, stompClient }: I_useIngame) => {
const ingameSubscription = useRef<StompSubscription>();

const connectHeaders = getToken();
const { setIsIngameWsError, setIngameRoomRes } = useIngameStore();
const { setAllMembers } = useGameWaitingRoomStore();
Expand Down
4 changes: 1 addition & 3 deletions src/pages/GamePage/hooks/useWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './init.ts';
import { Client, StompSubscription } from '@stomp/stompjs';
import { Client } from '@stomp/stompjs';
import { useEffect, useRef } from 'react';
import SockJS from 'sockjs-client';
import { BASE_PATH } from '@/generated/base';
Expand All @@ -10,7 +10,6 @@ import { getToken } from '@/utils/getToken';

const useWebsocket = (roomId: number | null) => {
const stompClient = useRef<Client>();
const ingameSubscription = useRef<StompSubscription>();

const connectHeaders = getToken();

Expand Down Expand Up @@ -101,7 +100,6 @@ const useWebsocket = (roomId: number | null) => {
return {
publishGameRoom,
stompClient,
ingameSubscription,
};
};

Expand Down

0 comments on commit 0f93377

Please sign in to comment.