Skip to content

Commit

Permalink
Merge pull request #34 from HandTris/#12
Browse files Browse the repository at this point in the history
feat: ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ณด๋‚ธ ๋ฉ”์‹œ์ง€๋ฅผ ์„œ๋ฒ„์—์„œ ๋‹ค์‹œ ๋™์ผํ•œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋‚ด์ง€ ์•Š๋Š” ๋กœ์ง ๊ตฌํ˜„
  • Loading branch information
seonghoo1217 authored Jun 22, 2024
2 parents 82490da + af67982 commit 4787d0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
public class TetrisService {
private final SimpMessagingTemplate messagingTemplate;

public void broadcastTetrisMessage(TetrisMessageRequest message) {
messagingTemplate.convertAndSend("/topic/tetris", message);
public void broadcastTetrisMessage(TetrisMessageRequest message, String senderSessionId) {
messagingTemplate.convertAndSend("/topic/tetris", message, Map.of("senderSessionId", senderSessionId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jungle.HandTris.application.service.TetrisService;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.stereotype.Controller;

@Controller
Expand All @@ -14,9 +14,8 @@ public class TetrisController {
private final TetrisService tetrisService;

@MessageMapping("/tetris")
@SendTo("/topic/tetris")
public TetrisMessageRequest handleTetrisMessage(TetrisMessageRequest message) {
tetrisService.broadcastTetrisMessage(message);
return message;
public void handleTetrisMessage(TetrisMessageRequest message, SimpMessageHeaderAccessor headerAccessor) {
String sessionId = headerAccessor.getSessionId();
tetrisService.broadcastTetrisMessage(message, sessionId);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jungle.HandTris.presentation.dto.request;

public record TetrisMessageRequest(String[][] board) {
public record TetrisMessageRequest(String sender, String[][] board) {
}

0 comments on commit 4787d0e

Please sign in to comment.