Skip to content

Commit

Permalink
feat: 채팅 연결 성공 - #64
Browse files Browse the repository at this point in the history
feat: 채팅 연결 성공 - #64
  • Loading branch information
aaahyunseo authored Aug 18, 2024
2 parents 298c6c4 + 8fd397e commit aeafb12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
public class StompWebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
// registry.addEndpoint("/ws/chat") // 클라이언트에서 서버로 WebSocket 연결하기 위해 /ws/chat 으로 요청을 보내도록 엔트포인트 설정
// .setAllowedOriginPatterns("*"); // 클라이언트에서 웹 소켓 서버에 요청하는 모든 요청을 수락, CORS 방지
registry.addEndpoint("/ws/chat")
.setAllowedOriginPatterns("*")
.withSockJS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.example.swcompetitionproject.entity.User;
import com.example.swcompetitionproject.service.ChattingService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

Expand All @@ -20,11 +20,10 @@
* (WebSocket 연결, 전송, 해제)
**/

@Profile("stomp")
@RequiredArgsConstructor
@Controller
public class ChatMessageController {
private final SimpMessagingTemplate template; // 기본브로커
private final SimpMessagingTemplate template;
private final ChattingService chattingService;

/**
Expand Down Expand Up @@ -58,7 +57,7 @@ public void enter(@DestinationVariable UUID roomId, @AuthenticatedUser User user
* 채팅방에 메시지 보내기
**/
@MessageMapping("/ws/chat/send")
public void message(ChatMessageDto message) {
public void message(@Payload ChatMessageDto message) {
// MessageRepository 에 메시지 저장
chattingService.saveMessage(message);
// 메시지 전송
Expand Down

0 comments on commit aeafb12

Please sign in to comment.