-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9294ab4
commit 230960b
Showing
8 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/HHive/hhive/domain/chatmessage/controller/SocketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.HHive.hhive.domain.chatmessage.controller; | ||
|
||
import com.HHive.hhive.domain.chatmessage.dto.ChatMessageRequestDTO; | ||
import com.HHive.hhive.domain.chatmessage.dto.ChatMessageResponseDTO; | ||
import com.HHive.hhive.domain.chatmessage.entity.ChatMessage; | ||
import com.HHive.hhive.domain.chatmessage.service.ChatMessageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.simp.SimpMessageSendingOperations; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class SocketController { | ||
|
||
private final SimpMessageSendingOperations sendingOperations; | ||
|
||
private final ChatMessageService chatMessageService; | ||
|
||
@MessageMapping("/chat") | ||
public void socketHandler(ChatMessageRequestDTO requestDTO) { | ||
|
||
ChatMessage chatMessage = chatMessageService.receiveAndSaveMessage(requestDTO); | ||
|
||
sendingOperations.convertAndSend("/topic/chat/" + requestDTO.getHiveId(), | ||
ChatMessageResponseDTO.from(chatMessage)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/HHive/hhive/global/config/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.HHive.hhive.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
|
||
//handshake를 위한 설정 | ||
registry.addEndpoint("/ws") | ||
.setAllowedOriginPatterns("*") | ||
//웹소켓 지원하지 않는 브라우저를 도움 | ||
.withSockJS(); | ||
} | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
|
||
//SimpleBroker로 바로 이동할 경로설정. 스프링에서 제공하는 내장 브로커를 사용하겠다 | ||
registry.enableSimpleBroker("/topic", "/queue"); | ||
|
||
//SimpAnnotationMethod 로 가는 경로. 메시지 처리 후 SimpleBroker로 이동할 | ||
registry.setApplicationDestinationPrefixes("/pub"); | ||
} | ||
|
||
} |