33import io .f1 .backend .domain .game .app .GameService ;
44import io .f1 .backend .domain .game .app .RoomService ;
55import io .f1 .backend .domain .game .dto .ChatMessage ;
6- import io .f1 .backend .domain .game .dto .GameStartData ;
76import io .f1 .backend .domain .game .dto .MessageType ;
8- import io .f1 .backend .domain .game .dto .PlayerReadyData ;
97import io .f1 .backend .domain .game .dto .RoomExitData ;
108import io .f1 .backend .domain .game .dto .RoomInitialData ;
119import io .f1 .backend .domain .game .dto .RoundResult ;
1210import io .f1 .backend .domain .game .dto .request .DefaultWebSocketRequest ;
1311import io .f1 .backend .domain .game .dto .request .GameStartRequest ;
12+ import io .f1 .backend .domain .game .dto .response .GameStartResponse ;
13+ import io .f1 .backend .domain .game .dto .response .PlayerListResponse ;
1414import io .f1 .backend .domain .user .dto .UserPrincipal ;
15-
1615import lombok .RequiredArgsConstructor ;
17-
1816import org .springframework .messaging .Message ;
1917import org .springframework .messaging .handler .annotation .DestinationVariable ;
2018import org .springframework .messaging .handler .annotation .MessageMapping ;
@@ -38,17 +36,18 @@ public void initializeRoomSocket(@DestinationVariable Long roomId, Message<?> me
3836 UserPrincipal principal = getSessionUser (message );
3937
4038 RoomInitialData roomInitialData =
41- roomService .initializeRoomSocket (roomId , websocketSessionId , principal );
42- String destination = roomInitialData .destination ();
39+ roomService .initializeRoomSocket (roomId , websocketSessionId , principal );
40+
41+ String destination = getDestination (roomId );
4342
4443 messageSender .send (
45- destination , MessageType .ROOM_SETTING , roomInitialData .roomSettingResponse ());
44+ destination , MessageType .ROOM_SETTING , roomInitialData .roomSettingResponse ());
4645 messageSender .send (
47- destination , MessageType .GAME_SETTING , roomInitialData .gameSettingResponse ());
46+ destination , MessageType .GAME_SETTING , roomInitialData .gameSettingResponse ());
4847 messageSender .send (
49- destination , MessageType .PLAYER_LIST , roomInitialData .playerListResponse ());
48+ destination , MessageType .PLAYER_LIST , roomInitialData .playerListResponse ());
5049 messageSender .send (
51- destination , MessageType .SYSTEM_NOTICE , roomInitialData .systemNoticeResponse ());
50+ destination , MessageType .SYSTEM_NOTICE , roomInitialData .systemNoticeResponse ());
5251 }
5352
5453 @ MessageMapping ("/room/exit/{roomId}" )
@@ -59,57 +58,56 @@ public void exitRoom(@DestinationVariable Long roomId, Message<?> message) {
5958
6059 RoomExitData roomExitData = roomService .exitRoom (roomId , websocketSessionId , principal );
6160
62- String destination = roomExitData . getDestination ();
61+ String destination = getDestination (roomId );
6362
6463 if (!roomExitData .isRemovedRoom ()) {
6564 messageSender .send (
66- destination , MessageType .PLAYER_LIST , roomExitData .getPlayerListResponses ());
65+ destination , MessageType .PLAYER_LIST , roomExitData .getPlayerListResponses ());
6766 messageSender .send (
68- destination , MessageType .SYSTEM_NOTICE , roomExitData .getSystemNoticeResponse ());
67+ destination , MessageType .SYSTEM_NOTICE , roomExitData .getSystemNoticeResponse ());
6968 }
7069 }
7170
7271 @ MessageMapping ("/room/start/{roomId}" )
7372 public void gameStart (
74- @ DestinationVariable Long roomId ,
75- Message <DefaultWebSocketRequest <GameStartRequest >> message ) {
73+ @ DestinationVariable Long roomId ,
74+ Message <DefaultWebSocketRequest <GameStartRequest >> message ) {
7675
77- GameStartData gameStartData =
78- gameService . gameStart ( roomId , message .getPayload ().getMessage ());
76+ GameStartResponse gameStartResponse = gameService . gameStart ( roomId ,
77+ message .getPayload ().getMessage ());
7978
80- String destination = gameStartData . destination ( );
79+ String destination = getDestination ( roomId );
8180
82- messageSender .send (destination , MessageType .GAME_START , gameStartData . gameStartResponse () );
81+ messageSender .send (destination , MessageType .GAME_START , gameStartResponse );
8382 }
8483
8584 @ MessageMapping ("room/chat/{roomId}" )
8685 public void chat (
87- @ DestinationVariable Long roomId ,
88- Message <DefaultWebSocketRequest <ChatMessage >> message ) {
86+ @ DestinationVariable Long roomId ,
87+ Message <DefaultWebSocketRequest <ChatMessage >> message ) {
8988 RoundResult roundResult =
90- roomService .chat (roomId , getSessionId (message ), message .getPayload ().getMessage ());
89+ roomService .chat (roomId , getSessionId (message ), message .getPayload ().getMessage ());
9190
92- String destination = roundResult . getDestination ();
91+ String destination = getDestination (roomId );
9392
9493 messageSender .send (destination , MessageType .CHAT , roundResult .getChat ());
9594
9695 if (!roundResult .hasOnlyChat ()) {
9796 messageSender .send (
98- destination , MessageType .QUESTION_RESULT , roundResult .getQuestionResult ());
97+ destination , MessageType .QUESTION_RESULT , roundResult .getQuestionResult ());
9998 messageSender .send (destination , MessageType .RANK_UPDATE , roundResult .getRankUpdate ());
10099 messageSender .send (
101- destination , MessageType .SYSTEM_NOTICE , roundResult .getSystemNotice ());
100+ destination , MessageType .SYSTEM_NOTICE , roundResult .getSystemNotice ());
102101 }
103102 }
104103
105104 @ MessageMapping ("/room/ready/{roomId}" )
106105 public void playerReady (@ DestinationVariable Long roomId , Message <?> message ) {
107106
108- PlayerReadyData playerReadyData =
109- roomService .handlePlayerReady (roomId , getSessionId (message ));
107+ PlayerListResponse playerListResponse = roomService .handlePlayerReady (roomId , getSessionId (message ));
110108
111109 messageSender .send (
112- playerReadyData . destination ( ), MessageType .PLAYER_LIST , playerReadyData . response () );
110+ getDestination ( roomId ), MessageType .PLAYER_LIST , playerListResponse );
113111 }
114112
115113 private static String getSessionId (Message <?> message ) {
@@ -122,4 +120,8 @@ private static UserPrincipal getSessionUser(Message<?> message) {
122120 Authentication auth = (Authentication ) accessor .getUser ();
123121 return (UserPrincipal ) auth .getPrincipal ();
124122 }
123+
124+ private String getDestination (Long roomId ) {
125+ return "/sub/room/" + roomId ;
126+ }
125127}
0 commit comments