Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/90 chatting #92

Merged
merged 6 commits into from
Jan 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws-connection")
.setAllowedOrigins("*")
.setAllowedOrigins("http://localhost:3000", "http://localhost:8080")
.withSockJS(); // websocket 미지원 λΈŒλΌμš°μ €λ₯Ό μœ„ν•΄ μΆ”κ°€
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sptp.backend.jwt.service.dto.CustomUserDetails;
import com.sptp.backend.message.service.MessageService;
import com.sptp.backend.message.web.dto.MessageRequest;
import com.sptp.backend.message.web.dto.MessageResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
Expand All @@ -23,7 +24,12 @@ public class MessageController {
@MessageMapping("/send")
public void chat(@Valid MessageRequest messageRequest, @AuthenticationPrincipal CustomUserDetails userDetails) {
messageService.saveMessage(userDetails.getMember().getId(), messageRequest);
MessageResponse messageResponse = MessageResponse.builder()
.chatRoomId(messageRequest.getChatRoomId())
.message(messageRequest.getMessage())
.build();

simpMessagingTemplate.convertAndSend("/queue/chat-rooms/" + messageRequest.getChatRoomId(),
messageRequest.getMessage());
messageResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sptp.backend.message.web.dto;

import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class MessageResponse {

private Long chatRoomId;

private String message;
}